-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathscale_test.go
More file actions
150 lines (110 loc) · 2.83 KB
/
scale_test.go
File metadata and controls
150 lines (110 loc) · 2.83 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package fleet
import (
"io/ioutil"
"path"
"strings"
"sync"
"testing"
"github.com/coreos/fleet/schema"
)
func TestScaleUp(t *testing.T) {
t.Parallel()
name, err := ioutil.TempDir("", "deisctl-fleetctl")
if err != nil {
t.Fatal(err)
}
ioutil.WriteFile(path.Join(name, "deis-router.service"), []byte("[Unit]"), 777)
testUnits := []*schema.Unit{
&schema.Unit{
Name: "deis-router@1.service",
DesiredState: "launched",
},
}
testFleetClient := stubFleetClient{testUnits: testUnits, testUnitStates: []*schema.UnitState{}, unitsMutex: &sync.Mutex{}, unitStatesMutex: &sync.Mutex{}}
c := &FleetClient{templatePaths: []string{name}, Fleet: &testFleetClient}
var errOutput string
var wg sync.WaitGroup
logMutex := sync.Mutex{}
se := newOutErr()
c.Scale("router", 3, &wg, se.out, se.ew)
wg.Wait()
logMutex.Lock()
if errOutput != "" {
t.Fatal(errOutput)
}
logMutex.Unlock()
expectedUnits := []string{"deis-router@1.service", "deis-router@2.service",
"deis-router@3.service"}
for _, expectedUnit := range expectedUnits {
found := false
for _, unit := range testFleetClient.testUnits {
if unit.Name == expectedUnit {
found = true
break
}
}
if !found {
t.Errorf("Expected Unit %s not found in Unit States", expectedUnit)
}
}
}
func TestScaleDown(t *testing.T) {
t.Parallel()
testUnits := []*schema.Unit{
&schema.Unit{
Name: "deis-router@1.service",
DesiredState: "launched",
},
&schema.Unit{
Name: "deis-router@2.service",
DesiredState: "launched",
},
&schema.Unit{
Name: "deis-router@3.service",
DesiredState: "launched",
},
}
testFleetClient := stubFleetClient{testUnits: testUnits, testUnitStates: []*schema.UnitState{}, unitsMutex: &sync.Mutex{}, unitStatesMutex: &sync.Mutex{}}
c := &FleetClient{Fleet: &testFleetClient}
var errOutput string
var wg sync.WaitGroup
logMutex := sync.Mutex{}
se := newOutErr()
c.Scale("router", 1, &wg, se.out, se.ew)
wg.Wait()
logMutex.Lock()
if errOutput != "" {
t.Fatal(errOutput)
}
logMutex.Unlock()
expectedUnits := []string{"deis-router@1.service"}
for _, expectedUnit := range expectedUnits {
found := false
for _, unit := range testFleetClient.testUnits {
if unit.Name == expectedUnit {
found = true
break
}
}
if !found {
t.Errorf("Expected Unit %s not found in Unit States", expectedUnit)
}
}
}
func TestScaleError(t *testing.T) {
t.Parallel()
c := &FleetClient{Fleet: &stubFleetClient{}}
var errOutput string
var wg sync.WaitGroup
logMutex := sync.Mutex{}
se := newOutErr()
c.Scale("router", -1, &wg, se.out, se.ew)
wg.Wait()
expected := "cannot scale below 0"
errOutput = strings.TrimSpace(se.ew.String())
logMutex.Lock()
if errOutput != expected {
t.Errorf("Expected '%s', Got '%s'", expected, errOutput)
}
logMutex.Unlock()
}