Keith Byrne | c1afb43 | 2015-09-10 13:43:12 +0100 | [diff] [blame] | 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 | } |