-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlist_units_test.go
More file actions
74 lines (62 loc) · 1.58 KB
/
list_units_test.go
File metadata and controls
74 lines (62 loc) · 1.58 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 (
"bytes"
"sync"
"testing"
"text/tabwriter"
"github.com/coreos/fleet/machine"
"github.com/coreos/fleet/schema"
)
func TestListUnits(t *testing.T) {
t.Parallel()
testUnitStates := []*schema.UnitState{
&schema.UnitState{
Name: "deis-controller.service",
MachineID: "123456",
SystemdLoadState: "loaded",
SystemdActiveState: "active",
SystemdSubState: "running",
Hash: "abcd",
},
&schema.UnitState{
Name: "deis-router@1.service",
MachineID: "654321",
SystemdLoadState: "loaded",
SystemdActiveState: "active",
SystemdSubState: "running",
Hash: "dcba",
},
}
testMachines := []machine.MachineState{
machine.MachineState{
ID: "123456",
PublicIP: "1.1.1.1",
Metadata: nil,
Version: "",
},
machine.MachineState{
ID: "654321",
PublicIP: "2.2.2.2",
Metadata: nil,
Version: "",
},
}
testWriter := bytes.Buffer{}
testTabWriter := new(tabwriter.Writer)
testTabWriter.Init(&testWriter, 0, 8, 1, '\t', 0)
c := &FleetClient{Fleet: &stubFleetClient{testUnitStates: testUnitStates,
testMachineStates: testMachines, unitStatesMutex: &sync.Mutex{}},
out: testTabWriter}
err := c.ListUnits()
if err != nil {
t.Fatal(err)
}
expected := `UNIT MACHINE LOAD ACTIVE SUB
deis-controller.service 123456.../1.1.1.1 loaded active running
deis-router@1.service 654321.../2.2.2.2 loaded active running
`
actual := testWriter.String()
if expected != actual {
t.Errorf("Expected '%s', Got '%s'", expected, actual)
}
}