use of com.synopsys.integration.detectable.detectables.docker.DockerExtractor in project synopsys-detect by blackducksoftware.
the class DockerExtractorTest method getMockDockerExtractor.
private DockerExtractor getMockDockerExtractor(DetectableExecutableRunner executableRunner, FileFinder fileFinder) {
BdioTransformer bdioTransformer = Mockito.mock(BdioTransformer.class);
ExternalIdFactory externalIdFactory = Mockito.mock(ExternalIdFactory.class);
Gson gson = new Gson();
DockerInspectorResultsFileParser dockerInspectorResultsFileParser = Mockito.mock(DockerInspectorResultsFileParser.class);
DockerInspectorResults dockerInspectorResults = new DockerInspectorResults("returnedimage", "returnedtag", "returned message");
Mockito.when(dockerInspectorResultsFileParser.parse(Mockito.anyString())).thenReturn(Optional.of(dockerInspectorResults));
ImageIdentifierGenerator imageIdentifierGenerator = new ImageIdentifierGenerator();
return new DockerExtractor(fileFinder, executableRunner, bdioTransformer, externalIdFactory, gson, dockerInspectorResultsFileParser, imageIdentifierGenerator);
}
use of com.synopsys.integration.detectable.detectables.docker.DockerExtractor in project synopsys-detect by blackducksoftware.
the class DockerExtractorTest method extract.
private Extraction extract(String image, String imageId, String tar, File returnedContainerFileSystemFile, File returnedSquashedImageFile, File resultsFile, DetectableExecutableRunner executableRunner) throws IOException, ExecutableRunnerException {
FileFinder fileFinder = Mockito.mock(FileFinder.class);
DockerExtractor dockerExtractor = getMockDockerExtractor(executableRunner, fileFinder);
File directory = new File(".");
File outputDirectory = new File("build/tmp/test/DockerExtractorTest");
ExecutableTarget bashExe = null;
ExecutableTarget javaExe = ExecutableTarget.forFile(new File("fake/test/java"));
DockerInspectorInfo dockerInspectorInfo = Mockito.mock(DockerInspectorInfo.class);
Mockito.when(fileFinder.findFile(outputDirectory, DockerExtractor.CONTAINER_FILESYSTEM_FILENAME_PATTERN)).thenReturn(returnedContainerFileSystemFile);
Mockito.when(fileFinder.findFile(outputDirectory, DockerExtractor.SQUASHED_IMAGE_FILENAME_PATTERN)).thenReturn(returnedSquashedImageFile);
Mockito.when(fileFinder.findFile(outputDirectory, DockerExtractor.RESULTS_FILENAME_PATTERN)).thenReturn(resultsFile);
Mockito.when(dockerInspectorInfo.getDockerInspectorJar()).thenReturn(new File("fake/test/dockerinspector.jar"));
return dockerExtractor.extract(directory, outputDirectory, bashExe, javaExe, image, imageId, tar, dockerInspectorInfo, Mockito.mock(DockerProperties.class));
}
use of com.synopsys.integration.detectable.detectables.docker.DockerExtractor in project synopsys-detect by blackducksoftware.
the class DockerDetectableTest method testApplicable.
@Test
public void testApplicable() {
DetectableEnvironment environment = null;
DockerInspectorResolver dockerInspectorResolver = null;
JavaResolver javaResolver = null;
DockerResolver dockerResolver = null;
DockerExtractor dockerExtractor = null;
DockerDetectableOptions dockerDetectableOptions = Mockito.mock(DockerDetectableOptions.class);
Mockito.when(dockerDetectableOptions.hasDockerImageOrTar()).thenReturn(Boolean.TRUE);
DockerDetectable detectable = new DockerDetectable(environment, dockerInspectorResolver, javaResolver, dockerResolver, dockerExtractor, dockerDetectableOptions);
DetectableResult result = detectable.applicable();
assertTrue(result.getPassed() || result instanceof WrongOperatingSystemResult);
}
use of com.synopsys.integration.detectable.detectables.docker.DockerExtractor in project synopsys-detect by blackducksoftware.
the class DockerExtractorTest method testGetImageIdentifierFromOutputDirectoryIfImageIdPresent.
@Test
@DisabledOnOs(WINDOWS)
public void testGetImageIdentifierFromOutputDirectoryIfImageIdPresent() throws URISyntaxException {
String testString = "test";
String imageIdArgument = "--docker.image.id=";
String imageName = "ubuntu:latest";
File outputDirectoryWithPopulatedResultsFile = new File(DockerExtractorTest.class.getClassLoader().getSystemResource("detectables/functional/docker/unit/outputDirectoryWithPopulatedResultsFile").toURI());
File outputDirectoryWithNonPopulatedResultsFile = new File(DockerExtractorTest.class.getClassLoader().getSystemResource("detectables/functional/docker/unit/outputDirectoryWithNonPopulatedResultsFile").toURI());
DetectableExecutableRunner executableRunner = Mockito.mock(DetectableExecutableRunner.class);
FileFinder fileFinder = Mockito.mock(FileFinder.class);
Mockito.when(fileFinder.findFile(outputDirectoryWithPopulatedResultsFile, DockerExtractor.RESULTS_FILENAME_PATTERN)).thenReturn(new File(outputDirectoryWithPopulatedResultsFile, "results.json"));
Mockito.when(fileFinder.findFile(outputDirectoryWithNonPopulatedResultsFile, DockerExtractor.RESULTS_FILENAME_PATTERN)).thenReturn(new File(outputDirectoryWithNonPopulatedResultsFile, "results.json"));
DockerExtractor dockerExtractor = getMockDockerExtractor(executableRunner, fileFinder);
assertEquals(imageName, dockerExtractor.getImageIdentifierFromOutputDirectoryIfImageIdPresent(outputDirectoryWithPopulatedResultsFile, testString, ImageIdentifierType.IMAGE_ID));
assertEquals(testString, dockerExtractor.getImageIdentifierFromOutputDirectoryIfImageIdPresent(outputDirectoryWithPopulatedResultsFile, testString, ImageIdentifierType.IMAGE_NAME));
assertEquals(testString, dockerExtractor.getImageIdentifierFromOutputDirectoryIfImageIdPresent(outputDirectoryWithNonPopulatedResultsFile, testString, ImageIdentifierType.IMAGE_ID));
}
Aggregations