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 11, 2016
1 parent 425c4d9 commit e6ba65f
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions functional/unit_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,78 @@ 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"
inputUnits := make([]string, 0)
inputUnits = append(inputUnits, path.Base(unitFile))

// 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 unloaded up to 15 seconds
listUnits, err := runListUnits(cluster, m, 1)
if err != nil {
t.Fatalf("Failed to run list-units: %v", err)
}

// given unit name must be there in list-units
listUnitNames := util.GetListUnitNames(listUnits)
if !util.SliceContains(listUnitNames, inputUnits) {
t.Fatalf("list-units doesn't contain expected units %v", inputUnits)
}

// 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
listUnits, err = runListUnits(cluster, m, 0)
if err != nil {
t.Fatalf("Failed to run list-units: %v", err)
}

// 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 unloaded up to 15 seconds
listUnits, err = runListUnits(cluster, m, 1)
if err != nil {
t.Fatalf("Failed to run list-units: %v", err)
}

// given unit name must be there in list-units
listUnitNames = util.GetListUnitNames(listUnits)
if !util.SliceContains(listUnitNames, inputUnits) {
t.Fatalf("list-units doesn't contain expected units %v", inputUnits)
}
}

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

0 comments on commit e6ba65f

Please sign in to comment.