|
1 | 1 | package fleet |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "strings" |
4 | 5 | "sync" |
5 | 6 | "testing" |
6 | 7 |
|
7 | 8 | "github.com/coreos/fleet/schema" |
8 | 9 | ) |
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 | + |
10 | 26 | func TestStart(t *testing.T) { |
11 | 27 | t.Parallel() |
12 | 28 |
|
13 | | - testUnits := []*schema.Unit{ |
14 | | - &schema.Unit{ |
15 | | - Name: "deis-controller.service", |
16 | | - DesiredState: "loaded", |
17 | | - }, |
18 | | - &schema.Unit{ |
19 | | - Name: "deis-builder.service", |
20 | | - DesiredState: "loaded", |
21 | | - }, |
22 | | - &schema.Unit{ |
23 | | - Name: "deis-publisher.service", |
24 | | - DesiredState: "loaded", |
25 | | - }, |
26 | | - } |
27 | | - |
28 | | - testFleetClient := stubFleetClient{testUnits: testUnits, |
| 29 | + testFleetClient := stubFleetClient{testUnits: startTestUnits, |
29 | 30 | unitsMutex: &sync.Mutex{}, unitStatesMutex: &sync.Mutex{}} |
30 | 31 |
|
31 | 32 | c := &FleetClient{Fleet: &testFleetClient} |
@@ -68,3 +69,22 @@ func TestStart(t *testing.T) { |
68 | 69 | } |
69 | 70 | } |
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 | +} |
0 commit comments