Making description mandatory and other small tweaks
diff --git a/openstack/compute/v2/extensions/secgroups/fixtures.go b/openstack/compute/v2/extensions/secgroups/fixtures.go
index 7943c71..d45609c 100644
--- a/openstack/compute/v2/extensions/secgroups/fixtures.go
+++ b/openstack/compute/v2/extensions/secgroups/fixtures.go
@@ -90,7 +90,8 @@
th.TestJSONRequest(t, r, `
{
"security_group": {
- "name": "new_name"
+ "name": "new_name",
+ "description": "new_desc"
}
}
`)
diff --git a/openstack/compute/v2/extensions/secgroups/requests.go b/openstack/compute/v2/extensions/secgroups/requests.go
index 3707840..820146e 100644
--- a/openstack/compute/v2/extensions/secgroups/requests.go
+++ b/openstack/compute/v2/extensions/secgroups/requests.go
@@ -35,11 +35,11 @@
type GroupOpts struct {
// Optional - the name of your security group. If no value provided, null
// will be set.
- Name string `json:"name,omitempty"`
+ Name string `json:"name"`
// Optional - the description of your security group. If no value provided,
// null will be set.
- Description string `json:"description,omitempty"`
+ Description string `json:"description"`
}
// CreateOpts is the struct responsible for creating a security group.
@@ -50,17 +50,25 @@
ToSecGroupCreateMap() (map[string]interface{}, error)
}
+var (
+ errName = errors.New("Name is a required field")
+ errDesc = errors.New("Description is a required field")
+)
+
// ToSecGroupCreateMap builds the create options into a serializable format.
func (opts CreateOpts) ToSecGroupCreateMap() (map[string]interface{}, error) {
sg := make(map[string]interface{})
- if opts.Name != "" {
- sg["name"] = opts.Name
+ if opts.Name == "" {
+ return sg, errName
}
- if opts.Description != "" {
- sg["description"] = opts.Description
+ if opts.Description == "" {
+ return sg, errDesc
}
+ sg["name"] = opts.Name
+ sg["description"] = opts.Description
+
return map[string]interface{}{"security_group": sg}, nil
}
@@ -96,13 +104,16 @@
func (opts UpdateOpts) ToSecGroupUpdateMap() (map[string]interface{}, error) {
sg := make(map[string]interface{})
- if opts.Name != "" {
- sg["name"] = opts.Name
+ if opts.Name == "" {
+ return sg, errName
}
- if opts.Description != "" {
- sg["description"] = opts.Description
+ if opts.Description == "" {
+ return sg, errDesc
}
+ sg["name"] = opts.Name
+ sg["description"] = opts.Description
+
return map[string]interface{}{"security_group": sg}, nil
}
diff --git a/openstack/compute/v2/extensions/secgroups/requests_test.go b/openstack/compute/v2/extensions/secgroups/requests_test.go
index 1c5d22f..667db59 100644
--- a/openstack/compute/v2/extensions/secgroups/requests_test.go
+++ b/openstack/compute/v2/extensions/secgroups/requests_test.go
@@ -114,7 +114,11 @@
mockUpdateGroupResponse(t, groupID)
- opts := UpdateOpts{Name: "new_name"}
+ opts := UpdateOpts{
+ Name: "new_name",
+ Description: "new_desc",
+ }
+
group, err := Update(client.ServiceClient(), groupID, opts).Extract()
th.AssertNoErr(t, err)