github.com/technosophos/deis@v1.7.1-0.20150915173815-f9005256004b/deisctl/backend/fleet/start_test.go (about) 1 package fleet 2 3 import ( 4 "strings" 5 "sync" 6 "testing" 7 8 "github.com/coreos/fleet/schema" 9 ) 10 11 var startTestUnits = []*schema.Unit{ 12 &schema.Unit{ 13 Name: "deis-controller.service", 14 DesiredState: "loaded", 15 }, 16 &schema.Unit{ 17 Name: "deis-builder.service", 18 DesiredState: "loaded", 19 }, 20 &schema.Unit{ 21 Name: "deis-publisher.service", 22 DesiredState: "loaded", 23 }, 24 } 25 26 func TestStart(t *testing.T) { 27 t.Parallel() 28 29 testFleetClient := stubFleetClient{testUnits: startTestUnits, 30 unitsMutex: &sync.Mutex{}, unitStatesMutex: &sync.Mutex{}} 31 32 c := &FleetClient{Fleet: &testFleetClient} 33 34 var errOutput string 35 var wg sync.WaitGroup 36 37 logMutex := sync.Mutex{} 38 39 se := newOutErr() 40 c.Start([]string{"controller", "builder", "publisher"}, &wg, se.out, se.ew) 41 42 wg.Wait() 43 44 logMutex.Lock() 45 if errOutput != "" { 46 t.Fatal(errOutput) 47 } 48 logMutex.Unlock() 49 50 expected := []string{"deis-controller.service", "deis-builder.service", "deis-publisher.service"} 51 52 for _, expectedUnit := range expected { 53 found := false 54 55 for _, unit := range testFleetClient.testUnitStates { 56 if unit.Name == expectedUnit { 57 found = true 58 59 if unit.SystemdSubState != "running" { 60 t.Errorf("Unit %s is %s, expected running", unit.Name, unit.SystemdSubState) 61 } 62 63 break 64 } 65 } 66 67 if !found { 68 t.Errorf("Expected Unit %s not found in Unit States", expectedUnit) 69 } 70 } 71 } 72 73 func TestStartFail(t *testing.T) { 74 fc := &failingFleetClient{stubFleetClient{ 75 testUnits: startTestUnits, 76 unitStatesMutex: &sync.Mutex{}, 77 unitsMutex: &sync.Mutex{}, 78 }} 79 var wg sync.WaitGroup 80 c := &FleetClient{Fleet: fc} 81 82 var b syncBuffer 83 c.Start([]string{"deis-builder.service"}, &wg, &b, &b) 84 wg.Wait() 85 86 if !strings.Contains(b.String(), "failed while starting") { 87 t.Errorf("Expected failure during start. Got '%s'", b.String()) 88 } 89 90 }