Handle Unmarshaling Compute Security Group IDs (#192)
* Handling integer secgroup IDs
* Handling integer secgroup rule IDs
* Updating unit tests for integer secgroup IDs and rule IDs
* Style updates
* Style updates
* Test formatting fix
diff --git a/openstack/compute/v2/extensions/secgroups/testing/fixtures.go b/openstack/compute/v2/extensions/secgroups/testing/fixtures.go
index 8a83ca8..536e7f8 100644
--- a/openstack/compute/v2/extensions/secgroups/testing/fixtures.go
+++ b/openstack/compute/v2/extensions/secgroups/testing/fixtures.go
@@ -163,10 +163,35 @@
fmt.Fprintf(w, `
{
"security_group": {
- "id": "12345"
+ "id": %d
}
}
- `)
+ `, groupID)
+ })
+}
+
+func mockGetNumericIDGroupRuleResponse(t *testing.T, groupID int) {
+ url := fmt.Sprintf("%s/%d", rootPath, groupID)
+ th.Mux.HandleFunc(url, func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "GET")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+
+ w.Header().Add("Content-Type", "application/json")
+ w.WriteHeader(http.StatusOK)
+
+ fmt.Fprintf(w, `
+{
+ "security_group": {
+ "id": %d,
+ "rules": [
+ {
+ "parent_group_id": %d,
+ "id": %d
+ }
+ ]
+ }
+}
+ `, groupID, groupID, groupID)
})
}
diff --git a/openstack/compute/v2/extensions/secgroups/testing/requests_test.go b/openstack/compute/v2/extensions/secgroups/testing/requests_test.go
index b7ffa20..b520764 100644
--- a/openstack/compute/v2/extensions/secgroups/testing/requests_test.go
+++ b/openstack/compute/v2/extensions/secgroups/testing/requests_test.go
@@ -178,6 +178,29 @@
th.AssertDeepEquals(t, expected, group)
}
+func TestGetNumericRuleID(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ numericGroupID := 12345
+
+ mockGetNumericIDGroupRuleResponse(t, numericGroupID)
+
+ group, err := secgroups.Get(client.ServiceClient(), "12345").Extract()
+ th.AssertNoErr(t, err)
+
+ expected := &secgroups.SecurityGroup{
+ ID: "12345",
+ Rules: []secgroups.Rule{
+ {
+ ParentGroupID: "12345",
+ ID: "12345",
+ },
+ },
+ }
+ th.AssertDeepEquals(t, expected, group)
+}
+
func TestDelete(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()