@@ -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" ,
@@ -117,52 +118,66 @@ func TestOCIChartRepoisitory_Get(t *testing.T) {
117
118
118
119
testCases := []struct {
119
120
name string
121
+ url string
120
122
version string
121
123
expected string
122
124
expectedErr string
123
125
}{
124
126
{
125
127
name : "should return latest stable version" ,
126
128
version : "" ,
129
+ url : "oci://localhost:5000/my_repo" ,
127
130
expected : "1.0.0" ,
128
131
},
129
132
{
130
133
name : "should return latest stable version (asterisk)" ,
131
134
version : "*" ,
135
+ url : "oci://localhost:5000/my_repo" ,
132
136
expected : "1.0.0" ,
133
137
},
134
138
{
135
139
name : "should return latest stable version (semver range)" ,
136
140
version : ">=0.1.5" ,
141
+ url : "oci://localhost:5000/my_repo" ,
137
142
expected : "1.0.0" ,
138
143
},
139
144
{
140
145
name : "should return 0.2.0 (semver range)" ,
141
146
version : "0.2.x" ,
147
+ url : "oci://localhost:5000/my_repo" ,
142
148
expected : "0.2.0" ,
143
149
},
144
150
{
145
151
name : "should return a perfect match" ,
146
152
version : "0.1.0" ,
153
+ url : "oci://localhost:5000/my_repo" ,
147
154
expected : "0.1.0" ,
148
155
},
149
156
{
150
157
name : "should return 0.10.0" ,
151
158
version : "0.*" ,
159
+ url : "oci://localhost:5000/my_repo" ,
152
160
expected : "0.10.0" ,
153
161
},
154
162
{
155
163
name : "should an error for unfunfilled range" ,
156
164
version : ">2.0.0" ,
165
+ url : "oci://localhost:5000/my_repo" ,
157
166
expectedErr : "could not locate a version matching provided version string >2.0.0" ,
158
167
},
168
+ {
169
+ name : "shouldn't error out with trailing slash" ,
170
+ version : "" ,
171
+ url : "oci://localhost:5000/my_repo/" ,
172
+ expected : "1.0.0" ,
173
+ },
159
174
}
160
175
161
- url := "oci://localhost:5000/my_repo"
162
176
for _ , tc := range testCases {
177
+
163
178
t .Run (tc .name , func (t * testing.T ) {
164
179
g := NewWithT (t )
165
- r , err := NewOCIChartRepository (url , WithOCIRegistryClient (registryClient ), WithOCIGetter (providers ))
180
+ r , err := NewOCIChartRepository (tc . url , WithOCIRegistryClient (registryClient ), WithOCIGetter (providers ))
166
181
g .Expect (err ).ToNot (HaveOccurred ())
167
182
g .Expect (r ).ToNot (BeNil ())
168
183
@@ -173,15 +188,18 @@ func TestOCIChartRepoisitory_Get(t *testing.T) {
173
188
g .Expect (err .Error ()).To (Equal (tc .expectedErr ))
174
189
return
175
190
}
191
+ g .Expect (err ).ToNot (HaveOccurred ())
176
192
193
+ u , err := url .Parse (tc .url )
177
194
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 )))
195
+ u .Path = path .Join (u .Path , chart )
196
+ g .Expect (cv .URLs [0 ]).To (Equal (fmt .Sprintf ("%s:%s" , u .String (), tc .expected )))
197
+ g .Expect (registryClient .LastCalledURL ).To (Equal (strings .TrimPrefix (u .String (), fmt .Sprintf ("%s://" , registry .OCIScheme ))))
180
198
})
181
199
}
182
200
}
183
201
184
- func TestOCIChartRepoisitory_DownloadChart (t * testing.T ) {
202
+ func TestOCIChartRepository_DownloadChart (t * testing.T ) {
185
203
client := & mockRegistryClient {}
186
204
testCases := []struct {
187
205
name string
0 commit comments