From 419fd8d930ebba63a3ef38eac32114fd4694108f Mon Sep 17 00:00:00 2001 From: Leoswaldo Macias Date: Tue, 2 Aug 2016 18:07:13 -0500 Subject: [PATCH] ciao-controller: add negative testcase for invalid tenantServersAction 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 --- ciao-controller/compute_test.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ciao-controller/compute_test.go b/ciao-controller/compute_test.go index 87ab46903..8d3328dac 100644 --- a/ciao-controller/compute_test.go +++ b/ciao-controller/compute_test.go @@ -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) @@ -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, } @@ -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) {