void writeMetadata(ImageReference imageReference, ImageMetadataTemplate metadata)
      throws IOException {
    verifyImageMetadata(metadata);
    Path imageDirectory = cacheStorageFiles.getImageDirectory(imageReference);
    Files.createDirectories(imageDirectory);

    try (LockFile ignored = LockFile.lock(imageDirectory.resolve("lock"))) {
      writeJsonTemplate(metadata, imageDirectory.resolve("manifests_configs.json"));
    }
  }
@Test
  public void testWriteMetadata_oci()
      throws URISyntaxException, IOException, InvalidImageReferenceException {
    ContainerConfigurationTemplate containerConfig =
        loadJsonResource("core/json/containerconfig.json", ContainerConfigurationTemplate.class);
    OciManifestTemplate manifest =
        loadJsonResource("core/json/ocimanifest.json", OciManifestTemplate.class);
    OciIndexTemplate ociIndex = loadJsonResource("core/json/ociindex.json", OciIndexTemplate.class);

    ImageReference imageReference = ImageReference.parse("image.reference/project/thing:tag");

    cacheStorageWriter.writeMetadata(
        imageReference,
        new ImageMetadataTemplate(
            ociIndex,
            Arrays.asList(
                new ManifestAndConfigTemplate(manifest, containerConfig, "sha256:digest"))));

    Path savedMetadataPath =
        cacheRoot.resolve("images/image.reference/project/thing!tag/manifests_configs.json");
    Assert.assertTrue(Files.exists(savedMetadataPath));

    ImageMetadataTemplate savedMetadata =
        JsonTemplateMapper.readJsonFromFile(savedMetadataPath, ImageMetadataTemplate.class);

    MatcherAssert.assertThat(
        savedMetadata.getManifestList(), CoreMatchers.instanceOf(OciIndexTemplate.class));
    List<? extends ContentDescriptorTemplate> savedManifestDescriptors =
        ((OciIndexTemplate) savedMetadata.getManifestList()).getManifests();

    Assert.assertEquals(1, savedManifestDescriptors.size());
    Assert.assertEquals(
        "8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad",
        savedManifestDescriptors.get(0).getDigest().getHash());

    Assert.assertEquals(1, savedMetadata.getManifestsAndConfigs().size());
    ManifestAndConfigTemplate savedManifestAndConfig =
        savedMetadata.getManifestsAndConfigs().get(0);

    OciManifestTemplate savedManifest1 = (OciManifestTemplate) savedManifestAndConfig.getManifest();
    Assert.assertEquals(2, savedManifest1.getSchemaVersion());

    Assert.assertEquals(1, savedManifest1.getLayers().size());
    Assert.assertEquals(
        "4945ba5011739b0b98c4a41afe224e417f47c7c99b2ce76830999c9a0861b236",
        savedManifest1.getLayers().get(0).getDigest().getHash());

    Assert.assertEquals(
        "8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad",
        savedManifest1.getContainerConfiguration().getDigest().getHash());

    Assert.assertEquals("wasm", savedManifestAndConfig.getConfig().getArchitecture());
  }