all tests for DockerfileServiceImpl
This commit is contained in:
parent
32827d7ba4
commit
390e389027
2 changed files with 99 additions and 42 deletions
|
@ -20,17 +20,13 @@ export class DockerfileServiceImpl implements DockerfileService {
|
|||
failure: (error: Event | string) => void): void {
|
||||
var reader: FileReader = this.FileReaderFactory();
|
||||
reader.onload = (event: any) => {
|
||||
|
||||
// FIXME: Debugging
|
||||
console.log(event.target.result);
|
||||
|
||||
this.DataFileService.readDataArrayAsPossibleArchive(event.target.result,
|
||||
(files: any[]) => {
|
||||
this.processFiles(files, event.target.result, success, failure);
|
||||
this.processFiles(files, success, failure);
|
||||
},
|
||||
() => {
|
||||
// Not an archive. Read directly as a single file.
|
||||
this.processFiles([], event.target.result, success, failure);
|
||||
// Not an archive. Read directly as a single file.
|
||||
this.processFile(event.target.result, success, failure);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -38,25 +34,23 @@ export class DockerfileServiceImpl implements DockerfileService {
|
|||
reader.readAsArrayBuffer(file);
|
||||
}
|
||||
|
||||
private processFile(dataArray: any,
|
||||
success: (dockerfile: DockerfileInfoImpl) => void,
|
||||
failure: (error: ErrorEvent | string) => void): void {
|
||||
this.DataFileService.arrayToString(dataArray, (contents: string) => {
|
||||
var result: DockerfileInfoImpl | null = DockerfileInfoImpl.forData(contents, this.Config);
|
||||
if (result == null) {
|
||||
failure('File chosen is not a valid Dockerfile');
|
||||
}
|
||||
else {
|
||||
success(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private processFiles(files: any[],
|
||||
dataArray: any[],
|
||||
success: (dockerfile: DockerfileInfoImpl) => void,
|
||||
failure: (error: ErrorEvent | string) => void): void {
|
||||
// The files array will be empty if the submitted file was not an archive. We therefore
|
||||
// treat it as a single Dockerfile.
|
||||
if (files.length == 0) {
|
||||
this.DataFileService.arrayToString(dataArray, (contents: string) => {
|
||||
var result: DockerfileInfoImpl | null = DockerfileInfoImpl.forData(contents, this.Config);
|
||||
if (result == null) {
|
||||
failure('File chosen is not a valid Dockerfile');
|
||||
return;
|
||||
}
|
||||
|
||||
success(result);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
var found: boolean = false;
|
||||
files.forEach((file) => {
|
||||
if (file['name'] == 'Dockerfile') {
|
||||
|
@ -64,10 +58,10 @@ export class DockerfileServiceImpl implements DockerfileService {
|
|||
var result: DockerfileInfoImpl | null = DockerfileInfoImpl.forData(contents, this.Config);
|
||||
if (result == null) {
|
||||
failure('Dockerfile inside archive is not a valid Dockerfile');
|
||||
return;
|
||||
}
|
||||
|
||||
success(result);
|
||||
else {
|
||||
success(result);
|
||||
}
|
||||
});
|
||||
found = true;
|
||||
}
|
||||
|
|
Reference in a new issue