Adding extra coverage to subnets
diff --git a/openstack/networking/v2/subnets/requests.go b/openstack/networking/v2/subnets/requests.go
index a9a3706..a7e6b53 100644
--- a/openstack/networking/v2/subnets/requests.go
+++ b/openstack/networking/v2/subnets/requests.go
@@ -89,7 +89,7 @@
IPVersion int
EnableDHCP *bool
DNSNameservers []string
- HostRoutes []interface{}
+ HostRoutes []HostRoute
}
// Create accepts a CreateOpts struct and creates a new subnet using the values
@@ -121,7 +121,7 @@
IPVersion int `json:"ip_version,omitempty"`
EnableDHCP *bool `json:"enable_dhcp,omitempty"`
DNSNameservers []string `json:"dns_nameservers,omitempty"`
- HostRoutes []interface{} `json:"host_routes,omitempty"`
+ HostRoutes []HostRoute `json:"host_routes,omitempty"`
}
type request struct {
Subnet subnet `json:"subnet"`
@@ -164,7 +164,7 @@
Name string
GatewayIP string
DNSNameservers []string
- HostRoutes []interface{}
+ HostRoutes []HostRoute
EnableDHCP *bool
}
@@ -172,11 +172,11 @@
// values provided.
func Update(c *gophercloud.ServiceClient, id string, opts UpdateOpts) UpdateResult {
type subnet struct {
- Name *string `json:"name,omitempty"`
- GatewayIP *string `json:"gateway_ip,omitempty"`
- DNSNameservers []string `json:"dns_nameservers,omitempty"`
- HostRoutes []interface{} `json:"host_routes,omitempty"`
- EnableDHCP *bool `json:"enable_dhcp,omitempty"`
+ Name *string `json:"name,omitempty"`
+ GatewayIP *string `json:"gateway_ip,omitempty"`
+ DNSNameservers []string `json:"dns_nameservers,omitempty"`
+ HostRoutes []HostRoute `json:"host_routes,omitempty"`
+ EnableDHCP *bool `json:"enable_dhcp,omitempty"`
}
type request struct {
Subnet subnet `json:"subnet"`
diff --git a/openstack/networking/v2/subnets/requests_test.go b/openstack/networking/v2/subnets/requests_test.go
index b49fcb9..987064a 100644
--- a/openstack/networking/v2/subnets/requests_test.go
+++ b/openstack/networking/v2/subnets/requests_test.go
@@ -194,7 +194,15 @@
"subnet": {
"network_id": "d32019d3-bc6e-4319-9c1d-6722fc136a22",
"ip_version": 4,
- "cidr": "192.168.199.0/24"
+ "cidr": "192.168.199.0/24",
+ "dns_nameservers": ["foo"],
+ "allocation_pools": [
+ {
+ "start": "192.168.199.2",
+ "end": "192.168.199.254"
+ }
+ ],
+ "host_routes": [{"destination":"","nexthop": "bar"}]
}
}
`)
@@ -226,7 +234,21 @@
`)
})
- opts := CreateOpts{NetworkID: "d32019d3-bc6e-4319-9c1d-6722fc136a22", IPVersion: 4, CIDR: "192.168.199.0/24"}
+ opts := CreateOpts{
+ NetworkID: "d32019d3-bc6e-4319-9c1d-6722fc136a22",
+ IPVersion: 4,
+ CIDR: "192.168.199.0/24",
+ AllocationPools: []AllocationPool{
+ AllocationPool{
+ Start: "192.168.199.2",
+ End: "192.168.199.254",
+ },
+ },
+ DNSNameservers: []string{"foo"},
+ HostRoutes: []HostRoute{
+ HostRoute{NextHop: "bar"},
+ },
+ }
s, err := Create(fake.ServiceClient(), opts).Extract()
th.AssertNoErr(t, err)
@@ -248,6 +270,23 @@
th.AssertEquals(t, s.ID, "3b80198d-4f7b-4f77-9ef5-774d54e17126")
}
+func TestRequiredCreateOpts(t *testing.T) {
+ res := Create(fake.ServiceClient(), CreateOpts{})
+ if res.Err == nil {
+ t.Fatalf("Expected error, got none")
+ }
+
+ res = Create(fake.ServiceClient(), CreateOpts{NetworkID: "foo"})
+ if res.Err == nil {
+ t.Fatalf("Expected error, got none")
+ }
+
+ res = Create(fake.ServiceClient(), CreateOpts{NetworkID: "foo", CIDR: "bar", IPVersion: 40})
+ if res.Err == nil {
+ t.Fatalf("Expected error, got none")
+ }
+}
+
func TestUpdate(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
@@ -260,7 +299,9 @@
th.TestJSONRequest(t, r, `
{
"subnet": {
- "name": "my_new_subnet"
+ "name": "my_new_subnet",
+ "dns_nameservers": ["foo"],
+ "host_routes": [{"destination":"","nexthop": "bar"}]
}
}
`)
@@ -292,7 +333,13 @@
`)
})
- opts := UpdateOpts{Name: "my_new_subnet"}
+ opts := UpdateOpts{
+ Name: "my_new_subnet",
+ DNSNameservers: []string{"foo"},
+ HostRoutes: []HostRoute{
+ HostRoute{NextHop: "bar"},
+ },
+ }
s, err := Update(fake.ServiceClient(), "08eae331-0402-425a-923c-34f7cfe39c1b", opts).Extract()
th.AssertNoErr(t, err)