Search in sources :

Example 1 with DockerExtractor

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);
}
Also used : BdioTransformer(com.synopsys.integration.bdio.BdioTransformer) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) DockerInspectorResultsFileParser(com.synopsys.integration.detectable.detectables.docker.parser.DockerInspectorResultsFileParser) Gson(com.google.gson.Gson) DockerExtractor(com.synopsys.integration.detectable.detectables.docker.DockerExtractor) ImageIdentifierGenerator(com.synopsys.integration.detectable.detectables.docker.ImageIdentifierGenerator) DockerInspectorResults(com.synopsys.integration.detectable.detectables.docker.model.DockerInspectorResults)

Example 2 with DockerExtractor

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));
}
Also used : DockerProperties(com.synopsys.integration.detectable.detectables.docker.DockerProperties) DockerExtractor(com.synopsys.integration.detectable.detectables.docker.DockerExtractor) FileFinder(com.synopsys.integration.common.util.finder.FileFinder) File(java.io.File) ExecutableTarget(com.synopsys.integration.detectable.ExecutableTarget) DockerInspectorInfo(com.synopsys.integration.detectable.detectables.docker.DockerInspectorInfo)

Example 3 with DockerExtractor

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);
}
Also used : JavaResolver(com.synopsys.integration.detectable.detectable.executable.resolver.JavaResolver) WrongOperatingSystemResult(com.synopsys.integration.detectable.detectable.result.WrongOperatingSystemResult) DockerDetectable(com.synopsys.integration.detectable.detectables.docker.DockerDetectable) DetectableResult(com.synopsys.integration.detectable.detectable.result.DetectableResult) DockerExtractor(com.synopsys.integration.detectable.detectables.docker.DockerExtractor) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment) DockerInspectorResolver(com.synopsys.integration.detectable.detectables.docker.DockerInspectorResolver) DockerResolver(com.synopsys.integration.detectable.detectable.executable.resolver.DockerResolver) DockerDetectableOptions(com.synopsys.integration.detectable.detectables.docker.DockerDetectableOptions) Test(org.junit.jupiter.api.Test)

Example 4 with DockerExtractor

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));
}
Also used : DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) DockerExtractor(com.synopsys.integration.detectable.detectables.docker.DockerExtractor) FileFinder(com.synopsys.integration.common.util.finder.FileFinder) File(java.io.File) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) Test(org.junit.jupiter.api.Test)

Aggregations

DockerExtractor (com.synopsys.integration.detectable.detectables.docker.DockerExtractor)4 FileFinder (com.synopsys.integration.common.util.finder.FileFinder)2 File (java.io.File)2 Test (org.junit.jupiter.api.Test)2 Gson (com.google.gson.Gson)1 BdioTransformer (com.synopsys.integration.bdio.BdioTransformer)1 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)1 DetectableEnvironment (com.synopsys.integration.detectable.DetectableEnvironment)1 ExecutableTarget (com.synopsys.integration.detectable.ExecutableTarget)1 DetectableExecutableRunner (com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner)1 DockerResolver (com.synopsys.integration.detectable.detectable.executable.resolver.DockerResolver)1 JavaResolver (com.synopsys.integration.detectable.detectable.executable.resolver.JavaResolver)1 DetectableResult (com.synopsys.integration.detectable.detectable.result.DetectableResult)1 WrongOperatingSystemResult (com.synopsys.integration.detectable.detectable.result.WrongOperatingSystemResult)1 DockerDetectable (com.synopsys.integration.detectable.detectables.docker.DockerDetectable)1 DockerDetectableOptions (com.synopsys.integration.detectable.detectables.docker.DockerDetectableOptions)1 DockerInspectorInfo (com.synopsys.integration.detectable.detectables.docker.DockerInspectorInfo)1 DockerInspectorResolver (com.synopsys.integration.detectable.detectables.docker.DockerInspectorResolver)1 DockerProperties (com.synopsys.integration.detectable.detectables.docker.DockerProperties)1 ImageIdentifierGenerator (com.synopsys.integration.detectable.detectables.docker.ImageIdentifierGenerator)1