Skip to content

Commit

Permalink
functional: add a new test TestUnitStartReplace
Browse files Browse the repository at this point in the history
TestUnitStartReplace() tests whether a command "fleetctl start
--replace hello.service" works or not.
  • Loading branch information
Dongsu Park committed Mar 15, 2016
1 parent 991875c commit 91fc9da
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions functional/unit_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,82 @@ func TestUnitLoadReplace(t *testing.T) {
}
}

// TestUnitStartReplace() tests whether a command "fleetctl start --replace
// hello.service" works or not.
func TestUnitStartReplace(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)
}

// start a unit and assert it shows up
if _, _, err := cluster.Fleetctl(m, "start", fxtHelloService); err != nil {
t.Fatalf("Unable to start fleet unit: %v", err)
}
stdout, _, err := cluster.Fleetctl(m, "list-units", "--no-legend")
if err != nil {
t.Fatalf("Failed to run list-units: %v", err)
}
units := strings.Split(strings.TrimSpace(stdout), "\n")
if len(units) != 1 {
t.Fatalf("Did not find 1 unit in cluster: \n%s", stdout)
}

// replace the unit and assert it shows up
if _, _, err := cluster.Fleetctl(m, "start", fxtHelloService); err != nil {
t.Fatalf("Unable to start fleet unit: %v", err)
}
err = genNewFleetService(tmpHelloService, fxtHelloService, "sleep 2", "sleep 1")
if err != nil {
t.Fatalf("Failed to generate a temp fleet service: %v", err)
}
if _, _, err := cluster.Fleetctl(m, "start", "--replace", tmpHelloService); err != nil {
t.Fatalf("Unable to replace fleet unit: %v", err)
}
stdout, _, err = cluster.Fleetctl(m, "list-units", "--no-legend")
if err != nil {
t.Fatalf("Failed to run list-units: %v", err)
}
units = strings.Split(strings.TrimSpace(stdout), "\n")
if len(units) != 1 {
t.Fatalf("Did not find 1 unit in cluster: \n%s", stdout)
}
os.Remove(tmpHelloService)

// destroy the unit and ensure it disappears from the unit list.
// It could take a little time until the unit gets destroyed.
maxAttempts := 3
for {
if _, _, err := cluster.Fleetctl(m, "destroy", fxtHelloService); err != nil {
t.Fatalf("Failed to destroy unit: %v", err)
}
_, err = cluster.WaitForNActiveUnits(m, 0)
if err == nil {
break
} else {
maxAttempts--
}
}

stdout, _, err = cluster.Fleetctl(m, "list-units", "--no-legend")
if err != nil {
t.Fatalf("Failed to run list-units: %v", err)
}
if strings.TrimSpace(stdout) != "" {
t.Fatalf("Did not find 0 units in cluster: \n%s", stdout)
}
}

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

0 comments on commit 91fc9da

Please sign in to comment.