/
down-script-steps.go
69 lines (49 loc) · 1.43 KB
/
down-script-steps.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
package steps
import (
"fmt"
"strings"
"github.com/ess/jamaica"
"github.com/ess/kennel"
)
type DownScript struct{}
func (steps *DownScript) StepUp(s kennel.Suite) {
s.Step(`^the stop script is not executed$`, func() error {
if strings.Contains(jamaica.LastCommandStdout(), "STOP_SCRIPT:") {
return fmt.Errorf("Expected the stop script to not be run")
}
return nil
})
s.Step(`^the stop script is executed for each target server$`, func() error {
output := jamaica.LastCommandStdout()
expected := len(mygroup.ScalingServers)
actual := strings.Count(output, "STOP_SCRIPT")
if actual != expected {
return fmt.Errorf("Expected %d stop script results, got %d", expected, actual)
}
return nil
})
s.Step(`^a stop script failure is logged for the first server$`, func() error {
output := jamaica.LastCommandStdout()
expected := 1
actual := strings.Count(output, "STOP_SCRIPT_ERROR")
if actual != expected {
return fmt.Errorf("Expected %d stop script errors, got %d", expected, actual)
}
found := ""
for _, line := range strings.Split(output, "\n") {
if strings.HasPrefix(line, "FAILURE : Group[mygroup]:") {
found = line
}
}
if len(found) == 0 {
return fmt.Errorf("No failure generated")
}
if !strings.Contains(found, mygroup.ScalingServers[0]) {
return fmt.Errorf("First server not listed in failure")
}
return nil
})
}
func init() {
kennel.Register(new(DownScript))
}