@@ -36,6 +36,62 @@ import (
36
36
var validRepoIndexYAMLBytes , _ = os .ReadFile ("testdata/valid-index.yaml" )
37
37
var validRepoIndexYAML = string (validRepoIndexYAMLBytes )
38
38
39
+ const chartsIndexManifestJSON = `
40
+ {
41
+ "schemaVersion": 2,
42
+ "config": {
43
+ "mediaType": "application/vnd.vmware.charts.index.config.v1+json",
44
+ "digest": "sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a",
45
+ "size": 2
46
+ },
47
+ "layers": [
48
+ {
49
+ "mediaType": "application/vnd.vmware.charts.index.layer.v1+json",
50
+ "digest": "sha256:f9f7df0ae3f50aaf9ff390034cec4286d2aa43f061ce4bc7aa3c9ac862800aba",
51
+ "size": 1169,
52
+ "annotations": {
53
+ "org.opencontainers.image.title": "charts-index.json"
54
+ }
55
+ }
56
+ ]
57
+ }
58
+ `
59
+ const chartsIndexJSON = `
60
+ {
61
+ "entries": {
62
+ "common": {
63
+ "versions": [
64
+ {
65
+ "version": "2.4.0",
66
+ "appVersion": "2.4.0",
67
+ "name": "common",
68
+ "urls": [
69
+ "harbor.example.com/charts/common:2.4.0"
70
+ ],
71
+ "digest": "sha256:c85139bbe83ec5af6201fe1bec39fc0d0db475de41bc74cd729acc5af8eed6ba",
72
+ "releasedAt": "2023-06-08T12:15:48.149853788Z"
73
+ }
74
+ ]
75
+ },
76
+ "redis": {
77
+ "versions": [
78
+ {
79
+ "version": "17.11.0",
80
+ "appVersion": "7.0.11",
81
+ "name": "redis",
82
+ "urls": [
83
+ "harbor.example.com/charts/redis:17.11.0"
84
+ ],
85
+ "digest": "sha256:45925becfe9aa2c6c4741c9fe1dd0ddca627894b696755c73830e4ae6b390c35",
86
+ "releasedAt": "2023-06-09T11:50:48.144176763Z"
87
+ }
88
+ ]
89
+ }
90
+ },
91
+ "apiVersion": "v1"
92
+ }
93
+ `
94
+
39
95
type badHTTPClient struct {
40
96
errMsg string
41
97
}
@@ -797,6 +853,63 @@ func Test_ociAPICli(t *testing.T) {
797
853
t .Errorf ("Tag 8.1.1 should be a helm chart" )
798
854
}
799
855
})
856
+
857
+ urlWithNamespace , _ := parseRepoURL ("http://oci-test/test/project" )
858
+ t .Run ("CatalogAvailable - successful request" , func (t * testing.T ) {
859
+ apiCli := & ociAPICli {
860
+ url : urlWithNamespace ,
861
+ netClient : & goodOCIAPIHTTPClient {
862
+ responseByPath : map [string ]string {
863
+ "/v2/test/project/charts-index/manifests/latest" : chartsIndexManifestJSON ,
864
+ },
865
+ },
866
+ }
867
+
868
+ if got , want := apiCli .CatalogAvailable ("my-user-agent" ), true ; got != want {
869
+ t .Errorf ("got: %t, want: %t" , got , want )
870
+ }
871
+ })
872
+
873
+ t .Run ("CatalogAvailable - returns false for incorrect media type" , func (t * testing.T ) {
874
+ apiCli := & ociAPICli {
875
+ url : urlWithNamespace ,
876
+ netClient : & goodOCIAPIHTTPClient {
877
+ responseByPath : map [string ]string {
878
+ "/v2/test/project/charts-index/manifests/latest" : `{"config": {"mediaType": "something-else"}}` ,
879
+ },
880
+ },
881
+ }
882
+
883
+ if got , want := apiCli .CatalogAvailable ("my-user-agent" ), false ; got != want {
884
+ t .Errorf ("got: %t, want: %t" , got , want )
885
+ }
886
+ })
887
+
888
+ t .Run ("CatalogAvailable - returns false for a 404" , func (t * testing.T ) {
889
+ apiCli := & ociAPICli {
890
+ url : urlWithNamespace ,
891
+ netClient : & goodOCIAPIHTTPClient {
892
+ responseByPath : map [string ]string {
893
+ "/v2/test/project/chart-index/manifests/latest" : chartsIndexJSON ,
894
+ },
895
+ },
896
+ }
897
+
898
+ if got , want := apiCli .CatalogAvailable ("my-user-agent" ), false ; got != want {
899
+ t .Errorf ("got: %t, want: %t" , got , want )
900
+ }
901
+ })
902
+
903
+ t .Run ("CatalogAvailable - returns false on any other" , func (t * testing.T ) {
904
+ apiCli := & ociAPICli {
905
+ url : urlWithNamespace ,
906
+ netClient : & badHTTPClient {},
907
+ }
908
+
909
+ if got , want := apiCli .CatalogAvailable ("my-user-agent" ), false ; got != want {
910
+ t .Errorf ("got: %t, want: %t" , got , want )
911
+ }
912
+ })
800
913
}
801
914
802
915
type fakeOCIAPICli struct {
@@ -812,6 +925,10 @@ func (o *fakeOCIAPICli) IsHelmChart(appName, tag, userAgent string) (bool, error
812
925
return true , o .err
813
926
}
814
927
928
+ func (o * fakeOCIAPICli ) CatalogAvailable (userAgent string ) bool {
929
+ return false
930
+ }
931
+
815
932
func Test_OCIRegistry (t * testing.T ) {
816
933
repo := OCIRegistry {
817
934
repositories : []string {"apache" , "jenkins" },
0 commit comments