-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathstart_test.go
More file actions
90 lines (69 loc) · 1.8 KB
/
start_test.go
File metadata and controls
90 lines (69 loc) · 1.8 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
package fleet
import (
"strings"
"sync"
"testing"
"github.com/coreos/fleet/schema"
)
var startTestUnits = []*schema.Unit{
&schema.Unit{
Name: "deis-controller.service",
DesiredState: "loaded",
},
&schema.Unit{
Name: "deis-builder.service",
DesiredState: "loaded",
},
&schema.Unit{
Name: "deis-publisher.service",
DesiredState: "loaded",
},
}
func TestStart(t *testing.T) {
t.Parallel()
testFleetClient := stubFleetClient{testUnits: startTestUnits,
unitsMutex: &sync.Mutex{}, unitStatesMutex: &sync.Mutex{}}
c := &FleetClient{Fleet: &testFleetClient}
var errOutput string
var wg sync.WaitGroup
logMutex := sync.Mutex{}
se := newOutErr()
c.Start([]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 != "running" {
t.Errorf("Unit %s is %s, expected running", unit.Name, unit.SystemdSubState)
}
break
}
}
if !found {
t.Errorf("Expected Unit %s not found in Unit States", expectedUnit)
}
}
}
func TestStartFail(t *testing.T) {
fc := &failingFleetClient{stubFleetClient{
testUnits: startTestUnits,
unitStatesMutex: &sync.Mutex{},
unitsMutex: &sync.Mutex{},
}}
var wg sync.WaitGroup
c := &FleetClient{Fleet: fc}
var b syncBuffer
c.Start([]string{"deis-builder.service"}, &wg, &b, &b)
wg.Wait()
if !strings.Contains(b.String(), "failed while starting") {
t.Errorf("Expected failure during start. Got '%s'", b.String())
}
}