forked from helmfile/chartify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchartify_test.go
113 lines (101 loc) · 2.24 KB
/
chartify_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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package chartify
import (
"os"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/require"
)
func TestReadAdhocDependencies(t *testing.T) {
type testcase struct {
opts ChartifyOpts
wantDendency []Dependency
wantErr bool
errorKeyMsg string
}
helm := "helm"
if h := os.Getenv("HELM_BIN"); h != "" {
helm = h
}
runner := New(HelmBin(helm))
setupHelmConfig(t)
repo := "myrepo"
startServer(t, repo)
run := func(tc testcase) {
t.Helper()
got, err := runner.ReadAdhocDependencies(&tc.opts)
if tc.wantErr {
require.Error(t, err, "ReadAdhocDependencies() expected an error but got nil")
require.Containsf(t, err.Error(), tc.errorKeyMsg, "ReadAdhocDependencies() expected error key message %q but got %q", tc.errorKeyMsg, err.Error())
} else {
require.NoError(t, err, "ReadAdhocDependencies() expected error is nil but got an error")
}
if d := cmp.Diff(tc.wantDendency, got); d != "" {
t.Fatalf("unexpected result: want (-), got (+):\n%s", d)
}
}
run(testcase{
opts: ChartifyOpts{
AdhocChartDependencies: []ChartDependency{
{
Chart: "./testdata/charts/db",
},
},
},
wantDendency: []Dependency{
{
Repository: "file://./testdata/charts/db",
Name: "db",
Condition: "db.enabled",
},
},
})
run(testcase{
opts: ChartifyOpts{
AdhocChartDependencies: []ChartDependency{
{
Chart: "myrepo/db",
Version: "0.1.0",
},
},
},
wantDendency: []Dependency{
{
Repository: "http://localhost:18080/",
Name: "db",
Version: "0.1.0",
Condition: "db.enabled",
},
},
})
run(testcase{
opts: ChartifyOpts{
AdhocChartDependencies: []ChartDependency{
{
Chart: "nomyrepo/db",
Version: "0.1.0",
},
},
},
wantDendency: nil,
wantErr: true,
errorKeyMsg: "no helm list entry found for repository \"nomyrepo\"",
})
run(testcase{
opts: ChartifyOpts{
AdhocChartDependencies: []ChartDependency{
{
Chart: "oci://r.example.com/incubator/raw",
Version: "0.1.0",
},
},
},
wantDendency: []Dependency{
{
Repository: "oci://r.example.com/incubator",
Name: "raw",
Version: "0.1.0",
Condition: "raw.enabled",
},
},
})
}