diff --git a/internal/run/lint.go b/internal/run/lint.go index b4093ac..bdc4f8c 100644 --- a/internal/run/lint.go +++ b/internal/run/lint.go @@ -1,7 +1,7 @@ package run import ( -// "fmt" + "fmt" ) // Lint is an execution step that calls `helm lint` when executed. @@ -18,7 +18,13 @@ func (l *Lint) Execute(_ Config) error { // Prepare gets the Lint ready to execute. func (l *Lint) Prepare(cfg Config) error { - args := []string{"lint"} + args := make([]string, 0) + + if cfg.Debug { + args = append(args, "--debug") + } + + args = append(args, "lint") if cfg.Values != "" { args = append(args, "--set", cfg.Values) @@ -36,5 +42,9 @@ func (l *Lint) Prepare(cfg Config) error { l.cmd.Stdout(cfg.Stdout) l.cmd.Stderr(cfg.Stderr) + if cfg.Debug { + fmt.Fprintf(cfg.Stderr, "Generated command: '%s'\n", l.cmd.String()) + } + return nil } diff --git a/internal/run/lint_test.go b/internal/run/lint_test.go index 1c119f1..25a6f26 100644 --- a/internal/run/lint_test.go +++ b/internal/run/lint_test.go @@ -1,8 +1,10 @@ package run import ( + "fmt" "github.com/golang/mock/gomock" "github.com/stretchr/testify/suite" + "strings" "testing" ) @@ -88,3 +90,35 @@ func (suite *LintTestSuite) TestPrepareWithLintFlags() { err := l.Prepare(cfg) suite.Require().Nil(err) } + +func (suite *LintTestSuite) TestPrepareWithDebugFlag() { + defer suite.ctrl.Finish() + + stderr := strings.Builder{} + + cfg := Config{ + Debug: true, + Stderr: &stderr, + } + + l := Lint{ + Chart: "./scotland/top_40", + } + + command = func(path string, args ...string) cmd { + suite.mockCmd.EXPECT(). + String(). + Return(fmt.Sprintf("%s %s", path, strings.Join(args, " "))) + + return suite.mockCmd + } + + suite.mockCmd.EXPECT().Stdout(gomock.Any()) + suite.mockCmd.EXPECT().Stderr(gomock.Any()) + + err := l.Prepare(cfg) + suite.Require().Nil(err) + + want := fmt.Sprintf("Generated command: '%s --debug lint ./scotland/top_40'\n", helmBin) + suite.Equal(want, stderr.String()) +}