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

Commit

Permalink
functional: a new test TestUnitLoad to check fleetctl {load,unload}
Browse files Browse the repository at this point in the history
A new test TestUnitLoad verifies that "fleetctl {load,unload}"
correctly works: load -> list-units -> unload -> list-units -> load
  • Loading branch information
Dongsu Park committed Apr 14, 2016
1 parent 64863ee commit 7bcdb51
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions functional/unit_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,81 @@ func TestUnitSubmit(t *testing.T) {
}
}

// TestUnitLoad checks if a unit becomes loaded and unloaded successfully.
// First it load a unit, and unloads the unit, verifies it's unloaded,
// finally loads the unit again.
func TestUnitLoad(t *testing.T) {
cluster, err := platform.NewNspawnCluster("smoke")
if err != nil {
t.Fatal(err)
}
defer cluster.Destroy()

m, err := cluster.CreateMember()
if err != nil {
t.Fatal(err)
}
_, err = cluster.WaitForNMachines(m, 1)
if err != nil {
t.Fatal(err)
}

unitFile := "fixtures/units/hello.service"

// load a unit and assert it shows up
_, _, err = cluster.Fleetctl(m, "load", unitFile)
if err != nil {
t.Fatalf("Unable to load fleet unit: %v", err)
}

// wait until the unit gets loaded up to 15 seconds
listUnitStates, err := cluster.WaitForNUnits(m, 1)
if err != nil {
t.Fatalf("Failed to run list-units: %v", err)
}

// given unit name must be there in list-units
_, found := listUnitStates[path.Base(unitFile)]
if len(listUnitStates) != 1 || !found {
t.Fatalf("Expected %s to be unit, got %v", path.Base(unitFile), listUnitStates)
}

// unload the unit and ensure it disappears from the unit list
_, _, err = cluster.Fleetctl(m, "unload", unitFile)
if err != nil {
t.Fatalf("Failed to unload unit: %v", err)
}

// wait until the unit gets unloaded up to 15 seconds
listUnitStates, err = cluster.WaitForNUnits(m, 0)
if err != nil {
t.Fatalf("Failed to run list-units: %v", err)
}

// given unit name must be there in list-units
if len(listUnitStates) != 0 {
t.Fatalf("Expected nil unit list, got %v", listUnitStates)
}

// loading the unit after destruction should succeed
_, _, err = cluster.Fleetctl(m, "load", unitFile)
if err != nil {
t.Fatalf("Unable to load fleet unit: %v", err)
}

// wait until the unit gets loaded up to 15 seconds
listUnitStates, err = cluster.WaitForNUnits(m, 1)
if err != nil {
t.Fatalf("Failed to run list-units: %v", err)
}

// given unit name must be there in list-units
_, found = listUnitStates[path.Base(unitFile)]
if len(listUnitStates) != 1 || !found {
t.Fatalf("Expected %s to be unit, got %v", path.Base(unitFile), listUnitStates)
}
}

func TestUnitRestart(t *testing.T) {
cluster, err := platform.NewNspawnCluster("smoke")
if err != nil {
Expand Down

0 comments on commit 7bcdb51

Please sign in to comment.