@@ -13,6 +13,9 @@ import (
1313 "testing"
1414
1515 "github.com/deis/deis/deisctl/backend"
16+ "github.com/deis/deis/deisctl/config"
17+ "github.com/deis/deis/deisctl/config/model"
18+ "github.com/deis/deis/deisctl/test/mock"
1619 "github.com/deis/deis/deisctl/units"
1720)
1821
@@ -21,6 +24,7 @@ type backendStub struct {
2124 stoppedUnits []string
2225 installedUnits []string
2326 uninstalledUnits []string
27+ restartedUnits []string
2428 expected bool
2529}
2630
@@ -46,6 +50,10 @@ func (backend *backendStub) Scale(component string, num int, wg *sync.WaitGroup,
4650 backend .expected = false
4751 }
4852}
53+ func (backend * backendStub ) RollingRestart (target string , wg * sync.WaitGroup , out , ew io.Writer ) {
54+ backend .restartedUnits = append (backend .restartedUnits , target )
55+ }
56+
4957func (backend * backendStub ) ListUnits () error {
5058 return nil
5159}
@@ -79,7 +87,7 @@ func (backend *backendStub) SSHExec(target, command string) error {
7987
8088var _ backend.Backend = & backendStub {}
8189
82- func fakeCheckKeys () error {
90+ func fakeCheckKeys (cb config. Backend ) error {
8391 return nil
8492}
8593
@@ -270,6 +278,57 @@ func TestStartSwarm(t *testing.T) {
270278 }
271279}
272280
281+ func TestRollingRestart (t * testing.T ) {
282+ t .Parallel ()
283+
284+ b := backendStub {}
285+ expected := []string {"router" }
286+
287+ RollingRestart ("router" , & b )
288+
289+ if ! reflect .DeepEqual (b .restartedUnits , expected ) {
290+ t .Error (fmt .Errorf ("Expected %v, Got %v" , expected , b .restartedUnits ))
291+ }
292+ }
293+
294+ func TestUpgradePrep (t * testing.T ) {
295+ t .Parallel ()
296+
297+ b := backendStub {}
298+ expected := []string {"database" , "registry@*" , "controller" , "builder" , "logger" , "logspout" , "store-volume" ,
299+ "store-gateway@*" , "store-metadata" , "store-daemon" , "store-monitor" }
300+
301+ UpgradePrep (& b )
302+
303+ if ! reflect .DeepEqual (b .stoppedUnits , expected ) {
304+ t .Error (fmt .Errorf ("Expected %v, Got %v" , expected , b .stoppedUnits ))
305+ }
306+ }
307+
308+ func TestUpgradeTakeover (t * testing.T ) {
309+ t .Parallel ()
310+ testMock := mock.ConfigBackend {Expected : []* model.ConfigNode {{Key : "/deis/services/app1" , Value : "foo" , TTL : 10 },
311+ {Key : "/deis/services/app2" , Value : "8000" , TTL : 10 }}}
312+
313+ b := backendStub {}
314+ expectedRestarted := []string {"router" }
315+ expectedStarted := []string {"publisher" , "store-monitor" , "store-daemon" , "store-metadata" ,
316+ "store-gateway@*" , "store-volume" , "logger" , "logspout" , "database" , "registry@*" ,
317+ "controller" , "builder" , "publisher" , "router@*" , "database" , "registry@*" ,
318+ "controller" , "builder" , "publisher" , "router@*" }
319+
320+ if err := doUpgradeTakeOver (& b , testMock ); err != nil {
321+ t .Error (fmt .Errorf ("Takeover failed: %v" , err ))
322+ }
323+
324+ if ! reflect .DeepEqual (b .restartedUnits , expectedRestarted ) {
325+ t .Error (fmt .Errorf ("Expected %v, Got %v" , expectedRestarted , b .restartedUnits ))
326+ }
327+ if ! reflect .DeepEqual (b .startedUnits , expectedStarted ) {
328+ t .Error (fmt .Errorf ("Expected %v, Got %v" , expectedStarted , b .startedUnits ))
329+ }
330+ }
331+
273332func TestStop (t * testing.T ) {
274333 t .Parallel ()
275334
@@ -419,9 +478,11 @@ func TestInstall(t *testing.T) {
419478 t .Parallel ()
420479
421480 b := backendStub {}
481+ cb := mock.ConfigBackend {}
482+
422483 expected := []string {"router@1" , "router@2" }
423484
424- Install (expected , & b , fakeCheckKeys )
485+ Install (expected , & b , & cb , fakeCheckKeys )
425486
426487 if ! reflect .DeepEqual (b .installedUnits , expected ) {
427488 t .Error (fmt .Errorf ("Expected %v, Got %v" , expected , b .installedUnits ))
@@ -432,11 +493,13 @@ func TestInstallPlatform(t *testing.T) {
432493 t .Parallel ()
433494
434495 b := backendStub {}
496+ cb := mock.ConfigBackend {}
497+
435498 expected := []string {"store-daemon" , "store-monitor" , "store-metadata" , "store-volume" ,
436499 "store-gateway@1" , "logger" , "logspout" , "database" , "registry@1" ,
437500 "controller" , "builder" , "publisher" , "router@1" , "router@2" , "router@3" }
438501
439- Install ([]string {"platform" }, & b , fakeCheckKeys )
502+ Install ([]string {"platform" }, & b , & cb , fakeCheckKeys )
440503
441504 if ! reflect .DeepEqual (b .installedUnits , expected ) {
442505 t .Error (fmt .Errorf ("Expected %v, Got %v" , expected , b .installedUnits ))
@@ -447,12 +510,14 @@ func TestInstallPlatformWithCustomRouterMeshSize(t *testing.T) {
447510 t .Parallel ()
448511
449512 b := backendStub {}
513+ cb := mock.ConfigBackend {}
514+
450515 expected := []string {"store-daemon" , "store-monitor" , "store-metadata" , "store-volume" ,
451516 "store-gateway@1" , "logger" , "logspout" , "database" , "registry@1" ,
452517 "controller" , "builder" , "publisher" , "router@1" , "router@2" , "router@3" , "router@4" , "router@5" }
453518 RouterMeshSize = 5
454519
455- Install ([]string {"platform" }, & b , fakeCheckKeys )
520+ Install ([]string {"platform" }, & b , & cb , fakeCheckKeys )
456521 RouterMeshSize = DefaultRouterMeshSize
457522
458523 if ! reflect .DeepEqual (b .installedUnits , expected ) {
@@ -464,10 +529,12 @@ func TestInstallStatelessPlatform(t *testing.T) {
464529 t .Parallel ()
465530
466531 b := backendStub {}
532+ cb := mock.ConfigBackend {}
533+
467534 expected := []string {"logspout" , "registry@1" ,
468535 "controller" , "builder" , "publisher" , "router@1" , "router@2" , "router@3" }
469536
470- Install ([]string {"stateless-platform" }, & b , fakeCheckKeys )
537+ Install ([]string {"stateless-platform" }, & b , & cb , fakeCheckKeys )
471538
472539 if ! reflect .DeepEqual (b .installedUnits , expected ) {
473540 t .Error (fmt .Errorf ("Expected %v, Got %v" , expected , b .installedUnits ))
@@ -478,9 +545,11 @@ func TestInstallSwarm(t *testing.T) {
478545 t .Parallel ()
479546
480547 b := backendStub {}
548+ cb := mock.ConfigBackend {}
549+
481550 expected := []string {"swarm-node" , "swarm-manager" }
482551
483- Install ([]string {"swarm" }, & b , fakeCheckKeys )
552+ Install ([]string {"swarm" }, & b , & cb , fakeCheckKeys )
484553
485554 if ! reflect .DeepEqual (b .installedUnits , expected ) {
486555 t .Error (fmt .Errorf ("Expected %v, Got %v" , expected , b .installedUnits ))
0 commit comments