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

Commit

Permalink
ciao-controller: add negative testcase for invalid tenantServersAction
Browse files Browse the repository at this point in the history
The function tenantServersAction has multiple scenarios (os-start,
os-stop, os-delete) for multiple actions, but also verifies the
requested action is valid, if not fail, this commit contains the required
changes to to verify that, if the action is not valid, then verify it.
To make this, we created the template testServersActionStop which receives
two extra parameters, the expected http status and the action to perform

In order to align the new code we had to made the TestServersActionStop
to call it with the action  "os-start" and its corresponding http status,
and then we added a new test cases, TestServersActionStopWrongAction,
which sends an invalid action, "wrong-action", with the correspoding http
status (StatusServiceUnavailable).

Fixes #349

Signed-off-by: Leoswaldo Macias <[email protected]>
  • Loading branch information
Leoswaldo Macias committed Aug 2, 2016
1 parent a00d0cc commit 419fd8d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions ciao-controller/compute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ func TestServersActionStartInvalidToken(t *testing.T) {
testServersActionStart(t, http.StatusUnauthorized, false)
}

func TestServersActionStop(t *testing.T) {
func testServersActionStop(t *testing.T, httpExpectedStatus int, action string) {
tenant, err := context.ds.GetTenant(testutil.ComputeUser)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -414,7 +414,7 @@ func TestServersActionStop(t *testing.T) {
ids = append(ids, servers.Servers[0].ID)

cmd := payloads.CiaoServersAction{
Action: "os-stop",
Action: action,
ServerIDs: ids,
}

Expand All @@ -423,7 +423,15 @@ func TestServersActionStop(t *testing.T) {
t.Fatal(err)
}

_ = testHTTPRequest(t, "POST", url, http.StatusAccepted, b, true)
_ = testHTTPRequest(t, "POST", url, httpExpectedStatus, b, true)
}

func TestServersActionStop(t *testing.T) {
testServersActionStop(t, http.StatusAccepted, "os-stop")
}

func TestServersActionStopWrongAction(t *testing.T) {
testServersActionStop(t, http.StatusServiceUnavailable, "wrong-action")
}

func testServerActionStop(t *testing.T, httpExpectedStatus int, validToken bool) {
Expand Down

0 comments on commit 419fd8d

Please sign in to comment.