Don't allow autoscale webhook updates with no metadata
diff --git a/rackspace/autoscale/v1/webhooks/requests.go b/rackspace/autoscale/v1/webhooks/requests.go
index bfdb01a..2a88959 100644
--- a/rackspace/autoscale/v1/webhooks/requests.go
+++ b/rackspace/autoscale/v1/webhooks/requests.go
@@ -7,9 +7,11 @@
"github.com/rackspace/gophercloud/pagination"
)
-// ErrNoName represents a validation error in which a create or update operation
-// has an empty name field.
-var ErrNoName = errors.New("Webhook name cannot by empty.")
+// Validation errors returned by create or update operations.
+var (
+ ErrNoName = errors.New("Webhook name cannot by empty.")
+ ErrNoMetadata = errors.New("Webhook metadata cannot be nil.")
+)
// List returns all webhooks for a scaling policy.
func List(client *gophercloud.ServiceClient, groupID, policyID string) pagination.Pager {
@@ -118,13 +120,14 @@
return nil, ErrNoName
}
+ if opts.Metadata == nil {
+ return nil, ErrNoMetadata
+ }
+
hook := make(map[string]interface{})
hook["name"] = opts.Name
-
- if opts.Metadata != nil {
- hook["metadata"] = opts.Metadata
- }
+ hook["metadata"] = opts.Metadata
return hook, nil
}
diff --git a/rackspace/autoscale/v1/webhooks/requests_test.go b/rackspace/autoscale/v1/webhooks/requests_test.go
index 925c29e..950c90d 100644
--- a/rackspace/autoscale/v1/webhooks/requests_test.go
+++ b/rackspace/autoscale/v1/webhooks/requests_test.go
@@ -105,6 +105,21 @@
th.AssertNoErr(t, err)
}
+func TestUpdateNoMetadata(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleWebhookUpdateSuccessfully(t)
+
+ client := client.ServiceClient()
+ opts := UpdateOpts{
+ Name: "updated hook",
+ }
+
+ err := Update(client, groupID, policyID, firstID, opts).ExtractErr()
+
+ th.AssertEquals(t, ErrNoMetadata, err)
+}
+
func TestDelete(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()