use of com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate in project jib by google.
the class CacheStorageReaderTest method testVerifyImageMetadata_validV22.
@Test
public void testVerifyImageMetadata_validV22() throws CacheCorruptedException {
ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(new V22ManifestTemplate(), new ContainerConfigurationTemplate());
ImageMetadataTemplate metadata = new ImageMetadataTemplate(null, Arrays.asList(manifestAndConfig));
CacheStorageReader.verifyImageMetadata(metadata, Paths.get("/cache/dir"));
// should pass without CacheCorruptedException
}
use of com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate in project jib by google.
the class CacheStorageReaderTest method testVerifyImageMetadata_schema2ManifestsCorrupted_nullContainerConfig.
@Test
public void testVerifyImageMetadata_schema2ManifestsCorrupted_nullContainerConfig() {
ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(new V22ManifestTemplate(), null, "sha256:digest");
ImageMetadataTemplate metadata = new ImageMetadataTemplate(null, Arrays.asList(manifestAndConfig));
try {
CacheStorageReader.verifyImageMetadata(metadata, Paths.get("/cache/dir"));
Assert.fail();
} catch (CacheCorruptedException ex) {
MatcherAssert.assertThat(ex.getMessage(), CoreMatchers.startsWith("Schema 2 manifests corrupted"));
}
}
use of com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate in project jib by google.
the class CacheStorageReaderTest method testVerifyImageMetadata_unknownManifestType.
@Test
public void testVerifyImageMetadata_unknownManifestType() {
ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(Mockito.mock(ManifestTemplate.class), new ContainerConfigurationTemplate());
ImageMetadataTemplate metadata = new ImageMetadataTemplate(null, Arrays.asList(manifestAndConfig));
try {
CacheStorageReader.verifyImageMetadata(metadata, Paths.get("/cache/dir"));
Assert.fail();
} catch (CacheCorruptedException ex) {
MatcherAssert.assertThat(ex.getMessage(), CoreMatchers.startsWith("Unknown manifest type:"));
}
}
use of com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate in project jib by google.
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.ManifestAndConfigTemplate in project jib by google.
the class CacheStorageReaderTest method testRetrieveMetadata_ociImageIndex.
@Test
public void testRetrieveMetadata_ociImageIndex() throws IOException, URISyntaxException, CacheCorruptedException {
setupCachedMetadataOciImageIndex(cacheDirectory);
ImageMetadataTemplate metadata = cacheStorageReader.retrieveMetadata(ImageReference.of("test", "image", "tag")).get();
MatcherAssert.assertThat(metadata.getManifestList(), CoreMatchers.instanceOf(OciIndexTemplate.class));
List<ContentDescriptorTemplate> manifestDescriptors = ((OciIndexTemplate) metadata.getManifestList()).getManifests();
Assert.assertEquals(1, manifestDescriptors.size());
Assert.assertEquals("8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad", manifestDescriptors.get(0).getDigest().getHash());
Assert.assertEquals(1, metadata.getManifestsAndConfigs().size());
ManifestAndConfigTemplate manifestAndConfig = metadata.getManifestsAndConfigs().get(0);
OciManifestTemplate manifestTemplate = (OciManifestTemplate) manifestAndConfig.getManifest();
Assert.assertEquals(2, manifestTemplate.getSchemaVersion());
Assert.assertEquals("8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad", manifestTemplate.getContainerConfiguration().getDigest().getHash());
Assert.assertEquals("wasm", manifestAndConfig.getConfig().getArchitecture());
}
Aggregations