github.com/didip/deis@v1.4.1/deisctl/cmd/cmd_test.go (about) 1 package cmd 2 3 import ( 4 "fmt" 5 "reflect" 6 "sync" 7 "testing" 8 ) 9 10 type stubBackend struct{} 11 12 var ( 13 startedUnits []string 14 stoppedUnits []string 15 installedUnits []string 16 ) 17 18 func (backend stubBackend) Create([]string, *sync.WaitGroup, chan string, chan error) { 19 return 20 } 21 func (backend stubBackend) Destroy([]string, *sync.WaitGroup, chan string, chan error) { 22 return 23 } 24 func (backend stubBackend) Start(targets []string, wg *sync.WaitGroup, outchan chan string, errchan chan error) { 25 startedUnits = targets 26 return 27 } 28 func (backend stubBackend) Stop(targets []string, wg *sync.WaitGroup, outchan chan string, errchan chan error) { 29 stoppedUnits = targets 30 return 31 } 32 func (backend stubBackend) Scale(string, int, *sync.WaitGroup, chan string, chan error) { 33 return 34 } 35 func (backend stubBackend) ListUnits() error { 36 return fmt.Errorf("ListUnits not implemented yet.") 37 } 38 func (backend stubBackend) ListUnitFiles() error { 39 return fmt.Errorf("ListUnitFiles not implemented yet.") 40 } 41 func (backend stubBackend) Status(string) error { 42 return fmt.Errorf("Status not implemented yet.") 43 } 44 func (backend stubBackend) Journal(string) error { 45 return fmt.Errorf("Journal not implemented yet.") 46 } 47 48 var b stubBackend 49 50 // Start units 51 func TestStart(t *testing.T) { 52 Start([]string{"start", "router@1", "router@2"}, b) 53 54 if !reflect.DeepEqual(startedUnits, []string{"router@1", "router@2"}) { 55 t.Error(startedUnits) 56 } 57 } 58 59 // Stop units 60 func TestStop(t *testing.T) { 61 Stop([]string{"stop", "router@1", "router@2"}, b) 62 63 if !reflect.DeepEqual(stoppedUnits, []string{"router@1", "router@2"}) { 64 t.Error(stoppedUnits) 65 } 66 } 67 68 // Restart units 69 func TestRestart(t *testing.T) { 70 Restart([]string{"restart", "router@4", "router@5"}, b) 71 72 if !reflect.DeepEqual(stoppedUnits, []string{"router@4", "router@5"}) { 73 t.Error(stoppedUnits) 74 } 75 if !reflect.DeepEqual(startedUnits, []string{"router@4", "router@5"}) { 76 t.Error(startedUnits) 77 } 78 }