Implement the debug flag in lint [#3]
This commit is contained in:
parent
51800c18d7
commit
a6b7e06bd2
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue