New 🌊 wave for @helm

Commit 785f62fe

785f62fea54fMerged

Svyatoslav Dumchenko <[email protected]> · 4 years ago · 4 files · +2 added · ~2 modified

Description

more improvements to pkg/action tests

Details

Commit
785f62fea54f
Parent
7c0489608ec5

pkg/action/build_test.gomodifiedView file

@@ -3,7 +3,7 @@
33 package action
44
55 import (
6- "os"
6+ "path/filepath"
77 "testing"
88
99 "github.com/helmwave/helmwave/pkg/plan"
@@ -15,33 +15,30 @@
1515
1616 type BuildTestSuite struct {
1717 suite.Suite
18-}
19-
20-func (ts *BuildTestSuite) TearDownTest() {
21- _ = os.RemoveAll(tests.Root + plan.Dir)
2218 }
2319
2420 func (ts *BuildTestSuite) TestManifest() {
21+ tmpDir := ts.T().TempDir()
2522 y := &Yml{
26- tests.Root + "01_helmwave.yml.tpl",
27- tests.Root + "02_helmwave.yml",
23+ filepath.Join(tests.Root, "01_helmwave.yml.tpl"),
24+ filepath.Join(tests.Root, "02_helmwave.yml"),
2825 }
2926
3027 s := &Build{
31- plandir: tests.Root + plan.Dir,
28+ plandir: tmpDir,
3229 yml: y,
3330 tags: cli.StringSlice{},
3431 matchAll: true,
3532 }
3633
3734 ts.Require().NoError(s.Run())
38- ts.Require().DirExists(tests.Root + plan.Dir + plan.Manifest)
35+ ts.Require().DirExists(filepath.Join(s.plandir, plan.Manifest))
3936 }
4037
4138 // func (ts *BuildTestSuite) TestRepositories404() {
4239 // s := &Build{
43-// plandir: tests.Root + plan.Dir,
44-// ymlFile: tests.Root + "04_helmwave.yml",
40+// plandir: tmpDir,
41+// ymlFile: filepath.Join(tests.Root, "04_helmwave.yml"),
4542 // tags: cli.StringSlice{},
4643 // matchAll: true,
4744 // }
@@ -53,13 +50,14 @@
5350 // }
5451
5552 func (ts *BuildTestSuite) TestRepositories() {
53+ tmpDir := ts.T().TempDir()
5654 y := &Yml{
57- tests.Root + "01_helmwave.yml.tpl",
58- tests.Root + "02_helmwave.yml",
55+ filepath.Join(tests.Root, "01_helmwave.yml.tpl"),
56+ filepath.Join(tests.Root, "02_helmwave.yml"),
5957 }
6058
6159 s := &Build{
62- plandir: tests.Root + plan.Dir,
60+ plandir: tmpDir,
6361 yml: y,
6462 tags: cli.StringSlice{},
6563 matchAll: true,
@@ -68,7 +66,7 @@
6866 ts.Require().NoError(s.Run())
6967
7068 const rep = "bitnami"
71- b, _ := plan.NewBody(tests.Root + plan.Dir + plan.File)
69+ b, _ := plan.NewBody(filepath.Join(s.plandir, plan.File))
7270
7371 if _, found := repo.IndexOfName(b.Repositories, rep); !found {
7472 ts.Failf("%q not found", rep)
@@ -76,9 +74,10 @@
7674 }
7775
7876 func (ts *BuildTestSuite) TestReleasesMatchGroup() {
77+ tmpDir := ts.T().TempDir()
7978 y := &Yml{
80- tests.Root + "01_helmwave.yml.tpl",
81- tests.Root + "03_helmwave.yml",
79+ filepath.Join(tests.Root, "01_helmwave.yml.tpl"),
80+ filepath.Join(tests.Root, "03_helmwave.yml"),
8281 }
8382
8483 cases := []struct {
@@ -97,7 +96,7 @@
9796
9897 for _, c := range cases {
9998 s := &Build{
100- plandir: tests.Root + plan.Dir,
99+ plandir: tmpDir,
101100 yml: y,
102101 tags: *c.tags,
103102 matchAll: true,
@@ -105,7 +104,7 @@
105104
106105 ts.Require().NoError(s.Run())
107106
108- b, _ := plan.NewBody(tests.Root + plan.Dir + plan.File)
107+ b, _ := plan.NewBody(filepath.Join(s.plandir, plan.File))
109108
110109 names := make([]string, 0, len(b.Releases))
111110 for _, r := range b.Releases {
@@ -118,13 +117,14 @@
118117 }
119118
120119 func (ts *BuildTestSuite) TestAutoYml() {
120+ tmpDir := ts.T().TempDir()
121121 y := &Yml{
122- tests.Root + "01_helmwave.yml.tpl",
123- tests.Root + "01_auto_yaml_helmwave.yml",
122+ filepath.Join(tests.Root, "01_helmwave.yml.tpl"),
123+ filepath.Join(tmpDir, "01_auto_yaml_helmwave.yml"),
124124 }
125125
126126 s := &Build{
127- plandir: tests.Root + plan.Dir,
127+ plandir: tmpDir,
128128 tags: cli.StringSlice{},
129129 matchAll: true,
130130 autoYml: true,
@@ -132,21 +132,22 @@
132132 }
133133
134134 value := "test01"
135- _ = os.Setenv("PROJECT_NAME", value)
136- _ = os.Setenv("NAMESPACE", value)
135+ ts.T().Setenv("PROJECT_NAME", value)
136+ ts.T().Setenv("NAMESPACE", value)
137137
138138 ts.Require().NoError(s.Run())
139- ts.Require().DirExists(tests.Root + plan.Dir + plan.Manifest)
139+ ts.Require().DirExists(filepath.Join(s.plandir, plan.Manifest))
140140 }
141141
142142 func (ts *BuildTestSuite) TestGomplate() {
143+ tmpDir := ts.T().TempDir()
143144 y := &Yml{
144- tests.Root + "08_helmwave.yml",
145- tests.Root + "08_values.yml",
145+ filepath.Join(tests.Root, "08_helmwave.yml"),
146+ filepath.Join(tmpDir, "08_helmwave.yml"),
146147 }
147148
148149 s := &Build{
149- plandir: tests.Root + plan.Dir,
150+ plandir: tmpDir,
150151 tags: cli.StringSlice{},
151152 matchAll: true,
152153 autoYml: true,
@@ -154,21 +155,22 @@
154155 }
155156
156157 value := "test08"
157- _ = os.Setenv("PROJECT_NAME", value)
158- _ = os.Setenv("NAMESPACE", value)
158+ ts.T().Setenv("PROJECT_NAME", value)
159+ ts.T().Setenv("NAMESPACE", value)
159160
160161 ts.Require().NoError(s.Run())
161- ts.Require().DirExists(tests.Root + plan.Dir + plan.Manifest)
162+ ts.Require().DirExists(filepath.Join(s.plandir, plan.Manifest))
162163 }
163164
164165 func (ts *BuildTestSuite) TestDiffLocal() {
166+ tmpDir := ts.T().TempDir()
165167 y := &Yml{
166- tests.Root + "08_helmwave.yml",
167- tests.Root + "08_values.yml",
168+ filepath.Join(tests.Root, "08_helmwave.yml"),
169+ filepath.Join(tmpDir, "08_values.yml"),
168170 }
169171
170172 s := &Build{
171- plandir: tests.Root + plan.Dir,
173+ plandir: tmpDir,
172174 tags: cli.StringSlice{},
173175 matchAll: true,
174176 autoYml: true,
@@ -181,13 +183,14 @@
181183 }
182184
183185 func (ts *BuildTestSuite) TestDiffLive() {
186+ tmpDir := ts.T().TempDir()
184187 y := &Yml{
185- tests.Root + "08_helmwave.yml",
186- tests.Root + "08_values.yml",
188+ filepath.Join(tests.Root, "08_helmwave.yml"),
189+ filepath.Join(tmpDir, "08_values.yml"),
187190 }
188191
189192 s := &Build{
190- plandir: tests.Root + plan.Dir,
193+ plandir: tmpDir,
191194 tags: cli.StringSlice{},
192195 matchAll: true,
193196 autoYml: true,