Skip to content

Commit

Permalink
Test BasicRunner halting ability
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Jun 4, 2013
1 parent 818eb85 commit c4395e1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
20 changes: 18 additions & 2 deletions basic_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ func TestBasicRunner_ImplRunner(t *testing.T) {

func TestBasicRunner_Run(t *testing.T) {
data := make(map[string]interface{})
stepA := &TestStepAcc{"a"}
stepB := &TestStepAcc{"b"}
stepA := &TestStepAcc{Data: "a"}
stepB := &TestStepAcc{Data: "b"}

r := &BasicRunner{[]Step{stepA, stepB}}
r.Run(data)
Expand All @@ -27,3 +27,19 @@ func TestBasicRunner_Run(t *testing.T) {
t.Errorf("unexpected result: %#v", results)
}
}

func TestBasicRunner_Run_Halt(t *testing.T) {
data := make(map[string]interface{})
stepA := &TestStepAcc{Data: "a"}
stepB := &TestStepAcc{Data: "b", Halt: true}
stepC := &TestStepAcc{Data: "c"}

r := &BasicRunner{[]Step{stepA, stepB, stepC}}
r.Run(data)

expected := []string{"a", "b"}
results := data["data"].([]string)
if !reflect.DeepEqual(results, expected) {
t.Errorf("unexpected result: %#v", results)
}
}
7 changes: 7 additions & 0 deletions multistep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ package multistep
type TestStepAcc struct {
// The data inserted into the state bag.
Data string

// If true, it will halt at the step when it is run
Halt bool
}

func (s TestStepAcc) Run(state map[string]interface{}) StepAction {
Expand All @@ -17,6 +20,10 @@ func (s TestStepAcc) Run(state map[string]interface{}) StepAction {
data = append(data, s.Data)
state["data"] = data

if s.Halt {
return ActionHalt
}

return ActionContinue
}

Expand Down

0 comments on commit c4395e1

Please sign in to comment.