-
Notifications
You must be signed in to change notification settings - Fork 158
/
processes_test.go
123 lines (112 loc) · 2.63 KB
/
processes_test.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
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
package empire
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewFormation(t *testing.T) {
tests := []struct {
f Formation
other Formation
expected Formation
}{
// Check that default quantity and constraints are merged in.
{
f: Formation{
"web": Process{
Command: Command{"./bin/web"},
},
"worker": Process{
Command: Command{"sidekiq"},
},
},
other: nil,
expected: Formation{
"web": Process{
Quantity: 1,
Command: Command{"./bin/web"},
Memory: NamedConstraints["1X"].Memory,
CPUShare: NamedConstraints["1X"].CPUShare,
Nproc: NamedConstraints["1X"].Nproc,
},
"worker": Process{
Quantity: 0,
Command: Command{"sidekiq"},
Memory: NamedConstraints["1X"].Memory,
CPUShare: NamedConstraints["1X"].CPUShare,
Nproc: NamedConstraints["1X"].Nproc,
},
},
},
// Check that the quantity and constraints from the existing
// configuration are used.
{
f: Formation{
"web": Process{
Command: Command{"./bin/web"},
},
},
other: Formation{
"web": Process{
Command: Command{"./bin/web"},
Quantity: 2,
Memory: NamedConstraints["PX"].Memory,
CPUShare: NamedConstraints["PX"].CPUShare,
Nproc: NamedConstraints["PX"].Nproc,
},
},
expected: Formation{
"web": Process{
Quantity: 2,
Command: Command{"./bin/web"},
Memory: NamedConstraints["PX"].Memory,
CPUShare: NamedConstraints["PX"].CPUShare,
Nproc: NamedConstraints["PX"].Nproc,
},
},
},
// Check that removed processes are ignored.
{
f: Formation{
"web": Process{
Command: Command{"./bin/web"},
},
},
other: Formation{
"worker": Process{
Command: Command{"sidekiq"},
Quantity: 2,
Memory: NamedConstraints["PX"].Memory,
CPUShare: NamedConstraints["PX"].CPUShare,
Nproc: NamedConstraints["PX"].Nproc,
},
},
expected: Formation{
"web": Process{
Quantity: 1,
Command: Command{"./bin/web"},
Memory: NamedConstraints["1X"].Memory,
CPUShare: NamedConstraints["1X"].CPUShare,
Nproc: NamedConstraints["1X"].Nproc,
},
},
},
}
for _, tt := range tests {
f := tt.f.Merge(tt.other)
assert.Equal(t, tt.expected, f)
}
}
func ExampleCommand() {
cmd := Command{"/bin/ls", "-h"}
fmt.Println(cmd)
}
func ExampleParseCommand() {
cmd1, _ := ParseCommand(`/bin/ls -h`)
cmd2, _ := ParseCommand(`/bin/echo 'hello world'`)
fmt.Printf("%#v\n", cmd1)
fmt.Printf("%#v\n", cmd2)
// Output:
// empire.Command{"/bin/ls", "-h"}
// empire.Command{"/bin/echo", "hello world"}
}