-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathstop_test.go
More file actions
105 lines (83 loc) · 2.1 KB
/
stop_test.go
File metadata and controls
105 lines (83 loc) · 2.1 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package fleet
import (
"strings"
"sync"
"testing"
"github.com/coreos/fleet/schema"
)
func TestStop(t *testing.T) {
t.Parallel()
testUnits := []*schema.Unit{
&schema.Unit{
Name: "deis-controller.service",
DesiredState: "launched",
},
&schema.Unit{
Name: "deis-builder.service",
DesiredState: "launched",
},
&schema.Unit{
Name: "deis-publisher.service",
DesiredState: "launch",
},
}
testFleetClient := stubFleetClient{testUnits: testUnits, unitsMutex: &sync.Mutex{},
unitStatesMutex: &sync.Mutex{}}
c := &FleetClient{Fleet: &testFleetClient}
var errOutput string
var wg sync.WaitGroup
logMutex := sync.Mutex{}
se := newOutErr()
c.Stop([]string{"controller", "builder", "publisher"}, &wg, se.out, se.ew)
wg.Wait()
logMutex.Lock()
if errOutput != "" {
t.Fatal(errOutput)
}
logMutex.Unlock()
expected := []string{"deis-controller.service", "deis-builder.service", "deis-publisher.service"}
for _, expectedUnit := range expected {
found := false
for _, unit := range testFleetClient.testUnitStates {
if unit.Name == expectedUnit {
found = true
if unit.SystemdSubState != "dead" {
t.Errorf("Unit %s is %s, expected dead", unit.Name, unit.SystemdSubState)
}
break
}
}
if !found {
t.Errorf("Expected Unit %s not found in Unit States", expectedUnit)
}
}
}
var stopTestUnits = []*schema.Unit{
&schema.Unit{
Name: "deis-controller.service",
DesiredState: "launched",
},
&schema.Unit{
Name: "deis-builder.service",
DesiredState: "launched",
},
&schema.Unit{
Name: "deis-publisher.service",
DesiredState: "launch",
},
}
func TestStopFail(t *testing.T) {
fc := &failingFleetClient{stubFleetClient{
testUnits: stopTestUnits,
unitStatesMutex: &sync.Mutex{},
unitsMutex: &sync.Mutex{},
}}
var wg sync.WaitGroup
c := &FleetClient{Fleet: fc}
var b syncBuffer
c.Stop([]string{"deis-builder.service"}, &wg, &b, &b)
wg.Wait()
if !strings.Contains(b.String(), "failed while stopping") {
t.Errorf("Expected 'failed while stopping'. Got '%s'", b.String())
}
}