Optional<ImageMetadataTemplate> retrieveMetadata(ImageReference imageReference)
      throws IOException, CacheCorruptedException {
    Path imageDirectory = cacheStorageFiles.getImageDirectory(imageReference);
    Path metadataPath = imageDirectory.resolve("manifests_configs.json");
    if (!Files.exists(metadataPath)) {
      return Optional.empty();
    }

    ImageMetadataTemplate metadata;
    try (LockFile ignored = LockFile.lock(imageDirectory.resolve("lock"))) {
      metadata = JsonTemplateMapper.readJsonFromFile(metadataPath, ImageMetadataTemplate.class);
    }
    verifyImageMetadata(metadata, imageDirectory);
    return Optional.of(metadata);
  }
@Test
  public void testRetrieveMetadata_v21SingleManifest()
      throws IOException, URISyntaxException, CacheCorruptedException {
    setupCachedMetadataV21(cacheDirectory);

    ImageMetadataTemplate metadata =
        cacheStorageReader.retrieveMetadata(ImageReference.of("test", "image", "tag")).get();
    Assert.assertNull(metadata.getManifestList());
    Assert.assertEquals(1, metadata.getManifestsAndConfigs().size());
    Assert.assertNull(metadata.getManifestsAndConfigs().get(0).getConfig());

    V21ManifestTemplate manifestTemplate =
        (V21ManifestTemplate) metadata.getManifestsAndConfigs().get(0).getManifest();
    Assert.assertEquals(1, manifestTemplate.getSchemaVersion());
    Assert.assertEquals(2, manifestTemplate.getLayerDigests().size());
    Assert.assertEquals(
        "8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad",
        manifestTemplate.getLayerDigests().get(0).getHash());
    Assert.assertEquals(
        "5bd451067f9ab05e97cda8476c82f86d9b69c2dffb60a8ad2fe3723942544ab3",
        manifestTemplate.getLayerDigests().get(1).getHash());
  }