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));
}
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));
}
Aggregations