diff --git a/internal/helm/mock_step_test.go b/internal/helm/mock_step_test.go index 5387162..ca8e90c 100644 --- a/internal/helm/mock_step_test.go +++ b/internal/helm/mock_step_test.go @@ -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)) } diff --git a/internal/helm/plan.go b/internal/helm/plan.go index bb1e901..5d28b10 100644 --- a/internal/helm/plan.go +++ b/internal/helm/plan.go @@ -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) } } diff --git a/internal/helm/plan_test.go b/internal/helm/plan_test.go index a792440..2dea619 100644 --- a/internal/helm/plan_test.go +++ b/internal/helm/plan_test.go @@ -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")) diff --git a/internal/run/addrepo.go b/internal/run/addrepo.go index 8cc7552..6a065bf 100644 --- a/internal/run/addrepo.go +++ b/internal/run/addrepo.go @@ -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() } diff --git a/internal/run/addrepo_test.go b/internal/run/addrepo_test.go index 51c31a0..5e4d0bc 100644 --- a/internal/run/addrepo_test.go +++ b/internal/run/addrepo_test.go @@ -70,7 +70,7 @@ func (suite *AddRepoTestSuite) TestPrepareAndExecute() { Run(). Times(1) - suite.Require().NoError(a.Execute(cfg)) + suite.Require().NoError(a.Execute()) } diff --git a/internal/run/depupdate.go b/internal/run/depupdate.go index c34c0ee..5f3f189 100644 --- a/internal/run/depupdate.go +++ b/internal/run/depupdate.go @@ -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() } diff --git a/internal/run/depupdate_test.go b/internal/run/depupdate_test.go index 94b0198..f0a7e1a 100644 --- a/internal/run/depupdate_test.go +++ b/internal/run/depupdate_test.go @@ -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() { diff --git a/internal/run/help.go b/internal/run/help.go index 40e0f86..69666d3 100644 --- a/internal/run/help.go +++ b/internal/run/help.go @@ -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) } diff --git a/internal/run/help_test.go b/internal/run/help_test.go index 0cf5927..1bad0bf 100644 --- a/internal/run/help_test.go +++ b/internal/run/help_test.go @@ -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() { diff --git a/internal/run/initkube.go b/internal/run/initkube.go index cee9d28..b6c0440 100644 --- a/internal/run/initkube.go +++ b/internal/run/initkube.go @@ -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) diff --git a/internal/run/initkube_test.go b/internal/run/initkube_test.go index 87e5398..567944e 100644 --- a/internal/run/initkube_test.go +++ b/internal/run/initkube_test.go @@ -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") diff --git a/internal/run/lint.go b/internal/run/lint.go index 03912fd..e6b550c 100644 --- a/internal/run/lint.go +++ b/internal/run/lint.go @@ -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() } diff --git a/internal/run/lint_test.go b/internal/run/lint_test.go index 3323ccb..e7469de 100644 --- a/internal/run/lint_test.go +++ b/internal/run/lint_test.go @@ -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() { diff --git a/internal/run/uninstall.go b/internal/run/uninstall.go index 790e9c6..07fd820 100644 --- a/internal/run/uninstall.go +++ b/internal/run/uninstall.go @@ -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() } diff --git a/internal/run/uninstall_test.go b/internal/run/uninstall_test.go index 0dafe33..6bac55c 100644 --- a/internal/run/uninstall_test.go +++ b/internal/run/uninstall_test.go @@ -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() { diff --git a/internal/run/upgrade.go b/internal/run/upgrade.go index b85b431..317f065 100644 --- a/internal/run/upgrade.go +++ b/internal/run/upgrade.go @@ -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() } diff --git a/internal/run/upgrade_test.go b/internal/run/upgrade_test.go index 46fb7c5..71b92cb 100644 --- a/internal/run/upgrade_test.go +++ b/internal/run/upgrade_test.go @@ -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() {