-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathmultistep_test.go
74 lines (56 loc) · 1.55 KB
/
multistep_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package multistep
// A step for testing that accumuluates data into a string slice in the
// the state bag. It always uses the "data" key in the state bag, and will
// initialize it.
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
}
// A step that syncs by sending a channel and expecting a response.
type TestStepSync struct {
Ch chan chan bool
}
// A step that sleeps forever
type TestStepWaitForever struct {
}
// A step that manually flips state to cancelling in run
type TestStepInjectCancel struct {
}
func (s TestStepAcc) Run(state StateBag) StepAction {
s.insertData(state, "data")
if s.Halt {
return ActionHalt
}
return ActionContinue
}
func (s TestStepAcc) Cleanup(state StateBag) {
s.insertData(state, "cleanup")
}
func (s TestStepAcc) insertData(state StateBag, key string) {
if _, ok := state.GetOk(key); !ok {
state.Put(key, make([]string, 0, 5))
}
data := state.Get(key).([]string)
data = append(data, s.Data)
state.Put(key, data)
}
func (s TestStepSync) Run(StateBag) StepAction {
ch := make(chan bool)
s.Ch <- ch
<-ch
return ActionContinue
}
func (s TestStepSync) Cleanup(StateBag) {}
func (s TestStepWaitForever) Run(StateBag) StepAction {
select {}
return ActionContinue
}
func (s TestStepWaitForever) Cleanup(StateBag) {}
func (s TestStepInjectCancel) Run(state StateBag) StepAction {
r := state.Get("runner").(*BasicRunner)
r.state = stateCancelling
return ActionContinue
}
func (s TestStepInjectCancel) Cleanup(StateBag) {}