github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/networking/v2/subnets/testing/results_test.go (about)

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