File tree 4 files changed +24
-5
lines changed
4 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -1187,7 +1187,7 @@ func (r *HelmChartReconciler) indexHelmRepositoryByURL(o client.Object) []string
1187
1187
panic (fmt .Sprintf ("Expected a HelmRepository, got %T" , o ))
1188
1188
}
1189
1189
u , err := repository .NormalizeURL (repo .Spec .URL )
1190
- if u != "" && err ! = nil {
1190
+ if u != "" && err = = nil {
1191
1191
return []string {u }
1192
1192
}
1193
1193
return nil
Original file line number Diff line number Diff line change @@ -268,7 +268,7 @@ func (dm *DependencyManager) resolveRepository(url string) (repo repository.Down
268
268
269
269
nUrl , err := repository .NormalizeURL (url )
270
270
if err != nil {
271
- return nil , err
271
+ return
272
272
}
273
273
err = repository .ValidateDepURL (nUrl )
274
274
if err != nil {
Original file line number Diff line number Diff line change 37
37
38
38
// NormalizeURL normalizes a ChartRepository URL by its scheme.
39
39
func NormalizeURL (repositoryURL string ) (string , error ) {
40
+ if repositoryURL == "" {
41
+ return "" , nil
42
+ }
40
43
u , err := url .Parse (repositoryURL )
41
44
if err != nil {
42
45
return "" , err
Original file line number Diff line number Diff line change @@ -24,9 +24,10 @@ import (
24
24
25
25
func TestNormalizeURL (t * testing.T ) {
26
26
tests := []struct {
27
- name string
28
- url string
29
- want string
27
+ name string
28
+ url string
29
+ want string
30
+ wantErr bool
30
31
}{
31
32
{
32
33
name : "with slash" ,
@@ -63,12 +64,27 @@ func TestNormalizeURL(t *testing.T) {
63
64
url : "http://example.com/?st=pr" ,
64
65
want : "http://example.com/?st=pr" ,
65
66
},
67
+ {
68
+ name : "empty url" ,
69
+ url : "" ,
70
+ want : "" ,
71
+ },
72
+ {
73
+ name : "bad url" ,
74
+ url : "://badurl." ,
75
+ wantErr : true ,
76
+ },
66
77
}
67
78
for _ , tt := range tests {
68
79
t .Run (tt .name , func (t * testing.T ) {
69
80
g := NewWithT (t )
70
81
71
82
got , err := NormalizeURL (tt .url )
83
+ if tt .wantErr {
84
+ g .Expect (err ).To (HaveOccurred ())
85
+ return
86
+ }
87
+
72
88
g .Expect (err ).To (Not (HaveOccurred ()))
73
89
g .Expect (got ).To (Equal (tt .want ))
74
90
})
You can’t perform that action at this time.
0 commit comments