Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Commit 7bcdb51

Browse files
author
Dongsu Park
committed
functional: a new test TestUnitLoad to check fleetctl {load,unload}
A new test TestUnitLoad verifies that "fleetctl {load,unload}" correctly works: load -> list-units -> unload -> list-units -> load
1 parent 64863ee commit 7bcdb51

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

functional/unit_action_test.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,81 @@ func TestUnitSubmit(t *testing.T) {
129129
}
130130
}
131131

132+
// TestUnitLoad checks if a unit becomes loaded and unloaded successfully.
133+
// First it load a unit, and unloads the unit, verifies it's unloaded,
134+
// finally loads the unit again.
135+
func TestUnitLoad(t *testing.T) {
136+
cluster, err := platform.NewNspawnCluster("smoke")
137+
if err != nil {
138+
t.Fatal(err)
139+
}
140+
defer cluster.Destroy()
141+
142+
m, err := cluster.CreateMember()
143+
if err != nil {
144+
t.Fatal(err)
145+
}
146+
_, err = cluster.WaitForNMachines(m, 1)
147+
if err != nil {
148+
t.Fatal(err)
149+
}
150+
151+
unitFile := "fixtures/units/hello.service"
152+
153+
// load a unit and assert it shows up
154+
_, _, err = cluster.Fleetctl(m, "load", unitFile)
155+
if err != nil {
156+
t.Fatalf("Unable to load fleet unit: %v", err)
157+
}
158+
159+
// wait until the unit gets loaded up to 15 seconds
160+
listUnitStates, err := cluster.WaitForNUnits(m, 1)
161+
if err != nil {
162+
t.Fatalf("Failed to run list-units: %v", err)
163+
}
164+
165+
// given unit name must be there in list-units
166+
_, found := listUnitStates[path.Base(unitFile)]
167+
if len(listUnitStates) != 1 || !found {
168+
t.Fatalf("Expected %s to be unit, got %v", path.Base(unitFile), listUnitStates)
169+
}
170+
171+
// unload the unit and ensure it disappears from the unit list
172+
_, _, err = cluster.Fleetctl(m, "unload", unitFile)
173+
if err != nil {
174+
t.Fatalf("Failed to unload unit: %v", err)
175+
}
176+
177+
// wait until the unit gets unloaded up to 15 seconds
178+
listUnitStates, err = cluster.WaitForNUnits(m, 0)
179+
if err != nil {
180+
t.Fatalf("Failed to run list-units: %v", err)
181+
}
182+
183+
// given unit name must be there in list-units
184+
if len(listUnitStates) != 0 {
185+
t.Fatalf("Expected nil unit list, got %v", listUnitStates)
186+
}
187+
188+
// loading the unit after destruction should succeed
189+
_, _, err = cluster.Fleetctl(m, "load", unitFile)
190+
if err != nil {
191+
t.Fatalf("Unable to load fleet unit: %v", err)
192+
}
193+
194+
// wait until the unit gets loaded up to 15 seconds
195+
listUnitStates, err = cluster.WaitForNUnits(m, 1)
196+
if err != nil {
197+
t.Fatalf("Failed to run list-units: %v", err)
198+
}
199+
200+
// given unit name must be there in list-units
201+
_, found = listUnitStates[path.Base(unitFile)]
202+
if len(listUnitStates) != 1 || !found {
203+
t.Fatalf("Expected %s to be unit, got %v", path.Base(unitFile), listUnitStates)
204+
}
205+
}
206+
132207
func TestUnitRestart(t *testing.T) {
133208
cluster, err := platform.NewNspawnCluster("smoke")
134209
if err != nil {

0 commit comments

Comments
 (0)