Add support for deleting LBs
diff --git a/rackspace/lb/lb/fixtures.go b/rackspace/lb/lb/fixtures.go
index 5fbdee9..7cdcb0f 100644
--- a/rackspace/lb/lb/fixtures.go
+++ b/rackspace/lb/lb/fixtures.go
@@ -3,6 +3,7 @@
import (
"fmt"
"net/http"
+ "strconv"
"testing"
th "github.com/rackspace/gophercloud/testhelper"
@@ -135,10 +136,26 @@
})
}
-func mockDeleteLBResponse(t *testing.T) {
+func mockBatchDeleteLBResponse(t *testing.T, ids []int) {
th.Mux.HandleFunc("/loadbalancers", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "DELETE")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+
+ r.ParseForm()
+
+ for k, v := range ids {
+ fids := r.Form["id"]
+ th.AssertEquals(t, strconv.Itoa(v), fids[k])
+ }
+
+ w.WriteHeader(http.StatusAccepted)
+ })
+}
+
+func mockDeleteLBResponse(t *testing.T, id int) {
+ th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(id), func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "DELETE")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
w.WriteHeader(http.StatusAccepted)
})
}
diff --git a/rackspace/lb/lb/requests.go b/rackspace/lb/lb/requests.go
index e2c5a01..0be2d4a 100644
--- a/rackspace/lb/lb/requests.go
+++ b/rackspace/lb/lb/requests.go
@@ -247,3 +247,14 @@
return res
}
+
+func Delete(c *gophercloud.ServiceClient, id int) DeleteResult {
+ var res DeleteResult
+
+ _, res.Err = perigee.Request("DELETE", resourceURL(c, id), perigee.Options{
+ MoreHeaders: c.AuthenticatedHeaders(),
+ OkCodes: []int{202},
+ })
+
+ return res
+}
diff --git a/rackspace/lb/lb/requests_test.go b/rackspace/lb/lb/requests_test.go
index 2f4572f..220f11e 100644
--- a/rackspace/lb/lb/requests_test.go
+++ b/rackspace/lb/lb/requests_test.go
@@ -116,12 +116,26 @@
th.AssertDeepEquals(t, expected, lb)
}
-func TestBulkDelete(t *testing.T) {
+func TestBulkDeleteLBs(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
- mockDeleteLBResponse(t)
+ ids := []int{12345, 67890}
- err := BulkDelete(client.ServiceClient(), []int{12345, 67890}).ExtractErr()
+ mockBatchDeleteLBResponse(t, ids)
+
+ err := BulkDelete(client.ServiceClient(), ids).ExtractErr()
+ th.AssertNoErr(t, err)
+}
+
+func TestDeleteLB(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ id := 12345
+
+ mockDeleteLBResponse(t, id)
+
+ err := Delete(client.ServiceClient(), id).ExtractErr()
th.AssertNoErr(t, err)
}
diff --git a/rackspace/lb/lb/urls.go b/rackspace/lb/lb/urls.go
index a11d6b9..bf02b02 100644
--- a/rackspace/lb/lb/urls.go
+++ b/rackspace/lb/lb/urls.go
@@ -1,11 +1,15 @@
package lb
-import "github.com/rackspace/gophercloud"
+import (
+ "strconv"
+
+ "github.com/rackspace/gophercloud"
+)
const path = "loadbalancers"
-func resourceURL(c *gophercloud.ServiceClient, id string) string {
- return c.ServiceURL(path, id)
+func resourceURL(c *gophercloud.ServiceClient, id int) string {
+ return c.ServiceURL(path, strconv.Itoa(id))
}
func rootURL(c *gophercloud.ServiceClient) string {