From 991bbf97b4c30755d75a466b6233d5503f14354d Mon Sep 17 00:00:00 2001 From: Erin Call Date: Tue, 17 Dec 2019 16:21:45 -0800 Subject: [PATCH] Create a Lint step [#3] Still need global flags and checks for mandatory settings, but the basic functionality is there. --- internal/run/lint.go | 28 +++++++++++++++++++ internal/run/lint_test.go | 58 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 internal/run/lint.go create mode 100644 internal/run/lint_test.go diff --git a/internal/run/lint.go b/internal/run/lint.go new file mode 100644 index 0000000..85082c3 --- /dev/null +++ b/internal/run/lint.go @@ -0,0 +1,28 @@ +package run + +import ( +// "fmt" +) + +// Lint is an execution step that calls `helm lint` when executed. +type Lint struct { + Chart string + + cmd cmd +} + +// Execute executes the `helm lint` command. +func (l *Lint) Execute(_ Config) error { + return l.cmd.Run() +} + +// Prepare gets the Lint ready to execute. +func (l *Lint) Prepare(cfg Config) error { + args := []string{"lint", l.Chart} + + l.cmd = command(helmBin, args...) + l.cmd.Stdout(cfg.Stdout) + l.cmd.Stderr(cfg.Stderr) + + return nil +} diff --git a/internal/run/lint_test.go b/internal/run/lint_test.go new file mode 100644 index 0000000..e86bcb5 --- /dev/null +++ b/internal/run/lint_test.go @@ -0,0 +1,58 @@ +package run + +import ( + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/suite" + "testing" +) + +type LintTestSuite struct { + suite.Suite + ctrl *gomock.Controller + mockCmd *Mockcmd + originalCommand func(string, ...string) cmd +} + +func (suite *LintTestSuite) BeforeTest(_, _ string) { + suite.ctrl = gomock.NewController(suite.T()) + suite.mockCmd = NewMockcmd(suite.ctrl) + + suite.originalCommand = command + command = func(path string, args ...string) cmd { return suite.mockCmd } +} + +func (suite *LintTestSuite) AfterTest(_, _ string) { + command = suite.originalCommand +} + +func TestLintTestSuite(t *testing.T) { + suite.Run(t, new(LintTestSuite)) +} + +func (suite *LintTestSuite) TestPrepareAndExecute() { + defer suite.ctrl.Finish() + + l := Lint{ + Chart: "./epic/mychart", + } + + command = func(path string, args ...string) cmd { + suite.Equal(helmBin, path) + suite.Equal([]string{"lint", "./epic/mychart"}, args) + + return suite.mockCmd + } + + suite.mockCmd.EXPECT(). + Stdout(gomock.Any()) + suite.mockCmd.EXPECT(). + Stderr(gomock.Any()) + suite.mockCmd.EXPECT(). + Run(). + Times(1) + + cfg := Config{} + err := l.Prepare(cfg) + suite.Require().Nil(err) + l.Execute(cfg) +}