Initialize run.Configs in the NewSTEP functions [#67]
This fixes the run package's leaky abstraction; other packages no longer need to know or care that run.Config even exists. Note that since the various Steps now depend on having a non-nil pointer to a run.Config, it's unsafe (or at least risky) to initialize them directly. They should be created with their NewSTEPNAME functions. All their fields are now private, to reflect this.
This commit is contained in:
@@ -42,13 +42,12 @@ func (suite *LintTestSuite) TestNewLint() {
|
||||
}
|
||||
lint := NewLint(cfg)
|
||||
suite.Require().NotNil(lint)
|
||||
suite.Equal(&Lint{
|
||||
Chart: "./flow",
|
||||
Values: "steadfastness,forthrightness",
|
||||
StringValues: "tensile_strength,flexibility",
|
||||
ValuesFiles: []string{"/root/price_inventory.yml"},
|
||||
Strict: true,
|
||||
}, lint)
|
||||
suite.Equal("./flow", lint.chart)
|
||||
suite.Equal("steadfastness,forthrightness", lint.values)
|
||||
suite.Equal("tensile_strength,flexibility", lint.stringValues)
|
||||
suite.Equal([]string{"/root/price_inventory.yml"}, lint.valuesFiles)
|
||||
suite.Equal(true, lint.strict)
|
||||
suite.NotNil(lint.config)
|
||||
}
|
||||
|
||||
func (suite *LintTestSuite) TestPrepareAndExecute() {
|
||||
@@ -57,13 +56,12 @@ func (suite *LintTestSuite) TestPrepareAndExecute() {
|
||||
stdout := strings.Builder{}
|
||||
stderr := strings.Builder{}
|
||||
|
||||
l := Lint{
|
||||
Chart: "./epic/mychart",
|
||||
}
|
||||
cfg := Config{
|
||||
cfg := env.Config{
|
||||
Chart: "./epic/mychart",
|
||||
Stdout: &stdout,
|
||||
Stderr: &stderr,
|
||||
}
|
||||
l := NewLint(cfg)
|
||||
|
||||
command = func(path string, args ...string) cmd {
|
||||
suite.Equal(helmBin, path)
|
||||
@@ -72,6 +70,7 @@ func (suite *LintTestSuite) TestPrepareAndExecute() {
|
||||
return suite.mockCmd
|
||||
}
|
||||
|
||||
suite.mockCmd.EXPECT().String().AnyTimes()
|
||||
suite.mockCmd.EXPECT().
|
||||
Stdout(&stdout)
|
||||
suite.mockCmd.EXPECT().
|
||||
@@ -80,7 +79,7 @@ func (suite *LintTestSuite) TestPrepareAndExecute() {
|
||||
Run().
|
||||
Times(1)
|
||||
|
||||
err := l.Prepare(cfg)
|
||||
err := l.Prepare()
|
||||
suite.Require().Nil(err)
|
||||
l.Execute()
|
||||
}
|
||||
@@ -90,25 +89,22 @@ func (suite *LintTestSuite) TestPrepareRequiresChart() {
|
||||
suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes()
|
||||
suite.mockCmd.EXPECT().Stderr(gomock.Any()).AnyTimes()
|
||||
|
||||
cfg := Config{}
|
||||
l := Lint{}
|
||||
|
||||
err := l.Prepare(cfg)
|
||||
l := NewLint(env.Config{})
|
||||
err := l.Prepare()
|
||||
suite.EqualError(err, "chart is required", "Chart should be mandatory")
|
||||
}
|
||||
|
||||
func (suite *LintTestSuite) TestPrepareWithLintFlags() {
|
||||
defer suite.ctrl.Finish()
|
||||
|
||||
cfg := Config{}
|
||||
|
||||
l := Lint{
|
||||
cfg := env.Config{
|
||||
Chart: "./uk/top_40",
|
||||
Values: "width=5",
|
||||
StringValues: "version=2.0",
|
||||
ValuesFiles: []string{"/usr/local/underrides", "/usr/local/overrides"},
|
||||
Strict: true,
|
||||
LintStrictly: true,
|
||||
}
|
||||
l := NewLint(cfg)
|
||||
|
||||
command = func(path string, args ...string) cmd {
|
||||
suite.Equal(helmBin, path)
|
||||
@@ -125,8 +121,9 @@ func (suite *LintTestSuite) TestPrepareWithLintFlags() {
|
||||
|
||||
suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes()
|
||||
suite.mockCmd.EXPECT().Stderr(gomock.Any()).AnyTimes()
|
||||
suite.mockCmd.EXPECT().String().AnyTimes()
|
||||
|
||||
err := l.Prepare(cfg)
|
||||
err := l.Prepare()
|
||||
suite.Require().Nil(err)
|
||||
}
|
||||
|
||||
@@ -135,14 +132,12 @@ func (suite *LintTestSuite) TestPrepareWithDebugFlag() {
|
||||
|
||||
stderr := strings.Builder{}
|
||||
|
||||
cfg := Config{
|
||||
cfg := env.Config{
|
||||
Debug: true,
|
||||
Stderr: &stderr,
|
||||
Chart: "./scotland/top_40",
|
||||
}
|
||||
|
||||
l := Lint{
|
||||
Chart: "./scotland/top_40",
|
||||
}
|
||||
l := NewLint(cfg)
|
||||
|
||||
command = func(path string, args ...string) cmd {
|
||||
suite.mockCmd.EXPECT().
|
||||
@@ -155,7 +150,7 @@ func (suite *LintTestSuite) TestPrepareWithDebugFlag() {
|
||||
suite.mockCmd.EXPECT().Stdout(gomock.Any())
|
||||
suite.mockCmd.EXPECT().Stderr(&stderr)
|
||||
|
||||
err := l.Prepare(cfg)
|
||||
err := l.Prepare()
|
||||
suite.Require().Nil(err)
|
||||
|
||||
want := fmt.Sprintf("Generated command: '%s --debug lint ./scotland/top_40'\n", helmBin)
|
||||
@@ -165,13 +160,11 @@ func (suite *LintTestSuite) TestPrepareWithDebugFlag() {
|
||||
func (suite *LintTestSuite) TestPrepareWithNamespaceFlag() {
|
||||
defer suite.ctrl.Finish()
|
||||
|
||||
cfg := Config{
|
||||
cfg := env.Config{
|
||||
Namespace: "table-service",
|
||||
Chart: "./wales/top_40",
|
||||
}
|
||||
|
||||
l := Lint{
|
||||
Chart: "./wales/top_40",
|
||||
}
|
||||
l := NewLint(cfg)
|
||||
|
||||
actual := []string{}
|
||||
command = func(path string, args ...string) cmd {
|
||||
@@ -182,7 +175,7 @@ func (suite *LintTestSuite) TestPrepareWithNamespaceFlag() {
|
||||
suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes()
|
||||
suite.mockCmd.EXPECT().Stderr(gomock.Any()).AnyTimes()
|
||||
|
||||
err := l.Prepare(cfg)
|
||||
err := l.Prepare()
|
||||
suite.Require().Nil(err)
|
||||
|
||||
expected := []string{"--namespace", "table-service", "lint", "./wales/top_40"}
|
||||
|
||||
Reference in New Issue
Block a user