1
16
17 package action
18
19 import (
20 "bytes"
21 "os"
22 "path/filepath"
23 "testing"
24
25 "github.com/stretchr/testify/assert"
26
27 "helm.sh/helm/v3/internal/test"
28 "helm.sh/helm/v3/pkg/chart"
29 "helm.sh/helm/v3/pkg/chartutil"
30 )
31
32 func TestList(t *testing.T) {
33 for _, tcase := range []struct {
34 chart string
35 golden string
36 }{
37 {
38 chart: "testdata/charts/chart-with-compressed-dependencies",
39 golden: "output/list-compressed-deps.txt",
40 },
41 {
42 chart: "testdata/charts/chart-with-compressed-dependencies-2.1.8.tgz",
43 golden: "output/list-compressed-deps-tgz.txt",
44 },
45 {
46 chart: "testdata/charts/chart-with-uncompressed-dependencies",
47 golden: "output/list-uncompressed-deps.txt",
48 },
49 {
50 chart: "testdata/charts/chart-with-uncompressed-dependencies-2.1.8.tgz",
51 golden: "output/list-uncompressed-deps-tgz.txt",
52 },
53 {
54 chart: "testdata/charts/chart-missing-deps",
55 golden: "output/list-missing-deps.txt",
56 },
57 } {
58 buf := bytes.Buffer{}
59 if err := NewDependency().List(tcase.chart, &buf); err != nil {
60 t.Fatal(err)
61 }
62 test.AssertGoldenString(t, buf.String(), tcase.golden)
63 }
64 }
65
66
67
68 func TestDependencyStatus_Dashes(t *testing.T) {
69
70 dir := t.TempDir()
71
72 chartpath := filepath.Join(dir, "charts")
73 if err := os.MkdirAll(chartpath, 0700); err != nil {
74 t.Fatal(err)
75 }
76
77
78 first := buildChart(withName("first-chart"))
79 _, err := chartutil.Save(first, chartpath)
80 if err != nil {
81 t.Fatal(err)
82 }
83
84 second := buildChart(withName("first-chart-second-chart"))
85 _, err = chartutil.Save(second, chartpath)
86 if err != nil {
87 t.Fatal(err)
88 }
89
90 dep := &chart.Dependency{
91 Name: "first-chart",
92 Version: "0.1.0",
93 }
94
95
96 stat := NewDependency().dependencyStatus(dir, dep, first)
97 if stat != "ok" {
98 t.Errorf("Unexpected status: %q", stat)
99 }
100 }
101
102 func TestStatArchiveForStatus(t *testing.T) {
103
104 dir := t.TempDir()
105
106 chartpath := filepath.Join(dir, "charts")
107 if err := os.MkdirAll(chartpath, 0700); err != nil {
108 t.Fatal(err)
109 }
110
111
112 lilith := buildChart(withName("lilith"))
113
114
115 dep := &chart.Dependency{
116 Name: "lilith",
117 Version: "1.2.3",
118 }
119
120 is := assert.New(t)
121
122 lilithpath := filepath.Join(chartpath, "lilith-1.2.3.tgz")
123 is.Empty(statArchiveForStatus(lilithpath, dep))
124
125
126 where, err := chartutil.Save(lilith, chartpath)
127 is.NoError(err)
128
129
130 is.Equal("wrong version", statArchiveForStatus(where, dep))
131
132
133 dep = &chart.Dependency{
134 Name: "lilith",
135 Version: "1.2.3.4.5",
136 }
137 is.Equal("invalid version", statArchiveForStatus(where, dep))
138
139
140 dep = &chart.Dependency{
141 Name: "lilith2",
142 Version: "1.2.3",
143 }
144 is.Equal("misnamed", statArchiveForStatus(where, dep))
145
146
147 dep = &chart.Dependency{
148 Name: "lilith",
149 Version: "0.1.0",
150 }
151 is.Equal("ok", statArchiveForStatus(where, dep))
152 }
153
View as plain text