Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
Signed-off-by: Andrii Nasinnyk <[email protected]>
  • Loading branch information
anasinnyk committed Jun 14, 2019
1 parent e920eca commit b8d744f
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 27 deletions.
21 changes: 21 additions & 0 deletions server/events/mocks/matchers/map_of_string_to_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 12 additions & 8 deletions server/events/mocks/mock_custom_step_runner.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 12 additions & 8 deletions server/events/mocks/mock_step_runner.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 4 additions & 10 deletions server/events/project_command_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestDefaultProjectCommandRunner_Plan(t *testing.T) {
mockInit := mocks.NewMockStepRunner()
mockPlan := mocks.NewMockStepRunner()
mockApply := mocks.NewMockStepRunner()
mockEnv := mocks.NewMockEnvStepRunner()
mockRun := mocks.NewMockCustomStepRunner()
mockWorkingDir := mocks.NewMockWorkingDir()
mockLocker := mocks.NewMockProjectLocker()
Expand All @@ -45,6 +46,7 @@ func TestDefaultProjectCommandRunner_Plan(t *testing.T) {
PlanStepRunner: mockPlan,
ApplyStepRunner: mockApply,
RunStepRunner: mockRun,
EnvStepRunner: mockEnv,
PullApprovedChecker: nil,
WorkingDir: mockWorkingDir,
Webhooks: nil,
Expand Down Expand Up @@ -86,28 +88,20 @@ func TestDefaultProjectCommandRunner_Plan(t *testing.T) {
{
StepName: "init",
},
{
StepName: "env",
Env: "test",
RunCommand: "echo 123",
},
},
Workspace: "default",
RepoRelDir: ".",
Env: map[string]string{},
}
// Each step will output its step name.
When(mockInit.Run(ctx, nil, repoDir)).ThenReturn("init", nil)
When(mockPlan.Run(ctx, nil, repoDir)).ThenReturn("plan", nil)
When(mockApply.Run(ctx, nil, repoDir)).ThenReturn("apply", nil)
When(mockRun.Run(ctx, "", repoDir)).ThenReturn("run", nil)
When(mockRun.Run(ctx, "echo 123", repoDir)).ThenReturn("123", nil)
res := runner.Plan(ctx)

Assert(t, res.PlanSuccess != nil, "exp plan success")
Equals(t, "https://lock-key", res.PlanSuccess.LockURL)
Equals(t, "run\napply\nplan\ninit", res.PlanSuccess.TerraformOutput)
Equals(t, "123", ctx.Env["test"])

expSteps := []string{"run", "apply", "plan", "init", "var"}
for _, step := range expSteps {
Expand All @@ -120,8 +114,6 @@ func TestDefaultProjectCommandRunner_Plan(t *testing.T) {
mockApply.VerifyWasCalledOnce().Run(ctx, nil, repoDir)
case "run":
mockRun.VerifyWasCalledOnce().Run(ctx, "", repoDir)
case "env":
mockRun.VerifyWasCalledOnce().Run(ctx, "echo 123", repoDir)
}
}
}
Expand Down Expand Up @@ -260,6 +252,7 @@ func TestDefaultProjectCommandRunner_Apply(t *testing.T) {
mockPlan := mocks.NewMockStepRunner()
mockApply := mocks.NewMockStepRunner()
mockRun := mocks.NewMockCustomStepRunner()
mockEnv := mocks.NewMockEnvStepRunner()
mockApproved := mocks2.NewMockPullApprovedChecker()
mockWorkingDir := mocks.NewMockWorkingDir()
mockLocker := mocks.NewMockProjectLocker()
Expand All @@ -272,6 +265,7 @@ func TestDefaultProjectCommandRunner_Apply(t *testing.T) {
PlanStepRunner: mockPlan,
ApplyStepRunner: mockApply,
RunStepRunner: mockRun,
EnvStepRunner: mockEnv,
PullApprovedChecker: mockApproved,
WorkingDir: mockWorkingDir,
Webhooks: mockSender,
Expand Down
2 changes: 1 addition & 1 deletion server/events/yaml/raw/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (s *Step) unmarshalGeneric(unmarshal func(interface{}) error) error {
// name: k
// value: hi //optional
// command: exec
// We validate if the key var
// We validate if the key env
var envStep map[string]map[string]string
err = unmarshal(&envStep)
if err == nil {
Expand Down

0 comments on commit b8d744f

Please sign in to comment.