-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcreate_test.go
More file actions
74 lines (54 loc) · 1.44 KB
/
create_test.go
File metadata and controls
74 lines (54 loc) · 1.44 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
package fleet
import (
"fmt"
"io/ioutil"
"path"
"sync"
"testing"
"github.com/coreos/fleet/schema"
)
func TestCreate(t *testing.T) {
t.Parallel()
unitFiles := []string{"deis-controller.service", "deis-builder.service",
"deis-router.service"}
unitContents := []byte("[Unit]")
name, err := ioutil.TempDir("", "deisctl-fleetctl")
if err != nil {
t.Fatal(err)
}
for _, unit := range unitFiles {
ioutil.WriteFile(path.Join(name, unit), unitContents, 777)
}
testFleetClient := stubFleetClient{testUnits: []*schema.Unit{}, unitsMutex: &sync.Mutex{},
unitStatesMutex: &sync.Mutex{}}
c := &FleetClient{templatePaths: []string{name}, Fleet: &testFleetClient}
var errOutput string
outchan := make(chan string)
errchan := make(chan error)
var wg sync.WaitGroup
logMutex := sync.Mutex{}
go logState(outchan, errchan, &errOutput, &logMutex)
c.Create([]string{"controller", "builder", "router@1"}, &wg, outchan, errchan)
wg.Wait()
close(errchan)
close(outchan)
logMutex.Lock()
if errOutput != "" {
t.Fatal(errOutput)
}
logMutex.Unlock()
expectedUnits := []string{"deis-controller.service", "deis-builder.service",
"deis-router@1.service"}
for _, expectedUnit := range expectedUnits {
found := false
for _, unit := range testFleetClient.testUnits {
if unit.Name == expectedUnit {
found = true
break
}
}
if !found {
t.Error(fmt.Errorf("Expected Unit %s not found in Unit States", expectedUnit))
}
}
}