Skip to content

Commit 9ddb42c

Browse files
authored
Add withArtifactType for Index (#590)
Signed-off-by: Valentin Delaye <jonesbusy@users.noreply.github.com>
1 parent 202cad1 commit 9ddb42c

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

src/main/java/land/oras/Index.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,16 @@ public ManifestDescriptor getDescriptor() {
205205
return null;
206206
}
207207

208+
/**
209+
* Return a new index with the given artifact type
210+
* @param artifactType The artifact type
211+
* @return The index
212+
*/
213+
public Index withArtifactType(String artifactType) {
214+
return new Index(
215+
schemaVersion, mediaType, artifactType, manifests, annotations, subject, descriptor, registry, json);
216+
}
217+
208218
/**
209219
* Return a new index with the given descriptor
210220
* @param descriptor The descriptor

src/test/java/land/oras/IndexTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ void shouldReadAndWriteIndex() {
5555
result);
5656
}
5757

58+
@Test
59+
void shouldAddArtifactType() {
60+
Index index = Index.fromManifests(List.of());
61+
index = index.withArtifactType("application/vnd.opentofu.provider");
62+
assertNotNull(index.getArtifactType());
63+
assertEquals(
64+
"application/vnd.opentofu.provider", index.getArtifactType().getMediaType());
65+
assertEquals(
66+
"{\"schemaVersion\":2,\"mediaType\":\"application/vnd.oci.image.index.v1+json\",\"artifactType\":\"application/vnd.opentofu.provider\",\"manifests\":[]}",
67+
index.toJson());
68+
}
69+
5870
@Test
5971
void shouldReadAndWriteIndexWithAnnotations() {
6072
String json =

0 commit comments

Comments
 (0)