use of com.google.cloud.tools.jib.image.json.ImageMetadataTemplate in project jib by GoogleContainerTools.
the class PullBaseImageStepTest method testGetCachedBaseImages_v22ManifestListCached.
@Test
public void testGetCachedBaseImages_v22ManifestListCached() throws InvalidImageReferenceException, IOException, CacheCorruptedException, UnlistedPlatformInManifestListException, BadContainerConfigurationFormatException, LayerCountMismatchException {
ImageReference imageReference = ImageReference.parse("cat");
Mockito.when(buildContext.getBaseImageConfiguration()).thenReturn(ImageConfiguration.builder(imageReference).build());
ContainerConfigurationTemplate containerConfigJson1 = new ContainerConfigurationTemplate();
ContainerConfigurationTemplate containerConfigJson2 = new ContainerConfigurationTemplate();
containerConfigJson1.setContainerUser("user1");
containerConfigJson2.setContainerUser("user2");
V22ManifestListTemplate manifestList = Mockito.mock(V22ManifestListTemplate.class);
Mockito.when(manifestList.getDigestsForPlatform("arch1", "os1")).thenReturn(Arrays.asList("sha256:digest1"));
Mockito.when(manifestList.getDigestsForPlatform("arch2", "os2")).thenReturn(Arrays.asList("sha256:digest2"));
ImageMetadataTemplate imageMetadata = new ImageMetadataTemplate(manifestList, Arrays.asList(new ManifestAndConfigTemplate(new V22ManifestTemplate(), containerConfigJson1, "sha256:digest1"), new ManifestAndConfigTemplate(new V22ManifestTemplate(), containerConfigJson2, "sha256:digest2")));
Mockito.when(cache.retrieveMetadata(imageReference)).thenReturn(Optional.of(imageMetadata));
Mockito.when(containerConfig.getPlatforms()).thenReturn(ImmutableSet.of(new Platform("arch1", "os1"), new Platform("arch2", "os2")));
List<Image> images = pullBaseImageStep.getCachedBaseImages();
Assert.assertEquals(2, images.size());
Assert.assertEquals("user1", images.get(0).getUser());
Assert.assertEquals("user2", images.get(1).getUser());
}
use of com.google.cloud.tools.jib.image.json.ImageMetadataTemplate in project jib by GoogleContainerTools.
the class CacheStorageReaderTest method testVerifyImageMetadata_manifestCacheEmpty.
@Test
public void testVerifyImageMetadata_manifestCacheEmpty() {
ImageMetadataTemplate metadata = new ImageMetadataTemplate(null, Collections.emptyList());
try {
CacheStorageReader.verifyImageMetadata(metadata, Paths.get("/cache/dir"));
Assert.fail();
} catch (CacheCorruptedException ex) {
MatcherAssert.assertThat(ex.getMessage(), CoreMatchers.startsWith("Manifest cache empty"));
}
}
use of com.google.cloud.tools.jib.image.json.ImageMetadataTemplate in project jib by GoogleContainerTools.
the class CacheStorageReaderTest method testVerifyImageMetadata_schema1ManifestsCorrupted_manifestListExists.
@Test
public void testVerifyImageMetadata_schema1ManifestsCorrupted_manifestListExists() {
ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(new V21ManifestTemplate(), null);
ImageMetadataTemplate metadata = new ImageMetadataTemplate(new V22ManifestListTemplate(), Arrays.asList(manifestAndConfig));
try {
CacheStorageReader.verifyImageMetadata(metadata, Paths.get("/cache/dir"));
Assert.fail();
} catch (CacheCorruptedException ex) {
MatcherAssert.assertThat(ex.getMessage(), CoreMatchers.startsWith("Schema 1 manifests corrupted"));
}
}
use of com.google.cloud.tools.jib.image.json.ImageMetadataTemplate in project jib by GoogleContainerTools.
the class CacheStorageReaderTest method setupCachedMetadataOci.
private static void setupCachedMetadataOci(Path cacheDirectory) throws IOException, URISyntaxException {
Path imageDirectory = cacheDirectory.resolve("images/test/image!tag");
Files.createDirectories(imageDirectory);
ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(loadJsonResource("core/json/ocimanifest.json", OciManifestTemplate.class), loadJsonResource("core/json/containerconfig.json", ContainerConfigurationTemplate.class), "sha256:digest");
try (OutputStream out = Files.newOutputStream(imageDirectory.resolve("manifests_configs.json"))) {
JsonTemplateMapper.writeTo(new ImageMetadataTemplate(null, Arrays.asList(manifestAndConfig)), out);
}
}
use of com.google.cloud.tools.jib.image.json.ImageMetadataTemplate in project jib by GoogleContainerTools.
the class CacheStorageReaderTest method testVerifyImageMetadata_manifestListMissing.
@Test
public void testVerifyImageMetadata_manifestListMissing() {
ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(new V22ManifestListTemplate(), new ContainerConfigurationTemplate());
ImageMetadataTemplate metadata = new ImageMetadataTemplate(null, Arrays.asList(manifestAndConfig, manifestAndConfig));
try {
CacheStorageReader.verifyImageMetadata(metadata, Paths.get("/cache/dir"));
Assert.fail();
} catch (CacheCorruptedException ex) {
MatcherAssert.assertThat(ex.getMessage(), CoreMatchers.startsWith("Manifest list missing"));
}
}
Aggregations