Skip to content

Commit 9b97f31

Browse files
authored
Add test to package a standard Flux Artifact (#576)
2 parents 6d63912 + c434724 commit 9b97f31

3 files changed

Lines changed: 89 additions & 1 deletion

File tree

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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.io.TempDir;
33+
import org.junit.jupiter.api.parallel.Execution;
34+
import org.junit.jupiter.api.parallel.ExecutionMode;
35+
import org.testcontainers.junit.jupiter.Container;
36+
import org.testcontainers.junit.jupiter.Testcontainers;
37+
38+
@Testcontainers
39+
@Execution(ExecutionMode.CONCURRENT)
40+
class FluxCDITCase {
41+
42+
@TempDir
43+
Path tempDir;
44+
45+
@Container
46+
private final ZotUnsecureContainer unsecureRegistry = new ZotUnsecureContainer().withStartupAttempts(3);
47+
48+
/**
49+
* This test demonstrate how to assemble a Flux CD OCI Artifact
50+
*/
51+
@Test
52+
void shouldAssembleArtifact() {
53+
54+
// The compressed manifests
55+
Path archive = Paths.get("src/test/resources/archives").resolve("flux-manifests.tgz");
56+
String configMediaType = "application/vnd.cncf.flux.config.v1+json";
57+
String contentMediaType = "application/vnd.cncf.flux.content.v1.tar+gzip";
58+
59+
Map<String, String> annotations = Map.of(
60+
Const.ANNOTATION_REVISION, "@sha1:6d63912ed9a9443dd01fbfd2991173a246050079",
61+
Const.ANNOTATION_SOURCE, "git@github.com:jonesbusy/oras-java.git",
62+
Const.ANNOTATION_CREATED, Const.currentTimestamp());
63+
64+
// Create objects
65+
Config config = Config.empty().withMediaType(configMediaType);
66+
Layer layer = Layer.fromFile(archive).withMediaType(contentMediaType);
67+
Manifest manifest =
68+
Manifest.empty().withConfig(config).withLayers(List.of(layer)).withAnnotations(annotations);
69+
70+
// Push config, layers and manifest to registry
71+
Registry registry = Registry.builder()
72+
.insecure()
73+
.withRegistry(unsecureRegistry.getRegistry())
74+
.build();
75+
ContainerRef containerRef = ContainerRef.parse("manifests:latest");
76+
77+
registry.pushConfig(containerRef, config);
78+
registry.pushBlob(containerRef, archive);
79+
registry.pushManifest(containerRef, manifest);
80+
81+
// Ensure we can pull
82+
Manifest createdManifest = registry.getManifest(containerRef);
83+
assertNotNull(createdManifest);
84+
85+
// We can test pull with flux pull artifact oci://localhost:<port>/manifests:latest --output .
86+
87+
}
88+
}

src/test/java/land/oras/utils/ArchiveUtilsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ void shouldCreateTarGzAndExtractIt() throws Exception {
199199
}
200200

201201
@ParameterizedTest
202-
@ValueSource(strings = {"jenkins-chart.tgz", "jenkins-sources.tar.gz"})
202+
@ValueSource(strings = {"jenkins-chart.tgz", "jenkins-sources.tar.gz", "flux-manifests.tgz"})
203203
@Disabled("https://issues.apache.org/jira/browse/COMPRESS-705")
204204
void shouldExtractSeveralExistingArchive(String file) {
205205
Path archive = Paths.get("src/test/resources/archives").resolve(file);
180 KB
Binary file not shown.

0 commit comments

Comments
 (0)