Remove the cfg argument from Step.Execute [#67]
This is the first step toward removing run.Config entirely. InitKube was the only Step that even used cfg in its Execute function; the rest just discarded it.
This commit is contained in:
parent
88bb8085b0
commit
231138563c
|
@ -48,15 +48,15 @@ func (mr *MockStepMockRecorder) Prepare(arg0 interface{}) *gomock.Call {
|
|||
}
|
||||
|
||||
// Execute mocks base method
|
||||
func (m *MockStep) Execute(arg0 run.Config) error {
|
||||
func (m *MockStep) Execute() error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Execute", arg0)
|
||||
ret := m.ctrl.Call(m, "Execute")
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Execute indicates an expected call of Execute
|
||||
func (mr *MockStepMockRecorder) Execute(arg0 interface{}) *gomock.Call {
|
||||
func (mr *MockStepMockRecorder) Execute() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Execute", reflect.TypeOf((*MockStep)(nil).Execute), arg0)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Execute", reflect.TypeOf((*MockStep)(nil).Execute))
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ const (
|
|||
// A Step is one step in the plan.
|
||||
type Step interface {
|
||||
Prepare(run.Config) error
|
||||
Execute(run.Config) error
|
||||
Execute() error
|
||||
}
|
||||
|
||||
// A Plan is a series of steps to perform.
|
||||
|
@ -84,7 +84,7 @@ func (p *Plan) Execute() error {
|
|||
fmt.Fprintf(p.cfg.Stderr, "calling %T.Execute (step %d)\n", step, i)
|
||||
}
|
||||
|
||||
if err := step.Execute(p.runCfg); err != nil {
|
||||
if err := step.Execute(); err != nil {
|
||||
return fmt.Errorf("while executing %T step: %w", step, err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,10 +98,10 @@ func (suite *PlanTestSuite) TestExecute() {
|
|||
}
|
||||
|
||||
stepOne.EXPECT().
|
||||
Execute(runCfg).
|
||||
Execute().
|
||||
Times(1)
|
||||
stepTwo.EXPECT().
|
||||
Execute(runCfg).
|
||||
Execute().
|
||||
Times(1)
|
||||
|
||||
suite.NoError(plan.Execute())
|
||||
|
@ -121,7 +121,7 @@ func (suite *PlanTestSuite) TestExecuteAbortsOnError() {
|
|||
}
|
||||
|
||||
stepOne.EXPECT().
|
||||
Execute(runCfg).
|
||||
Execute().
|
||||
Times(1).
|
||||
Return(fmt.Errorf("oh, he'll gnaw"))
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ func NewAddRepo(repo string) *AddRepo {
|
|||
}
|
||||
|
||||
// Execute executes the `helm repo add` command.
|
||||
func (a *AddRepo) Execute(_ Config) error {
|
||||
func (a *AddRepo) Execute() error {
|
||||
return a.cmd.Run()
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ func (suite *AddRepoTestSuite) TestPrepareAndExecute() {
|
|||
Run().
|
||||
Times(1)
|
||||
|
||||
suite.Require().NoError(a.Execute(cfg))
|
||||
suite.Require().NoError(a.Execute())
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ func NewDepUpdate(cfg env.Config) *DepUpdate {
|
|||
}
|
||||
|
||||
// Execute executes the `helm upgrade` command.
|
||||
func (d *DepUpdate) Execute(_ Config) error {
|
||||
func (d *DepUpdate) Execute() error {
|
||||
return d.cmd.Run()
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ func (suite *DepUpdateTestSuite) TestPrepareAndExecute() {
|
|||
}
|
||||
|
||||
suite.Require().NoError(d.Prepare(cfg))
|
||||
suite.NoError(d.Execute(cfg))
|
||||
suite.NoError(d.Execute())
|
||||
}
|
||||
|
||||
func (suite *DepUpdateTestSuite) TestPrepareNamespaceFlag() {
|
||||
|
|
|
@ -19,7 +19,7 @@ func NewHelp(cfg env.Config) *Help {
|
|||
}
|
||||
|
||||
// Execute executes the `helm help` command.
|
||||
func (h *Help) Execute(cfg Config) error {
|
||||
func (h *Help) Execute() error {
|
||||
if err := h.cmd.Run(); err != nil {
|
||||
return fmt.Errorf("while running '%s': %w", h.cmd.String(), err)
|
||||
}
|
||||
|
|
|
@ -73,15 +73,14 @@ func (suite *HelpTestSuite) TestExecute() {
|
|||
Run().
|
||||
Times(2)
|
||||
|
||||
cfg := Config{}
|
||||
help := Help{
|
||||
HelmCommand: "help",
|
||||
cmd: mCmd,
|
||||
}
|
||||
suite.NoError(help.Execute(cfg))
|
||||
suite.NoError(help.Execute())
|
||||
|
||||
help.HelmCommand = "get down on friday"
|
||||
suite.EqualError(help.Execute(cfg), "unknown command 'get down on friday'")
|
||||
suite.EqualError(help.Execute(), "unknown command 'get down on friday'")
|
||||
}
|
||||
|
||||
func (suite *HelpTestSuite) TestPrepareDebugFlag() {
|
||||
|
|
|
@ -13,6 +13,8 @@ import (
|
|||
type InitKube struct {
|
||||
templateFilename string
|
||||
configFilename string
|
||||
debug bool
|
||||
stderr io.Writer
|
||||
template *template.Template
|
||||
configFile io.WriteCloser
|
||||
values kubeValues
|
||||
|
@ -40,13 +42,15 @@ func NewInitKube(cfg env.Config, templateFile, configFile string) *InitKube {
|
|||
},
|
||||
templateFilename: templateFile,
|
||||
configFilename: configFile,
|
||||
debug: cfg.Debug,
|
||||
stderr: cfg.Stderr,
|
||||
}
|
||||
}
|
||||
|
||||
// Execute generates a kubernetes config file from drone-helm3's template.
|
||||
func (i *InitKube) Execute(cfg Config) error {
|
||||
if cfg.Debug {
|
||||
fmt.Fprintf(cfg.Stderr, "writing kubeconfig file to %s\n", i.configFilename)
|
||||
func (i *InitKube) Execute() error {
|
||||
if i.debug {
|
||||
fmt.Fprintf(i.stderr, "writing kubeconfig file to %s\n", i.configFilename)
|
||||
}
|
||||
defer i.configFile.Close()
|
||||
return i.template.Execute(i.configFile, i.values)
|
||||
|
@ -67,22 +71,22 @@ func (i *InitKube) Prepare(cfg Config) error {
|
|||
i.values.ServiceAccount = "helm"
|
||||
}
|
||||
|
||||
if cfg.Debug {
|
||||
fmt.Fprintf(cfg.Stderr, "loading kubeconfig template from %s\n", i.templateFilename)
|
||||
if i.debug {
|
||||
fmt.Fprintf(i.stderr, "loading kubeconfig template from %s\n", i.templateFilename)
|
||||
}
|
||||
i.template, err = template.ParseFiles(i.templateFilename)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not load kubeconfig template: %w", err)
|
||||
}
|
||||
|
||||
if cfg.Debug {
|
||||
if i.debug {
|
||||
if _, err := os.Stat(i.configFilename); err != nil {
|
||||
// non-nil err here isn't an actual error state; the kubeconfig just doesn't exist
|
||||
fmt.Fprint(cfg.Stderr, "creating ")
|
||||
fmt.Fprint(i.stderr, "creating ")
|
||||
} else {
|
||||
fmt.Fprint(cfg.Stderr, "truncating ")
|
||||
fmt.Fprint(i.stderr, "truncating ")
|
||||
}
|
||||
fmt.Fprintf(cfg.Stderr, "kubeconfig file at %s\n", i.configFilename)
|
||||
fmt.Fprintf(i.stderr, "kubeconfig file at %s\n", i.configFilename)
|
||||
}
|
||||
|
||||
i.configFile, err = os.Create(i.configFilename)
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
yaml "gopkg.in/yaml.v2"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"text/template"
|
||||
)
|
||||
|
@ -25,6 +26,8 @@ func (suite *InitKubeTestSuite) TestNewInitKube() {
|
|||
APIServer: "98.765.43.21",
|
||||
ServiceAccount: "greathelm",
|
||||
KubeToken: "b2YgbXkgYWZmZWN0aW9u",
|
||||
Stderr: &strings.Builder{},
|
||||
Debug: true,
|
||||
}
|
||||
|
||||
init := NewInitKube(cfg, "conf.tpl", "conf.yml")
|
||||
|
@ -38,6 +41,8 @@ func (suite *InitKubeTestSuite) TestNewInitKube() {
|
|||
},
|
||||
templateFilename: "conf.tpl",
|
||||
configFilename: "conf.yml",
|
||||
debug: true,
|
||||
stderr: cfg.Stderr,
|
||||
}, init)
|
||||
}
|
||||
|
||||
|
@ -70,7 +75,7 @@ namespace: {{ .Namespace }}
|
|||
suite.IsType(&template.Template{}, init.template)
|
||||
suite.NotNil(init.configFile)
|
||||
|
||||
err = init.Execute(cfg)
|
||||
err = init.Execute()
|
||||
suite.Require().Nil(err)
|
||||
|
||||
conf, err := ioutil.ReadFile(configFile.Name())
|
||||
|
@ -101,7 +106,7 @@ func (suite *InitKubeTestSuite) TestExecuteGeneratesConfig() {
|
|||
},
|
||||
}
|
||||
suite.Require().NoError(init.Prepare(cfg))
|
||||
suite.Require().NoError(init.Execute(cfg))
|
||||
suite.Require().NoError(init.Execute())
|
||||
|
||||
contents, err := ioutil.ReadFile(configFile.Name())
|
||||
suite.Require().NoError(err)
|
||||
|
@ -128,7 +133,7 @@ func (suite *InitKubeTestSuite) TestExecuteGeneratesConfig() {
|
|||
init.values.Certificate = ""
|
||||
|
||||
suite.Require().NoError(init.Prepare(cfg))
|
||||
suite.Require().NoError(init.Execute(cfg))
|
||||
suite.Require().NoError(init.Execute())
|
||||
contents, err = ioutil.ReadFile(configFile.Name())
|
||||
suite.Require().NoError(err)
|
||||
suite.Contains(string(contents), "insecure-skip-tls-verify: true")
|
||||
|
|
|
@ -27,7 +27,7 @@ func NewLint(cfg env.Config) *Lint {
|
|||
}
|
||||
|
||||
// Execute executes the `helm lint` command.
|
||||
func (l *Lint) Execute(_ Config) error {
|
||||
func (l *Lint) Execute() error {
|
||||
return l.cmd.Run()
|
||||
}
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ func (suite *LintTestSuite) TestPrepareAndExecute() {
|
|||
|
||||
err := l.Prepare(cfg)
|
||||
suite.Require().Nil(err)
|
||||
l.Execute(cfg)
|
||||
l.Execute()
|
||||
}
|
||||
|
||||
func (suite *LintTestSuite) TestPrepareRequiresChart() {
|
||||
|
|
|
@ -23,7 +23,7 @@ func NewUninstall(cfg env.Config) *Uninstall {
|
|||
}
|
||||
|
||||
// Execute executes the `helm uninstall` command.
|
||||
func (u *Uninstall) Execute(_ Config) error {
|
||||
func (u *Uninstall) Execute() error {
|
||||
return u.cmd.Run()
|
||||
}
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ func (suite *UninstallTestSuite) TestPrepareAndExecute() {
|
|||
expected := []string{"uninstall", "zayde_wølf_king"}
|
||||
suite.Equal(expected, actual)
|
||||
|
||||
u.Execute(cfg)
|
||||
u.Execute()
|
||||
}
|
||||
|
||||
func (suite *UninstallTestSuite) TestPrepareDryRunFlag() {
|
||||
|
|
|
@ -45,7 +45,7 @@ func NewUpgrade(cfg env.Config) *Upgrade {
|
|||
}
|
||||
|
||||
// Execute executes the `helm upgrade` command.
|
||||
func (u *Upgrade) Execute(_ Config) error {
|
||||
func (u *Upgrade) Execute() error {
|
||||
return u.cmd.Run()
|
||||
}
|
||||
|
||||
|
|
|
@ -93,7 +93,7 @@ func (suite *UpgradeTestSuite) TestPrepareAndExecute() {
|
|||
cfg := Config{}
|
||||
err := u.Prepare(cfg)
|
||||
suite.Require().Nil(err)
|
||||
u.Execute(cfg)
|
||||
u.Execute()
|
||||
}
|
||||
|
||||
func (suite *UpgradeTestSuite) TestPrepareNamespaceFlag() {
|
||||
|
|
Loading…
Reference in a new issue