github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/subnets/testing/results_test.go (about) 1 package testing 2 3 import ( 4 "encoding/json" 5 "testing" 6 7 "github.com/huaweicloud/golangsdk" 8 "github.com/huaweicloud/golangsdk/openstack/networking/v2/subnets" 9 th "github.com/huaweicloud/golangsdk/testhelper" 10 ) 11 12 func TestHostRoute(t *testing.T) { 13 sejson := []byte(` 14 {"subnet": { 15 "name": "test-subnet", 16 "enable_dhcp": false, 17 "network_id": "3e66c41e-cbbd-4019-9aab-740b7e4150a0", 18 "tenant_id": "f86e123198cf42d19c8854c5f80c2f06", 19 "dns_nameservers": [], 20 "gateway_ip": "172.16.0.1", 21 "ipv6_ra_mode": null, 22 "allocation_pools": [ 23 { 24 "start": "172.16.0.2", 25 "end": "172.16.255.254" 26 } 27 ], 28 "host_routes": [ 29 { 30 "destination": "172.20.1.0/24", 31 "nexthop": "172.16.0.2" 32 } 33 ], 34 "ip_version": 4, 35 "ipv6_address_mode": null, 36 "cidr": "172.16.0.0/16", 37 "id": "6dcaa873-7115-41af-9ef5-915f73636e43", 38 "subnetpool_id": null 39 }} 40 `) 41 42 var dejson interface{} 43 err := json.Unmarshal(sejson, &dejson) 44 if err != nil { 45 t.Fatalf("%s", err) 46 } 47 48 resp := golangsdk.Result{Body: dejson} 49 var subnetWrapper struct { 50 Subnet subnets.Subnet `json:"subnet"` 51 } 52 err = resp.ExtractInto(&subnetWrapper) 53 if err != nil { 54 t.Fatalf("%s", err) 55 } 56 route := subnetWrapper.Subnet.HostRoutes[0] 57 th.AssertEquals(t, route.NextHop, "172.16.0.2") 58 th.AssertEquals(t, route.DestinationCIDR, "172.20.1.0/24") 59 }