New ๐ŸŒŠ wave for @helm

Commit 5f9f0405

5f9f04052349Merged

Svyatoslav Dumchenko <[email protected]> ยท 4 years ago ยท 2 files ยท ~2 modified

Description

Refactor pkg/action/build_test.go to testify

Details

Commit
5f9f04052349
Parent
a2b4a098b69d

pkg/action/build_test.gomodifiedView file

@@ -6,20 +6,22 @@
66 "os"
77 "testing"
88
9- "github.com/helmwave/helmwave/pkg/helper"
109 "github.com/helmwave/helmwave/pkg/plan"
1110 "github.com/helmwave/helmwave/pkg/repo"
1211 "github.com/helmwave/helmwave/tests"
12+ "github.com/stretchr/testify/suite"
1313 "github.com/urfave/cli/v2"
1414 )
1515
16-func clean() {
17- _ = os.RemoveAll(tests.Root + plan.Dir)
16+type BuildTestSuite struct {
17+ suite.Suite
1818 }
1919
20-func TestBuildManifest(t *testing.T) {
21- defer clean()
20+func (ts *BuildTestSuite) TearDownTest() {
21+ _ = os.RemoveAll(tests.Root + plan.Dir)
22+}
2223
24+func (ts *BuildTestSuite) BuildManifest() {
2325 y := &Yml{
2426 tests.Root + "01_helmwave.yml.tpl",
2527 tests.Root + "02_helmwave.yml",
@@ -32,19 +34,11 @@
3234 matchAll: true,
3335 }
3436
35- err := s.Run()
36- if err != nil {
37- t.Error(err)
38- }
39-
40- if ok := helper.IsExists(tests.Root + plan.Dir + plan.Manifest); !ok {
41- t.Error(plan.ErrManifestDirNotFound)
42- }
37+ ts.Require().NoError(s.Run())
38+ ts.Require().DirExists(tests.Root + plan.Dir + plan.Manifest)
4339 }
4440
45-// func TestBuildRepositories404(t *testing.T) {
46-// defer clean()
47-//
41+// func (ts *BuildTestSuite) BuildRepositories404() {
4842 // s := &Build{
4943 // plandir: tests.Root + plan.Dir,
5044 // ymlFile: tests.Root + "04_helmwave.yml",
@@ -58,9 +52,7 @@
5852 // }
5953 // }
6054
61-func TestBuildRepositories(t *testing.T) {
62- defer clean()
63-
55+func (ts *BuildTestSuite) BuildRepositories() {
6456 y := &Yml{
6557 tests.Root + "01_helmwave.yml.tpl",
6658 tests.Root + "02_helmwave.yml",
@@ -73,76 +65,59 @@
7365 matchAll: true,
7466 }
7567
76- err := s.Run()
77- if err != nil {
78- t.Error(err)
79- }
68+ ts.Require().NoError(s.Run())
8069
8170 const rep = "bitnami"
8271 b, _ := plan.NewBody(tests.Root + plan.Dir + plan.File)
8372
8473 if _, found := repo.IndexOfName(b.Repositories, rep); !found {
85- t.Errorf("%q not found", rep)
74+ ts.Failf("%q not found", rep)
8675 }
8776 }
8877
89-func TestBuildReleasesMatchGroup(t *testing.T) {
90- defer clean()
91-
78+func (ts *BuildTestSuite) BuildReleasesMatchGroup() {
9279 y := &Yml{
9380 tests.Root + "01_helmwave.yml.tpl",
9481 tests.Root + "03_helmwave.yml",
9582 }
9683
97- s := &Build{
98- plandir: tests.Root + plan.Dir,
99- yml: y,
100- tags: *cli.NewStringSlice("b"),
101- matchAll: true,
84+ cases := []struct {
85+ tags *cli.StringSlice
86+ names []string
87+ }{
88+ {
89+ tags: cli.NewStringSlice("b"),
90+ names: []string{"redis-b", "memcached-b"},
91+ },
92+ {
93+ tags: cli.NewStringSlice("b", "redis"),
94+ names: []string{"redis-b"},
95+ },
10296 }
10397
104- err := s.Run()
105- if err != nil {
106- t.Error(err)
107- }
98+ for _, c := range cases {
99+ s := &Build{
100+ plandir: tests.Root + plan.Dir,
101+ yml: y,
102+ tags: *c.tags,
103+ matchAll: true,
104+ }
108105
109- b, _ := plan.NewBody(tests.Root + plan.Dir + plan.File)
106+ ts.Require().NoError(s.Run())
110107
111- if len(b.Releases) != 2 && b.Releases[0].Name != "redis-b" && b.Releases[1].Name != "memcached-b" {
112- t.Error("'redis-b' and 'memcached-b' not found")
113- }
114-}
108+ b, _ := plan.NewBody(tests.Root + plan.Dir + plan.File)
115109
116-func TestBuildReleasesMatchGroups(t *testing.T) {
117- defer clean()
110+ names := make([]string, 0, len(b.Releases))
111+ for _, r := range b.Releases {
112+ names = append(names, r.Name)
113+ }
118114
119- y := &Yml{
120- tests.Root + "01_helmwave.yml.tpl",
121- tests.Root + "03_helmwave.yml",
122- }
123-
124- s := &Build{
125- plandir: tests.Root + plan.Dir,
126- yml: y,
127- tags: *cli.NewStringSlice("b", "redis"),
128- matchAll: true,
115+ ts.Require().ElementsMatch(c.names, names)
129116 }
130117
131- err := s.Run()
132- if err != nil {
133- t.Error(err)
134- }
135-
136- b, _ := plan.NewBody(tests.Root + plan.Dir + plan.File)
137-
138- if len(b.Releases) != 1 && b.Releases[0].Name != "redis-b" {
139- t.Error("'redis-b' not found")
140- }
141118 }
142-
143-func TestBuildAutoYml(t *testing.T) {
144- defer clean()
145119
120+func (ts *BuildTestSuite) BuildAutoYml() {
146121 y := &Yml{
147122 tests.Root + "01_helmwave.yml.tpl",
148123 tests.Root + "01_auto_yaml_helmwave.yml",
@@ -160,19 +135,11 @@
160135 _ = os.Setenv("PROJECT_NAME", value)
161136 _ = os.Setenv("NAMESPACE", value)
162137
163- err := s.Run()
164- if err != nil {
165- t.Error(err)
166- }
167-
168- if ok := helper.IsExists(tests.Root + plan.Dir + plan.Manifest); !ok {
169- t.Error(plan.ErrManifestDirNotFound)
170- }
138+ ts.Require().NoError(s.Run())
139+ ts.Require().DirExists(tests.Root + plan.Dir + plan.Manifest)
171140 }
172141
173-func TestBuildGomplate(t *testing.T) {
174- defer clean()
175-
142+func (ts *BuildTestSuite) BuildGomplate() {
176143 y := &Yml{
177144 tests.Root + "08_helmwave.yml",
178145 tests.Root + "08_values.yml",
@@ -190,12 +157,11 @@
190157 _ = os.Setenv("PROJECT_NAME", value)
191158 _ = os.Setenv("NAMESPACE", value)
192159
193- err := s.Run()
194- if err != nil {
195- t.Error(err)
196- }
160+ ts.Require().NoError(s.Run())
161+ ts.Require().DirExists(tests.Root + plan.Dir + plan.Manifest)
162+}
197163
198- if ok := helper.IsExists(tests.Root + plan.Dir + plan.Manifest); !ok {
199- t.Error(plan.ErrManifestDirNotFound)
200- }
164+func TestBuildTestSuite(t *testing.T) {
165+ // t.Parallel()
166+ suite.Run(t, new(BuildTestSuite))
201167 }