Search in sources :

Example 1 with BdioBillOfMaterials

use of com.synopsys.integration.bdio.model.BdioBillOfMaterials in project blackduck-docker-inspector by blackducksoftware.

the class OutputTest method testSquashedImageCreation.

@Test
public void testSquashedImageCreation() throws IOException, IntegrationException {
    Mockito.when(config.getOutputPath()).thenReturn(outputDir.getAbsolutePath());
    Mockito.when(config.isOutputIncludeSquashedImage()).thenReturn(true);
    Mockito.when(programPaths.getUserOutputDirPath()).thenReturn(outputDir.getAbsolutePath());
    Mockito.when(programPaths.getDockerInspectorWorkingOutputPath()).thenReturn(workingDir.getAbsolutePath());
    Mockito.when(programPaths.getDockerInspectorSquashedImageTarFilePath()).thenReturn(squashedImageTarfile.getAbsolutePath());
    Mockito.when(programPaths.getDockerInspectorSquashedImageDirPath()).thenReturn(squashingTempDir.getAbsolutePath());
    SimpleBdioDocument bdioDoc = Mockito.mock(SimpleBdioDocument.class);
    BdioBillOfMaterials bom = new BdioBillOfMaterials();
    bom.spdxName = "registry.luciddg.com_luciddg_ldg-server-qa_2020.16.03_DPKG";
    Mockito.when(bdioDoc.getBillOfMaterials()).thenReturn(bom);
    BdioProject project = new BdioProject();
    Mockito.when(bdioDoc.getProject()).thenReturn(project);
    Mockito.when(containerFilesystemFilename.deriveContainerFilesystemFilename(null, null)).thenReturn("target_containerfilesystem.tar.gz");
    ImageTarFilename imageTarFilename = new ImageTarFilename();
    FileOperations fileOperations = new FileOperations();
    DockerClientManager dockerClientManager = new DockerClientManager(fileOperations, new ImageNameResolver(), config, imageTarFilename, programPaths);
    SquashedImage squashedImage = new SquashedImage();
    squashedImage.setFileOperations(fileOperations);
    squashedImage.setDockerClientManager(dockerClientManager);
    output.setSquashedImage(squashedImage);
    // Test
    OutputFiles outputFiles = output.addOutputToFinalOutputDir(bdioDoc, null, null);
    // Verify
    File generatedSquashedImageCompressedFile = outputFiles.getSquashedImageFile();
    File generatedSquashedImageTarfile = new File(workingDir, "generatedImageTarfile");
    CompressedFile.gunZipFile(generatedSquashedImageCompressedFile, generatedSquashedImageTarfile);
    File generatedSquashedImageContents = new File(workingDir, "generatedSquashedImageContents");
    CompressedFile.unTarFile(generatedSquashedImageTarfile, generatedSquashedImageContents);
    System.out.println(String.format("Look in: %s", generatedSquashedImageContents.getAbsolutePath()));
    Collection<File> layerFiles = FileUtils.listFiles(generatedSquashedImageContents, new NameFileFilter("layer.tar"), TrueFileFilter.TRUE);
    assertEquals(1, layerFiles.size());
    File generatedLayer = new File(workingDir, "generatedLayer");
    CompressedFile.unTarFile(layerFiles.iterator().next(), generatedLayer);
    File expectedFile = new File(generatedLayer, "opt/luciddg-server/modules/django/bin/100_assets.csv");
    assertTrue(expectedFile.exists());
}
Also used : NameFileFilter(org.apache.commons.io.filefilter.NameFileFilter) BdioBillOfMaterials(com.synopsys.integration.bdio.model.BdioBillOfMaterials) BdioProject(com.synopsys.integration.bdio.model.BdioProject) DockerClientManager(com.synopsys.integration.blackduck.dockerinspector.dockerclient.DockerClientManager) ImageNameResolver(com.synopsys.integration.blackduck.imageinspector.api.name.ImageNameResolver) FileOperations(com.synopsys.integration.blackduck.imageinspector.linux.FileOperations) File(java.io.File) SimpleBdioDocument(com.synopsys.integration.bdio.model.SimpleBdioDocument) Test(org.junit.jupiter.api.Test)

Aggregations

BdioBillOfMaterials (com.synopsys.integration.bdio.model.BdioBillOfMaterials)1 BdioProject (com.synopsys.integration.bdio.model.BdioProject)1 SimpleBdioDocument (com.synopsys.integration.bdio.model.SimpleBdioDocument)1 DockerClientManager (com.synopsys.integration.blackduck.dockerinspector.dockerclient.DockerClientManager)1 ImageNameResolver (com.synopsys.integration.blackduck.imageinspector.api.name.ImageNameResolver)1 FileOperations (com.synopsys.integration.blackduck.imageinspector.linux.FileOperations)1 File (java.io.File)1 NameFileFilter (org.apache.commons.io.filefilter.NameFileFilter)1 Test (org.junit.jupiter.api.Test)1