-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathjournal_test.go
More file actions
78 lines (62 loc) · 1.63 KB
/
journal_test.go
File metadata and controls
78 lines (62 loc) · 1.63 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
package fleet
import (
"bytes"
"fmt"
"sync"
"testing"
"time"
"github.com/coreos/fleet/machine"
"github.com/coreos/fleet/schema"
)
type mockJournalCommandRunner struct {
validUnits []string
}
func (mockJournalCommandRunner) LocalCommand(string) (int, error) {
return 0, nil
}
func (m mockJournalCommandRunner) RemoteCommand(cmd string, addr string, timeout time.Duration) (int, error) {
if addr != "1.1.1.1" || timeout != 0 {
return -1, fmt.Errorf("Got %s %d, which is unexpected", cmd, addr, timeout)
}
for _, unit := range m.validUnits {
if fmt.Sprintf("journalctl --unit %s --no-pager -n 40 -f", unit) == cmd {
return 0, nil
}
}
return -1, fmt.Errorf("Didn't find command %s to match with units %v", cmd, m.validUnits)
}
func TestJournal(t *testing.T) {
t.Parallel()
testMachines := []machine.MachineState{
machine.MachineState{
ID: "test-1",
PublicIP: "1.1.1.1",
Metadata: nil,
Version: "",
},
}
testUnits := []*schema.Unit{
&schema.Unit{
Name: "deis-router@1.service",
CurrentState: "loaded",
MachineID: "test-1",
},
&schema.Unit{
Name: "deis-router@2.service",
CurrentState: "loaded",
MachineID: "test-1",
},
}
testWriter := bytes.Buffer{}
c := &FleetClient{Fleet: &stubFleetClient{testUnits: testUnits, testMachineStates: testMachines,
unitsMutex: &sync.Mutex{}}, errWriter: &testWriter, runner: mockJournalCommandRunner{
validUnits: []string{"deis-router@1.service", "deis-router@2.service"}}}
err := c.Journal("router")
if err != nil {
t.Error(err)
}
commandErr := testWriter.String()
if commandErr != "" {
t.Error(commandErr)
}
}