-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathchart_test.go
97 lines (89 loc) · 2.06 KB
/
chart_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package helm_test
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
helmutils "github.com/operator-framework/operator-controller/internal/shared/util/helm"
)
func TestIsChart(t *testing.T) {
type response struct {
Oci bool
Chart bool
}
tt := []struct {
name string
url string
want response
wantErr bool
}{
{
name: "pull helm chart using image tag",
url: "quay.io/eochieng/metrics-server:3.12.0",
want: response{
Oci: true,
Chart: true,
},
wantErr: false,
},
{
name: "pull helm chart using image digest",
url: "quay.io/eochieng/metrics-server@sha256:dd56f2ccc6e29ba7a2c5492e12c8210fb7367771eca93380a8dd64a6c9c985cb",
want: response{
Oci: true,
Chart: true,
},
wantErr: false,
},
{
name: "pull helm chart from HTTP repository",
url: "https://github.com/kubernetes-sigs/metrics-server/releases/download/metrics-server-helm-chart-3.12.0/metrics-server-3.12.0.tgz",
want: response{
Oci: false,
Chart: true,
},
wantErr: false,
},
{
name: "pull helm chart with oci scheme",
url: "oci://quay.io/eochieng/metrics-server@sha256:dd56f2ccc6e29ba7a2c5492e12c8210fb7367771eca93380a8dd64a6c9c985cb",
want: response{
Oci: false,
Chart: false,
},
wantErr: true,
},
{
name: "pull kubernetes web page",
url: "https://kubernetes.io",
want: response{
Oci: false,
Chart: false,
},
wantErr: true,
},
{
name: "pull busybox image from OCI registry",
url: "quay.io/opdev/busybox:latest",
want: response{
Oci: true,
Chart: false,
},
wantErr: true,
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
response, err := helmutils.IsChart(context.Background(), tc.url)
assert.Equal(t, response.Oci, tc.want.Oci)
assert.Equal(t, response.Chart, tc.want.Chart)
if testing.Verbose() {
t.Logf("IsChart() is checking if %s is a helm chart.\n", tc.url)
}
if !tc.wantErr {
assert.NoError(t, err)
} else {
assert.Error(t, err, "helm chart not found")
}
})
}
}