-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathstop_test.go
More file actions
74 lines (57 loc) · 1.48 KB
/
stop_test.go
File metadata and controls
74 lines (57 loc) · 1.48 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
package fleet
import (
"fmt"
"sync"
"testing"
"github.com/coreos/fleet/schema"
)
func TestStop(t *testing.T) {
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
outchan := make(chan string)
errchan := make(chan error)
var wg sync.WaitGroup
logMutex := sync.Mutex{}
go logState(outchan, errchan, &errOutput, &logMutex)
c.Stop([]string{"controller", "builder", "publisher"}, &wg, outchan, errchan)
wg.Wait()
close(errchan)
close(outchan)
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.Error(fmt.Errorf("Unit %s is %s, expected dead", unit.Name, unit.SystemdSubState))
}
break
}
}
if !found {
t.Error(fmt.Errorf("Expected Unit %s not found in Unit States", expectedUnit))
}
}
}