2323import static org .junit .jupiter .api .Assertions .assertNotNull ;
2424
2525import 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 ;
2630import org .junit .jupiter .api .Disabled ;
2731import org .junit .jupiter .api .Test ;
2832import 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 () {
0 commit comments