@@ -20,6 +20,7 @@ import (
2020 "bytes"
2121 "fmt"
2222 "net/url"
23+ "path"
2324 "strings"
2425 "testing"
2526
@@ -46,8 +47,8 @@ type mockRegistryClient struct {
4647 LastCalledURL string
4748}
4849
49- func (m * mockRegistryClient ) Tags (url string ) ([]string , error ) {
50- m .LastCalledURL = url
50+ func (m * mockRegistryClient ) Tags (urlStr string ) ([]string , error ) {
51+ m .LastCalledURL = urlStr
5152 return m .tags , nil
5253}
5354
@@ -91,7 +92,7 @@ func TestNewOCIChartRepository(t *testing.T) {
9192
9293}
9394
94- func TestOCIChartRepoisitory_Get (t * testing.T ) {
95+ func TestOCIChartRepository_Get (t * testing.T ) {
9596 registryClient := & mockRegistryClient {
9697 tags : []string {
9798 "0.0.1" ,
@@ -114,55 +115,70 @@ func TestOCIChartRepoisitory_Get(t *testing.T) {
114115 New : helmgetter .NewOCIGetter ,
115116 },
116117 }
118+ testURL := "oci://localhost:5000/my_repo"
117119
118120 testCases := []struct {
119121 name string
122+ url string
120123 version string
121124 expected string
122125 expectedErr string
123126 }{
124127 {
125128 name : "should return latest stable version" ,
126129 version : "" ,
130+ url : testURL ,
127131 expected : "1.0.0" ,
128132 },
129133 {
130134 name : "should return latest stable version (asterisk)" ,
131135 version : "*" ,
136+ url : testURL ,
132137 expected : "1.0.0" ,
133138 },
134139 {
135140 name : "should return latest stable version (semver range)" ,
136141 version : ">=0.1.5" ,
142+ url : testURL ,
137143 expected : "1.0.0" ,
138144 },
139145 {
140146 name : "should return 0.2.0 (semver range)" ,
141147 version : "0.2.x" ,
148+ url : testURL ,
142149 expected : "0.2.0" ,
143150 },
144151 {
145152 name : "should return a perfect match" ,
146153 version : "0.1.0" ,
154+ url : testURL ,
147155 expected : "0.1.0" ,
148156 },
149157 {
150158 name : "should return 0.10.0" ,
151159 version : "0.*" ,
160+ url : testURL ,
152161 expected : "0.10.0" ,
153162 },
154163 {
155164 name : "should an error for unfunfilled range" ,
156165 version : ">2.0.0" ,
166+ url : testURL ,
157167 expectedErr : "could not locate a version matching provided version string >2.0.0" ,
158168 },
169+ {
170+ name : "shouldn't error out with trailing slash" ,
171+ version : "" ,
172+ url : "oci://localhost:5000/my_repo/" ,
173+ expected : "1.0.0" ,
174+ },
159175 }
160176
161- url := "oci://localhost:5000/my_repo"
162177 for _ , tc := range testCases {
178+
163179 t .Run (tc .name , func (t * testing.T ) {
164180 g := NewWithT (t )
165- r , err := NewOCIChartRepository (url , WithOCIRegistryClient (registryClient ), WithOCIGetter (providers ))
181+ r , err := NewOCIChartRepository (tc . url , WithOCIRegistryClient (registryClient ), WithOCIGetter (providers ))
166182 g .Expect (err ).ToNot (HaveOccurred ())
167183 g .Expect (r ).ToNot (BeNil ())
168184
@@ -173,15 +189,18 @@ func TestOCIChartRepoisitory_Get(t *testing.T) {
173189 g .Expect (err .Error ()).To (Equal (tc .expectedErr ))
174190 return
175191 }
192+ g .Expect (err ).ToNot (HaveOccurred ())
176193
194+ u , err := url .Parse (tc .url )
177195 g .Expect (err ).ToNot (HaveOccurred ())
178- g .Expect (cv .URLs [0 ]).To (Equal (fmt .Sprintf ("%s/%s:%s" , url , chart , tc .expected )))
179- g .Expect (registryClient .LastCalledURL ).To (Equal (fmt .Sprintf ("%s/%s" , strings .TrimPrefix (url , fmt .Sprintf ("%s://" , registry .OCIScheme )), chart )))
196+ u .Path = path .Join (u .Path , chart )
197+ g .Expect (cv .URLs [0 ]).To (Equal (fmt .Sprintf ("%s:%s" , u .String (), tc .expected )))
198+ g .Expect (registryClient .LastCalledURL ).To (Equal (strings .TrimPrefix (u .String (), fmt .Sprintf ("%s://" , registry .OCIScheme ))))
180199 })
181200 }
182201}
183202
184- func TestOCIChartRepoisitory_DownloadChart (t * testing.T ) {
203+ func TestOCIChartRepository_DownloadChart (t * testing.T ) {
185204 client := & mockRegistryClient {}
186205 testCases := []struct {
187206 name string
0 commit comments