New 🌊 wave for @helm

Commit c04f23a2

c04f23a29edfMerged

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

Description

Add tests for local plan diff

Details

Commit
c04f23a29edf
Parent
7e21fea75062

pkg/action/diff_plan_test.goaddedView file

1+//go:build ignore || integration
2+
3+package action
4+
5+import (
6+ "bytes"
7+ "os"
8+ "path/filepath"
9+ "testing"
10+
11+ "github.com/helmwave/helmwave/tests"
12+ log "github.com/sirupsen/logrus"
13+ "github.com/stretchr/testify/suite"
14+ "github.com/urfave/cli/v2"
15+)
16+
17+var buf bytes.Buffer
18+
19+type DiffPlanTestSuite struct {
20+ suite.Suite
21+}
22+
23+func (s *DiffPlanTestSuite) SetupTest() {
24+ log.StandardLogger().SetOutput(&buf)
25+}
26+
27+func (s *DiffPlanTestSuite) TearDownTest() {
28+ log.StandardLogger().SetOutput(os.Stderr)
29+}
30+
31+func (ts *DiffPlanTestSuite) TestRun() {
32+ s1 := &Build{
33+ plandir: ts.T().TempDir(),
34+ tags: cli.StringSlice{},
35+ yml: &Yml{
36+ filepath.Join(tests.Root, "02_helmwave.yml"),
37+ filepath.Join(tests.Root, "02_helmwave.yml"),
38+ },
39+ diff: &Diff{},
40+ diffMode: diffModeLive,
41+ }
42+
43+ s2 := &Build{
44+ plandir: ts.T().TempDir(),
45+ tags: cli.StringSlice{},
46+ yml: &Yml{
47+ filepath.Join(tests.Root, "03_helmwave.yml"),
48+ filepath.Join(tests.Root, "03_helmwave.yml"),
49+ },
50+ diff: &Diff{},
51+ diffMode: diffModeLive,
52+ }
53+
54+ d := DiffLocalPlan{diff: s1.diff, plandir1: s1.plandir, plandir2: s2.plandir}
55+
56+ ts.Require().ErrorIs(d.Run(), os.ErrNotExist)
57+ ts.Require().NoError(s1.Run())
58+ ts.Require().ErrorIs(d.Run(), os.ErrNotExist)
59+ ts.Require().NoError(s2.Run())
60+
61+ buf.Reset()
62+ ts.Require().NoError(d.Run())
63+
64+ output := buf.String()
65+ buf.Reset()
66+
67+ ts.Require().Contains(output, "nginx, Deployment (apps) has been added")
68+ ts.Require().Contains(output, "memcached-a-redis, Secret (v1) has been removed")
69+}
70+
71+//nolint:paralleltest // we capture output for global logger
72+func TestDiffPlanTestSuite(t *testing.T) {
73+ // t.Parallel()
74+ suite.Run(t, new(DiffPlanTestSuite))
75+}