From 52c9fb552cd00d120578351588f98b6edc5629a9 Mon Sep 17 00:00:00 2001 From: Erin Call Date: Tue, 24 Dec 2019 15:33:50 -0800 Subject: [PATCH 1/3] Ensure the plan test mocks' expectations are met [#33] --- internal/helm/plan_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/helm/plan_test.go b/internal/helm/plan_test.go index e5a1a96..e61a51c 100644 --- a/internal/helm/plan_test.go +++ b/internal/helm/plan_test.go @@ -20,6 +20,7 @@ func TestPlanTestSuite(t *testing.T) { func (suite *PlanTestSuite) TestNewPlan() { ctrl := gomock.NewController(suite.T()) + defer ctrl.Finish() stepOne := NewMockStep(ctrl) stepTwo := NewMockStep(ctrl) @@ -63,6 +64,7 @@ func (suite *PlanTestSuite) TestNewPlan() { func (suite *PlanTestSuite) TestNewPlanAbortsOnError() { ctrl := gomock.NewController(suite.T()) + defer ctrl.Finish() stepOne := NewMockStep(ctrl) stepTwo := NewMockStep(ctrl) From d86ac72529f873a483978c730e18e88b60b3d0eb Mon Sep 17 00:00:00 2001 From: Erin Call Date: Tue, 24 Dec 2019 15:47:26 -0800 Subject: [PATCH 2/3] Test Plan.Execute [#33] --- internal/helm/plan_test.go | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/internal/helm/plan_test.go b/internal/helm/plan_test.go index e61a51c..7c8c22b 100644 --- a/internal/helm/plan_test.go +++ b/internal/helm/plan_test.go @@ -87,6 +87,51 @@ func (suite *PlanTestSuite) TestNewPlanAbortsOnError() { suite.EqualError(err, "while preparing *helm.MockStep step: I'm starry Dave, aye, cat blew that") } +func (suite *PlanTestSuite) TestExecute() { + ctrl := gomock.NewController(suite.T()) + defer ctrl.Finish() + stepOne := NewMockStep(ctrl) + stepTwo := NewMockStep(ctrl) + + runCfg := run.Config{} + + plan := Plan{ + steps: []Step{stepOne, stepTwo}, + runCfg: runCfg, + } + + stepOne.EXPECT(). + Execute(runCfg). + Times(1) + stepTwo.EXPECT(). + Execute(runCfg). + Times(1) + + suite.NoError(plan.Execute()) +} + +func (suite *PlanTestSuite) TestExecuteAbortsOnError() { + ctrl := gomock.NewController(suite.T()) + defer ctrl.Finish() + stepOne := NewMockStep(ctrl) + stepTwo := NewMockStep(ctrl) + + runCfg := run.Config{} + + plan := Plan{ + steps: []Step{stepOne, stepTwo}, + runCfg: runCfg, + } + + stepOne.EXPECT(). + Execute(runCfg). + Times(1). + Return(fmt.Errorf("oh, he'll gnaw")) + + err := plan.Execute() + suite.EqualError(err, "in execution step 0: oh, he'll gnaw") +} + func (suite *PlanTestSuite) TestUpgrade() { cfg := Config{ ChartVersion: "seventeen", From cb58b5a021f8c330c3f53ba2fcd35c3d62806453 Mon Sep 17 00:00:00 2001 From: Erin Call Date: Tue, 24 Dec 2019 15:49:47 -0800 Subject: [PATCH 3/3] Phrase errors in Execute the same as in Prepare [#33] --- internal/helm/plan.go | 2 +- internal/helm/plan_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/helm/plan.go b/internal/helm/plan.go index 1d4ced9..7a753e5 100644 --- a/internal/helm/plan.go +++ b/internal/helm/plan.go @@ -85,7 +85,7 @@ func (p *Plan) Execute() error { } if err := step.Execute(p.runCfg); err != nil { - return fmt.Errorf("in execution step %d: %w", i, err) + 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 7c8c22b..5a6550a 100644 --- a/internal/helm/plan_test.go +++ b/internal/helm/plan_test.go @@ -129,7 +129,7 @@ func (suite *PlanTestSuite) TestExecuteAbortsOnError() { Return(fmt.Errorf("oh, he'll gnaw")) err := plan.Execute() - suite.EqualError(err, "in execution step 0: oh, he'll gnaw") + suite.EqualError(err, "while executing *helm.MockStep step: oh, he'll gnaw") } func (suite *PlanTestSuite) TestUpgrade() {