Skip to content

Commit 69f073e

Browse files
committed
More tests
Signed-off-by: Valentin Delaye <jonesbusy@users.noreply.github.com>
1 parent 9b97f31 commit 69f073e

4 files changed

Lines changed: 167 additions & 4 deletions

File tree

src/main/java/land/oras/utils/Const.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ private Const() {
199199
*/
200200
public static final String ANNOTATION_TITLE = "org.opencontainers.image.title";
201201

202+
/**
203+
* Annotation for the description
204+
*/
205+
public static final String ANNOTATION_DESCRIPTION = "org.opencontainers.image.description";
206+
202207
/**
203208
* Annotation for the crated date
204209
*/

src/test/java/land/oras/FluxCDITCase.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import land.oras.utils.Const;
3030
import land.oras.utils.ZotUnsecureContainer;
3131
import org.junit.jupiter.api.Test;
32-
import org.junit.jupiter.api.io.TempDir;
3332
import org.junit.jupiter.api.parallel.Execution;
3433
import org.junit.jupiter.api.parallel.ExecutionMode;
3534
import org.testcontainers.junit.jupiter.Container;
@@ -39,9 +38,6 @@
3938
@Execution(ExecutionMode.CONCURRENT)
4039
class FluxCDITCase {
4140

42-
@TempDir
43-
Path tempDir;
44-
4541
@Container
4642
private final ZotUnsecureContainer unsecureRegistry = new ZotUnsecureContainer().withStartupAttempts(3);
4743

src/test/java/land/oras/HarborS3ITCase.java

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
import static org.junit.jupiter.api.Assertions.assertNotNull;
2424

2525
import java.nio.file.Path;
26+
import java.nio.file.Paths;
27+
import java.util.List;
28+
import java.util.Map;
29+
import land.oras.utils.Const;
2630
import org.junit.jupiter.api.Disabled;
2731
import org.junit.jupiter.api.Test;
2832
import org.junit.jupiter.api.io.TempDir;
@@ -40,6 +44,80 @@ class HarborS3ITCase {
4044
@TempDir
4145
Path tempDir;
4246

47+
/**
48+
* This test demonstrate how to assemble a Flux CD OCI Artifact
49+
*/
50+
@Test
51+
void shouldPushHelmArtifact() {
52+
53+
// The compressed manifests
54+
Path archive = Paths.get("src/test/resources/archives").resolve("jenkins-chart.tgz");
55+
String configMediaType = "application/vnd.cncf.helm.config.v1+json";
56+
String contentMediaType = "application/vnd.cncf.helm.chart.content.v1.tar+gzip";
57+
58+
Map<String, String> annotations = Map.of(
59+
Const.ANNOTATION_DESCRIPTION, "Test helm chart",
60+
Const.ANNOTATION_SOURCE, "git@github.com:jonesbusy/oras-java.git",
61+
Const.ANNOTATION_CREATED, Const.currentTimestamp());
62+
63+
// Create objects
64+
Config config = Config.empty().withMediaType(configMediaType);
65+
Layer layer = Layer.fromFile(archive).withMediaType(contentMediaType);
66+
Manifest manifest =
67+
Manifest.empty().withConfig(config).withLayers(List.of(layer)).withAnnotations(annotations);
68+
69+
// Push config, layers and manifest to registry
70+
Registry registry = Registry.builder().defaults().build();
71+
ContainerRef containerRef = ContainerRef.parse("demo.goharbor.io/oras/chart:0.1.0");
72+
73+
registry.pushConfig(containerRef, config);
74+
registry.pushBlob(containerRef, archive);
75+
registry.pushManifest(containerRef, manifest);
76+
77+
// Ensure we can pull
78+
Manifest createdManifest = registry.getManifest(containerRef);
79+
assertNotNull(createdManifest);
80+
81+
// We can test pull with helm pull oci://demo.goharbor.io/oras/chart --version 0.1.0
82+
83+
}
84+
85+
@Test
86+
@Disabled
87+
void shouldPushFluxArtifact() {
88+
89+
// The compressed manifests
90+
Path archive = Paths.get("src/test/resources/archives").resolve("flux-manifests.tgz");
91+
String configMediaType = "application/vnd.cncf.flux.config.v1+json";
92+
String contentMediaType = "application/vnd.cncf.flux.content.v1.tar+gzip";
93+
94+
Map<String, String> annotations = Map.of(
95+
Const.ANNOTATION_REVISION, "@sha1:6d63912ed9a9443dd01fbfd2991173a246050079",
96+
Const.ANNOTATION_SOURCE, "git@github.com:jonesbusy/oras-java.git",
97+
Const.ANNOTATION_CREATED, Const.currentTimestamp());
98+
99+
// Create objects
100+
Config config = Config.empty().withMediaType(configMediaType);
101+
Layer layer = Layer.fromFile(archive).withMediaType(contentMediaType);
102+
Manifest manifest =
103+
Manifest.empty().withConfig(config).withLayers(List.of(layer)).withAnnotations(annotations);
104+
105+
// Push config, layers and manifest to registry
106+
Registry registry = Registry.builder().defaults().build();
107+
ContainerRef containerRef = ContainerRef.parse("demo.goharbor.io/oras/flux:latest");
108+
109+
registry.pushConfig(containerRef, config);
110+
registry.pushBlob(containerRef, archive);
111+
registry.pushManifest(containerRef, manifest);
112+
113+
// Ensure we can pull
114+
Manifest createdManifest = registry.getManifest(containerRef);
115+
assertNotNull(createdManifest);
116+
117+
// We can test pull with flux pull artifact oci://demo.goharbor.io/oras/flux:latest --output .
118+
119+
}
120+
43121
@Test
44122
@Disabled("Only to test with demo Harbor demo instance")
45123
void shouldGetManifest() {
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*-
2+
* =LICENSE=
3+
* ORAS Java SDK
4+
* ===
5+
* Copyright (C) 2024 - 2026 ORAS
6+
* ===
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* =LICENSEEND=
19+
*/
20+
21+
package land.oras;
22+
23+
import static org.junit.jupiter.api.Assertions.assertNotNull;
24+
25+
import java.nio.file.Path;
26+
import java.nio.file.Paths;
27+
import java.util.List;
28+
import java.util.Map;
29+
import land.oras.utils.Const;
30+
import land.oras.utils.ZotUnsecureContainer;
31+
import org.junit.jupiter.api.Test;
32+
import org.junit.jupiter.api.parallel.Execution;
33+
import org.junit.jupiter.api.parallel.ExecutionMode;
34+
import org.testcontainers.junit.jupiter.Container;
35+
import org.testcontainers.junit.jupiter.Testcontainers;
36+
37+
@Testcontainers
38+
@Execution(ExecutionMode.CONCURRENT)
39+
class HelmITCase {
40+
41+
@Container
42+
private final ZotUnsecureContainer unsecureRegistry = new ZotUnsecureContainer().withStartupAttempts(3);
43+
44+
/**
45+
* This test demonstrate how to assemble a Flux CD OCI Artifact
46+
*/
47+
@Test
48+
void shouldAssembleArtifact() {
49+
50+
// The compressed manifests
51+
Path archive = Paths.get("src/test/resources/archives").resolve("jenkins-chart.tgz");
52+
String configMediaType = "application/vnd.cncf.helm.config.v1+json";
53+
String contentMediaType = "application/vnd.cncf.helm.chart.content.v1.tar+gzip";
54+
55+
Map<String, String> annotations = Map.of(
56+
Const.ANNOTATION_DESCRIPTION, "Test helm chart",
57+
Const.ANNOTATION_SOURCE, "git@github.com:jonesbusy/oras-java.git",
58+
Const.ANNOTATION_CREATED, Const.currentTimestamp());
59+
60+
// Create objects
61+
Config config = Config.empty().withMediaType(configMediaType);
62+
Layer layer = Layer.fromFile(archive).withMediaType(contentMediaType);
63+
Manifest manifest =
64+
Manifest.empty().withConfig(config).withLayers(List.of(layer)).withAnnotations(annotations);
65+
66+
// Push config, layers and manifest to registry
67+
Registry registry = Registry.builder()
68+
.insecure()
69+
.withRegistry(unsecureRegistry.getRegistry())
70+
.build();
71+
ContainerRef containerRef = ContainerRef.parse("chart:0.1.0");
72+
73+
registry.pushConfig(containerRef, config);
74+
registry.pushBlob(containerRef, archive);
75+
registry.pushManifest(containerRef, manifest);
76+
77+
// Ensure we can pull
78+
Manifest createdManifest = registry.getManifest(containerRef);
79+
assertNotNull(createdManifest);
80+
81+
// We can test pull with helm pull oci://localhost:<port>/chart --plain-http --version 0.1.0
82+
83+
}
84+
}

0 commit comments

Comments
 (0)