Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 075bf42

Browse files
committed
Merge pull request #479 from timbyr/master
[rfr] Added mapstructure tags for HostRoute parsing
2 parents 53c3b4c + c1afb43 commit 075bf42

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

openstack/networking/v2/subnets/results.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ type AllocationPool struct {
5555
// HostRoute represents a route that should be used by devices with IPs from
5656
// a subnet (not including local subnet route).
5757
type HostRoute struct {
58-
DestinationCIDR string `json:"destination"`
59-
NextHop string `json:"nexthop"`
58+
DestinationCIDR string `mapstructure:"destination" json:"destination"`
59+
NextHop string `mapstructure:"nexthop" json:"nexthop"`
6060
}
6161

6262
// Subnet represents a subnet. See package documentation for a top-level
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package subnets
2+
3+
import (
4+
"encoding/json"
5+
"github.com/rackspace/gophercloud"
6+
th "github.com/rackspace/gophercloud/testhelper"
7+
"testing"
8+
)
9+
10+
func TestHostRoute(t *testing.T) {
11+
sejson := []byte(`
12+
{"subnet": {
13+
"name": "test-subnet",
14+
"enable_dhcp": false,
15+
"network_id": "3e66c41e-cbbd-4019-9aab-740b7e4150a0",
16+
"tenant_id": "f86e123198cf42d19c8854c5f80c2f06",
17+
"dns_nameservers": [],
18+
"gateway_ip": "172.16.0.1",
19+
"ipv6_ra_mode": null,
20+
"allocation_pools": [
21+
{
22+
"start": "172.16.0.2",
23+
"end": "172.16.255.254"
24+
}
25+
],
26+
"host_routes": [
27+
{
28+
"destination": "172.20.1.0/24",
29+
"nexthop": "172.16.0.2"
30+
}
31+
],
32+
"ip_version": 4,
33+
"ipv6_address_mode": null,
34+
"cidr": "172.16.0.0/16",
35+
"id": "6dcaa873-7115-41af-9ef5-915f73636e43",
36+
"subnetpool_id": null
37+
}}
38+
`)
39+
40+
var dejson interface{}
41+
err := json.Unmarshal(sejson, &dejson)
42+
if err != nil {
43+
t.Fatalf("%s", err)
44+
}
45+
46+
resp := commonResult{gophercloud.Result{Body: dejson}}
47+
subnet, err := resp.Extract()
48+
if err != nil {
49+
t.Fatalf("%s", err)
50+
}
51+
route := subnet.HostRoutes[0]
52+
th.AssertEquals(t, route.NextHop, "172.16.0.2")
53+
th.AssertEquals(t, route.DestinationCIDR, "172.20.1.0/24")
54+
}

0 commit comments

Comments
 (0)