-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcmd_test.go
More file actions
81 lines (70 loc) · 1.96 KB
/
cmd_test.go
File metadata and controls
81 lines (70 loc) · 1.96 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
package cmd
import (
"fmt"
"reflect"
"sync"
"testing"
)
type stubBackend struct{}
var (
startedUnits []string
stoppedUnits []string
installedUnits []string
)
func (backend stubBackend) Create([]string, *sync.WaitGroup, chan string, chan error) {
return
}
func (backend stubBackend) Destroy([]string, *sync.WaitGroup, chan string, chan error) {
return
}
func (backend stubBackend) Start(targets []string, wg *sync.WaitGroup, outchan chan string, errchan chan error) {
startedUnits = targets
return
}
func (backend stubBackend) Stop(targets []string, wg *sync.WaitGroup, outchan chan string, errchan chan error) {
stoppedUnits = targets
return
}
func (backend stubBackend) Scale(string, int, *sync.WaitGroup, chan string, chan error) {
return
}
func (backend stubBackend) ListUnits() error {
return fmt.Errorf("ListUnits not implemented yet.")
}
func (backend stubBackend) ListUnitFiles() error {
return fmt.Errorf("ListUnitFiles not implemented yet.")
}
func (backend stubBackend) Status(string) error {
return fmt.Errorf("Status not implemented yet.")
}
func (backend stubBackend) Journal(string) error {
return fmt.Errorf("Journal not implemented yet.")
}
func (backend stubBackend) SSH(string) error {
return fmt.Errorf("SSH not implemented yet.")
}
var b stubBackend
// Start units
func TestStart(t *testing.T) {
Start([]string{"start", "router@1", "router@2"}, b)
if !reflect.DeepEqual(startedUnits, []string{"router@1", "router@2"}) {
t.Error(startedUnits)
}
}
// Stop units
func TestStop(t *testing.T) {
Stop([]string{"stop", "router@1", "router@2"}, b)
if !reflect.DeepEqual(stoppedUnits, []string{"router@1", "router@2"}) {
t.Error(stoppedUnits)
}
}
// Restart units
func TestRestart(t *testing.T) {
Restart([]string{"restart", "router@4", "router@5"}, b)
if !reflect.DeepEqual(stoppedUnits, []string{"router@4", "router@5"}) {
t.Error(stoppedUnits)
}
if !reflect.DeepEqual(startedUnits, []string{"router@4", "router@5"}) {
t.Error(startedUnits)
}
}