use of com.google.cloud.tools.jib.image.json.ImageMetadataTemplate in project jib by google.
the class CacheStorageReaderTest method testRetrieveMetadata_containerConfiguration.
@Test
public void testRetrieveMetadata_containerConfiguration() throws IOException, URISyntaxException, CacheCorruptedException {
setupCachedMetadataV22(cacheDirectory);
ImageMetadataTemplate metadata = cacheStorageReader.retrieveMetadata(ImageReference.of("test", "image", "tag")).get();
Assert.assertNull(metadata.getManifestList());
Assert.assertEquals(1, metadata.getManifestsAndConfigs().size());
ContainerConfigurationTemplate configurationTemplate = metadata.getManifestsAndConfigs().get(0).getConfig();
Assert.assertNotNull(configurationTemplate);
Assert.assertEquals("wasm", configurationTemplate.getArchitecture());
Assert.assertEquals("js", configurationTemplate.getOs());
}
use of com.google.cloud.tools.jib.image.json.ImageMetadataTemplate in project jib by google.
the class CacheStorageReaderTest method setupCachedMetadataV21.
private static void setupCachedMetadataV21(Path cacheDirectory) throws IOException, URISyntaxException {
Path imageDirectory = cacheDirectory.resolve("images/test/image!tag");
Files.createDirectories(imageDirectory);
ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(loadJsonResource("core/json/v21manifest.json", V21ManifestTemplate.class), null);
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 google.
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 google.
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 google.
the class CacheStorageReaderTest method setupCachedMetadataOciImageIndex.
private static void setupCachedMetadataOciImageIndex(Path cacheDirectory) throws IOException, URISyntaxException {
Path imageDirectory = cacheDirectory.resolve("images/test/image!tag");
Files.createDirectories(imageDirectory);
ManifestTemplate ociIndex = loadJsonResource("core/json/ociindex.json", OciIndexTemplate.class);
ManifestTemplate ociManifest = loadJsonResource("core/json/ocimanifest.json", OciManifestTemplate.class);
ContainerConfigurationTemplate containerConfig = loadJsonResource("core/json/containerconfig.json", ContainerConfigurationTemplate.class);
List<ManifestAndConfigTemplate> manifestsAndConfigs = Arrays.asList(new ManifestAndConfigTemplate(ociManifest, containerConfig, "sha256:digest"));
try (OutputStream out = Files.newOutputStream(imageDirectory.resolve("manifests_configs.json"))) {
JsonTemplateMapper.writeTo(new ImageMetadataTemplate(ociIndex, manifestsAndConfigs), out);
}
}
Aggregations