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_v21()
      throws IOException, URISyntaxException, InvalidImageReferenceException {
    V21ManifestTemplate v21Manifest =
        loadJsonResource("core/json/v21manifest.json", V21ManifestTemplate.class);
    ImageReference imageReference = ImageReference.parse("image.reference/project/thing:tag");

    ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(v21Manifest, null);
    cacheStorageWriter.writeMetadata(
        imageReference, new ImageMetadataTemplate(null, Arrays.asList(manifestAndConfig)));

    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);
    Assert.assertNull(savedMetadata.getManifestList());
    Assert.assertEquals(1, savedMetadata.getManifestsAndConfigs().size());

    ManifestAndConfigTemplate savedManifestAndConfig =
        savedMetadata.getManifestsAndConfigs().get(0);
    Assert.assertNull(savedManifestAndConfig.getConfig());

    V21ManifestTemplate savedManifest = (V21ManifestTemplate) savedManifestAndConfig.getManifest();
    Assert.assertEquals(
        "ppc64le", savedManifest.getContainerConfiguration().get().getArchitecture());
  }