@@ -20,6 +20,7 @@ import (
20
20
"bytes"
21
21
"fmt"
22
22
"net/url"
23
+ "path"
23
24
"strings"
24
25
"testing"
25
26
@@ -46,8 +47,8 @@ type mockRegistryClient struct {
46
47
LastCalledURL string
47
48
}
48
49
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
51
52
return m .tags , nil
52
53
}
53
54
@@ -91,7 +92,7 @@ func TestNewOCIChartRepository(t *testing.T) {
91
92
92
93
}
93
94
94
- func TestOCIChartRepoisitory_Get (t * testing.T ) {
95
+ func TestOCIChartRepository_Get (t * testing.T ) {
95
96
registryClient := & mockRegistryClient {
96
97
tags : []string {
97
98
"0.0.1" ,
@@ -114,55 +115,70 @@ func TestOCIChartRepoisitory_Get(t *testing.T) {
114
115
New : helmgetter .NewOCIGetter ,
115
116
},
116
117
}
118
+ testURL := "oci://localhost:5000/my_repo"
117
119
118
120
testCases := []struct {
119
121
name string
122
+ url string
120
123
version string
121
124
expected string
122
125
expectedErr string
123
126
}{
124
127
{
125
128
name : "should return latest stable version" ,
126
129
version : "" ,
130
+ url : testURL ,
127
131
expected : "1.0.0" ,
128
132
},
129
133
{
130
134
name : "should return latest stable version (asterisk)" ,
131
135
version : "*" ,
136
+ url : testURL ,
132
137
expected : "1.0.0" ,
133
138
},
134
139
{
135
140
name : "should return latest stable version (semver range)" ,
136
141
version : ">=0.1.5" ,
142
+ url : testURL ,
137
143
expected : "1.0.0" ,
138
144
},
139
145
{
140
146
name : "should return 0.2.0 (semver range)" ,
141
147
version : "0.2.x" ,
148
+ url : testURL ,
142
149
expected : "0.2.0" ,
143
150
},
144
151
{
145
152
name : "should return a perfect match" ,
146
153
version : "0.1.0" ,
154
+ url : testURL ,
147
155
expected : "0.1.0" ,
148
156
},
149
157
{
150
158
name : "should return 0.10.0" ,
151
159
version : "0.*" ,
160
+ url : testURL ,
152
161
expected : "0.10.0" ,
153
162
},
154
163
{
155
164
name : "should an error for unfunfilled range" ,
156
165
version : ">2.0.0" ,
166
+ url : testURL ,
157
167
expectedErr : "could not locate a version matching provided version string >2.0.0" ,
158
168
},
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
+ },
159
175
}
160
176
161
- url := "oci://localhost:5000/my_repo"
162
177
for _ , tc := range testCases {
178
+
163
179
t .Run (tc .name , func (t * testing.T ) {
164
180
g := NewWithT (t )
165
- r , err := NewOCIChartRepository (url , WithOCIRegistryClient (registryClient ), WithOCIGetter (providers ))
181
+ r , err := NewOCIChartRepository (tc . url , WithOCIRegistryClient (registryClient ), WithOCIGetter (providers ))
166
182
g .Expect (err ).ToNot (HaveOccurred ())
167
183
g .Expect (r ).ToNot (BeNil ())
168
184
@@ -173,15 +189,18 @@ func TestOCIChartRepoisitory_Get(t *testing.T) {
173
189
g .Expect (err .Error ()).To (Equal (tc .expectedErr ))
174
190
return
175
191
}
192
+ g .Expect (err ).ToNot (HaveOccurred ())
176
193
194
+ u , err := url .Parse (tc .url )
177
195
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 ))))
180
199
})
181
200
}
182
201
}
183
202
184
- func TestOCIChartRepoisitory_DownloadChart (t * testing.T ) {
203
+ func TestOCIChartRepository_DownloadChart (t * testing.T ) {
185
204
client := & mockRegistryClient {}
186
205
testCases := []struct {
187
206
name string
0 commit comments