Search in sources :

Example 16 with DetectableExecutableRunner

use of com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner in project synopsys-detect by blackducksoftware.

the class DockerExtractorTest method testExtractImageReturningSquashedImage.

@Test
@DisabledOnOs(WINDOWS)
public void testExtractImageReturningSquashedImage() throws ExecutableRunnerException, IOException {
    final String image = "ubuntu:latest";
    String imageId = null;
    String tar = null;
    DetectableExecutableRunner executableRunner = getDetectableExecutableRunner();
    Extraction extraction = extract(image, imageId, tar, fakeContainerFileSystemFile, fakeSquashedImageFile, fakeResultsFile, executableRunner);
    assertEquals("ubuntu:latest", extraction.getMetaData(DockerExtractor.DOCKER_IMAGE_NAME_META_DATA).get());
    assertTrue(extraction.getMetaData(DockerExtractor.SQUASHED_IMAGE_META_DATA).get().getName().endsWith("_squashedimage.tar.gz"));
    ArgumentCaptor<Executable> executableArgumentCaptor = ArgumentCaptor.forClass(Executable.class);
    Mockito.verify(executableRunner).execute(executableArgumentCaptor.capture());
    Executable executableToVerify = executableArgumentCaptor.getValue();
    List<String> command = executableToVerify.getCommandWithArguments();
    assertTrue(command.get(0).endsWith("/fake/test/java"));
    assertEquals("-jar", command.get(1));
    assertTrue(command.get(2).endsWith("/fake/test/dockerinspector.jar"));
    assertTrue(command.get(3).startsWith("--spring.config.location="));
    assertTrue(command.get(3).endsWith("/application.properties"));
    assertEquals("--docker.image=ubuntu:latest", command.get(4));
}
Also used : DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) Extraction(com.synopsys.integration.detectable.extraction.Extraction) Executable(com.synopsys.integration.executable.Executable) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) Test(org.junit.jupiter.api.Test)

Example 17 with DetectableExecutableRunner

use of com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner 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

DetectableExecutableRunner (com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner)17 Test (org.junit.jupiter.api.Test)14 Executable (com.synopsys.integration.executable.Executable)9 ExecutableOutput (com.synopsys.integration.executable.ExecutableOutput)9 Extraction (com.synopsys.integration.detectable.extraction.Extraction)7 File (java.io.File)7 DisabledOnOs (org.junit.jupiter.api.condition.DisabledOnOs)5 ExecutableTarget (com.synopsys.integration.detectable.ExecutableTarget)4 ClangPackageManagerInfoFactory (com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManagerInfoFactory)3 PackageDetails (com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails)3 ArrayList (java.util.ArrayList)3 Gson (com.google.gson.Gson)2 FileFinder (com.synopsys.integration.common.util.finder.FileFinder)2 ClangPackageManager (com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManager)2 ClangPackageManagerRunner (com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManagerRunner)2 DpkgPackageManagerResolver (com.synopsys.integration.detectable.detectables.clang.packagemanager.resolver.DpkgPackageManagerResolver)2 DpkgPkgDetailsResolver (com.synopsys.integration.detectable.detectables.clang.packagemanager.resolver.DpkgPkgDetailsResolver)2 GoModCliExtractor (com.synopsys.integration.detectable.detectables.go.gomod.GoModCliExtractor)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2