forked from oras-project/oras-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathManifestTest.java
More file actions
105 lines (95 loc) · 3.77 KB
/
ManifestTest.java
File metadata and controls
105 lines (95 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package land.oras;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.junit.jupiter.Testcontainers;
@Testcontainers
public class ManifestTest {
/**
* Logger
*/
private static final Logger LOG = LoggerFactory.getLogger(ManifestTest.class);
@Test
void shouldReadManifest() {
String json = sampleManifest();
Manifest manifest = Manifest.fromJson(json);
// Assert manifest
assertEquals(2, manifest.getSchemaVersion());
assertEquals("application/vnd.oci.image.manifest.v1+json", manifest.getMediaType());
assertEquals(7023, manifest.getConfig().getSize());
assertEquals(
"sha256:abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890",
manifest.getConfig().getDigest());
assertEquals(
"application/vnd.oci.image.config.v1+json", manifest.getConfig().getMediaType());
assertEquals(2, manifest.getLayers().size());
assertEquals(0, manifest.getAnnotations().size());
// Assert layer
assertEquals(32654, manifest.getLayers().get(0).getSize());
assertEquals(
"sha256:abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890",
manifest.getLayers().get(0).getDigest());
assertEquals(
"application/vnd.oci.image.layer.v1.tar+gzip",
manifest.getLayers().get(0).getMediaType());
assertEquals(1048576, manifest.getLayers().get(1).getSize());
assertEquals(
"sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
manifest.getLayers().get(1).getDigest());
assertEquals(
"application/vnd.oci.image.layer.v1.tar+gzip",
manifest.getLayers().get(1).getMediaType());
manifest.toJson();
}
@Test
void shouldHaveEmptyManifest() {
assertEquals(
Manifest.fromJson(emptyManifest()).toJson(), Manifest.empty().toJson());
}
private String emptyManifest() {
return """
{
"schemaVersion": 2,
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"config": {
"mediaType": "application/vnd.oci.empty.v1+json",
"digest": "sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a",
"size": 2,
"annotations": {}
},
"layers": [],
"annotations": {}
}
""";
}
/**
* A sample manifest
* @return The manifest
*/
private String sampleManifest() {
return """
{
"schemaVersion": 2,
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"config": {
"mediaType": "application/vnd.oci.image.config.v1+json",
"digest": "sha256:abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890",
"size": 7023
},
"layers": [
{
"mediaType": "application/vnd.oci.image.layer.v1.tar+gzip",
"digest": "sha256:abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890",
"size": 32654
},
{
"mediaType": "application/vnd.oci.image.layer.v1.tar+gzip",
"digest": "sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
"size": 1048576
}
]
}
""";
}
}