github.com/technosophos/deis@v1.7.1-0.20150915173815-f9005256004b/deisctl/backend/fleet/create_test.go (about) 1 package fleet 2 3 import ( 4 "io/ioutil" 5 "path" 6 "sync" 7 "testing" 8 9 "github.com/deis/deis/deisctl/config/model" 10 "github.com/deis/deis/deisctl/test/mock" 11 12 "github.com/coreos/fleet/schema" 13 ) 14 15 func TestCreate(t *testing.T) { 16 t.Parallel() 17 18 unitFiles := []string{"deis-controller.service", "deis-builder.service", 19 "deis-router.service"} 20 21 unitContents := []byte("[Unit]") 22 23 name, err := ioutil.TempDir("", "deisctl-fleetctl") 24 25 if err != nil { 26 t.Fatal(err) 27 } 28 29 for _, unit := range unitFiles { 30 ioutil.WriteFile(path.Join(name, unit), unitContents, 777) 31 } 32 33 testFleetClient := stubFleetClient{testUnits: []*schema.Unit{}, unitsMutex: &sync.Mutex{}, 34 unitStatesMutex: &sync.Mutex{}} 35 36 testConfigBackend := mock.ConfigBackend{Expected: []*model.ConfigNode{{Key: "/deis/platform/enablePlacementOptions", Value: "true"}}} 37 38 c := &FleetClient{templatePaths: []string{name}, Fleet: &testFleetClient, configBackend: testConfigBackend} 39 40 var errOutput string 41 var wg sync.WaitGroup 42 43 logMutex := sync.Mutex{} 44 45 se := newOutErr() 46 c.Create([]string{"controller", "builder", "router@1"}, &wg, se.out, se.ew) 47 48 wg.Wait() 49 50 logMutex.Lock() 51 if errOutput != "" { 52 t.Fatal(errOutput) 53 } 54 logMutex.Unlock() 55 56 expectedUnits := []string{"deis-controller.service", "deis-builder.service", 57 "deis-router@1.service"} 58 59 for _, expectedUnit := range expectedUnits { 60 found := false 61 62 for _, unit := range testFleetClient.testUnits { 63 if unit.Name == expectedUnit { 64 found = true 65 break 66 } 67 } 68 69 if !found { 70 t.Errorf("Expected Unit %s not found in Unit States", expectedUnit) 71 } 72 } 73 }