|
24 | 24 |
|
25 | 25 | import java.util.List; |
26 | 26 | import java.util.Map; |
| 27 | +import land.oras.exception.OrasException; |
27 | 28 | import land.oras.utils.Const; |
28 | 29 | import land.oras.utils.SupportedAlgorithm; |
29 | 30 | import org.junit.jupiter.api.Test; |
@@ -118,6 +119,28 @@ void shouldReadAndWriteIndexWithArtifactType() { |
118 | 119 | assertEquals(json, index.toJson()); |
119 | 120 | } |
120 | 121 |
|
| 122 | + @Test |
| 123 | + void shouldRemoveManifest() { |
| 124 | + |
| 125 | + // Create 2 descriptors |
| 126 | + Manifest newManifest1 = Manifest.empty().withAnnotations(Map.of("foo", "bar")); |
| 127 | + ManifestDescriptor descriptor1 = ManifestDescriptor.of(newManifest1); |
| 128 | + Manifest newManifest2 = Manifest.empty().withAnnotations(Map.of("foo1", "bar2")); |
| 129 | + ManifestDescriptor descriptor2 = ManifestDescriptor.of(newManifest2); |
| 130 | + |
| 131 | + Index index = Index.fromManifests(List.of(descriptor1, descriptor2)); |
| 132 | + assertEquals(2, index.getManifests().size()); |
| 133 | + |
| 134 | + final Index indexFinal = index.withRemovedDescriptor(descriptor1); |
| 135 | + assertEquals(1, indexFinal.getManifests().size()); |
| 136 | + assertEquals(descriptor2.getDigest(), indexFinal.getManifests().get(0).getDigest()); |
| 137 | + |
| 138 | + OrasException e = assertThrows(OrasException.class, () -> indexFinal.withRemovedDescriptor(descriptor1)); |
| 139 | + assertEquals( |
| 140 | + "Cannot remove manifest descriptor with digest sha256:d37ee97188d29dd838306ac7c5d35c03cc4cdac37c6a9e98529fee5aa0d65635 because it does not exist in the index", |
| 141 | + e.getMessage()); |
| 142 | + } |
| 143 | + |
121 | 144 | @Test |
122 | 145 | void shouldAddManifests() { |
123 | 146 | Index index = Index.fromManifests(List.of()); |
|
0 commit comments