github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/subnets/testing/requests_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  
     8  	fake "github.com/huaweicloud/golangsdk/openstack/networking/v2/common"
     9  	"github.com/huaweicloud/golangsdk/openstack/networking/v2/subnets"
    10  	"github.com/huaweicloud/golangsdk/pagination"
    11  	th "github.com/huaweicloud/golangsdk/testhelper"
    12  )
    13  
    14  func TestList(t *testing.T) {
    15  	th.SetupHTTP()
    16  	defer th.TeardownHTTP()
    17  
    18  	th.Mux.HandleFunc("/v2.0/subnets", func(w http.ResponseWriter, r *http.Request) {
    19  		th.TestMethod(t, r, "GET")
    20  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
    21  
    22  		w.Header().Add("Content-Type", "application/json")
    23  		w.WriteHeader(http.StatusOK)
    24  
    25  		fmt.Fprintf(w, SubnetListResult)
    26  	})
    27  
    28  	count := 0
    29  
    30  	subnets.List(fake.ServiceClient(), subnets.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
    31  		count++
    32  		actual, err := subnets.ExtractSubnets(page)
    33  		if err != nil {
    34  			t.Errorf("Failed to extract subnets: %v", err)
    35  			return false, nil
    36  		}
    37  
    38  		expected := []subnets.Subnet{
    39  			Subnet1,
    40  			Subnet2,
    41  			Subnet3,
    42  			Subnet4,
    43  		}
    44  
    45  		th.CheckDeepEquals(t, expected, actual)
    46  
    47  		return true, nil
    48  	})
    49  
    50  	if count != 1 {
    51  		t.Errorf("Expected 1 page, got %d", count)
    52  	}
    53  }
    54  
    55  func TestGet(t *testing.T) {
    56  	th.SetupHTTP()
    57  	defer th.TeardownHTTP()
    58  
    59  	th.Mux.HandleFunc("/v2.0/subnets/54d6f61d-db07-451c-9ab3-b9609b6b6f0b", func(w http.ResponseWriter, r *http.Request) {
    60  		th.TestMethod(t, r, "GET")
    61  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
    62  
    63  		w.Header().Add("Content-Type", "application/json")
    64  		w.WriteHeader(http.StatusOK)
    65  
    66  		fmt.Fprintf(w, SubnetGetResult)
    67  	})
    68  
    69  	s, err := subnets.Get(fake.ServiceClient(), "54d6f61d-db07-451c-9ab3-b9609b6b6f0b").Extract()
    70  	th.AssertNoErr(t, err)
    71  
    72  	th.AssertEquals(t, s.Name, "my_subnet")
    73  	th.AssertEquals(t, s.EnableDHCP, true)
    74  	th.AssertEquals(t, s.NetworkID, "d32019d3-bc6e-4319-9c1d-6722fc136a22")
    75  	th.AssertEquals(t, s.TenantID, "4fd44f30292945e481c7b8a0c8908869")
    76  	th.AssertDeepEquals(t, s.DNSNameservers, []string{})
    77  	th.AssertDeepEquals(t, s.AllocationPools, []subnets.AllocationPool{
    78  		{
    79  			Start: "192.0.0.2",
    80  			End:   "192.255.255.254",
    81  		},
    82  	})
    83  	th.AssertDeepEquals(t, s.HostRoutes, []subnets.HostRoute{})
    84  	th.AssertEquals(t, s.IPVersion, 4)
    85  	th.AssertEquals(t, s.GatewayIP, "192.0.0.1")
    86  	th.AssertEquals(t, s.CIDR, "192.0.0.0/8")
    87  	th.AssertEquals(t, s.ID, "54d6f61d-db07-451c-9ab3-b9609b6b6f0b")
    88  	th.AssertEquals(t, s.SubnetPoolID, "b80340c7-9960-4f67-a99c-02501656284b")
    89  }
    90  
    91  func TestCreate(t *testing.T) {
    92  	th.SetupHTTP()
    93  	defer th.TeardownHTTP()
    94  
    95  	th.Mux.HandleFunc("/v2.0/subnets", func(w http.ResponseWriter, r *http.Request) {
    96  		th.TestMethod(t, r, "POST")
    97  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
    98  		th.TestHeader(t, r, "Content-Type", "application/json")
    99  		th.TestHeader(t, r, "Accept", "application/json")
   100  		th.TestJSONRequest(t, r, SubnetCreateRequest)
   101  
   102  		w.Header().Add("Content-Type", "application/json")
   103  		w.WriteHeader(http.StatusCreated)
   104  
   105  		fmt.Fprintf(w, SubnetCreateResult)
   106  	})
   107  
   108  	var gatewayIP = "192.168.199.1"
   109  	opts := subnets.CreateOpts{
   110  		NetworkID: "d32019d3-bc6e-4319-9c1d-6722fc136a22",
   111  		IPVersion: 4,
   112  		CIDR:      "192.168.199.0/24",
   113  		GatewayIP: &gatewayIP,
   114  		AllocationPools: []subnets.AllocationPool{
   115  			{
   116  				Start: "192.168.199.2",
   117  				End:   "192.168.199.254",
   118  			},
   119  		},
   120  		DNSNameservers: []string{"foo"},
   121  		HostRoutes: []subnets.HostRoute{
   122  			{NextHop: "bar"},
   123  		},
   124  		SubnetPoolID: "b80340c7-9960-4f67-a99c-02501656284b",
   125  	}
   126  	s, err := subnets.Create(fake.ServiceClient(), opts).Extract()
   127  	th.AssertNoErr(t, err)
   128  
   129  	th.AssertEquals(t, s.Name, "")
   130  	th.AssertEquals(t, s.EnableDHCP, true)
   131  	th.AssertEquals(t, s.NetworkID, "d32019d3-bc6e-4319-9c1d-6722fc136a22")
   132  	th.AssertEquals(t, s.TenantID, "4fd44f30292945e481c7b8a0c8908869")
   133  	th.AssertDeepEquals(t, s.DNSNameservers, []string{})
   134  	th.AssertDeepEquals(t, s.AllocationPools, []subnets.AllocationPool{
   135  		{
   136  			Start: "192.168.199.2",
   137  			End:   "192.168.199.254",
   138  		},
   139  	})
   140  	th.AssertDeepEquals(t, s.HostRoutes, []subnets.HostRoute{})
   141  	th.AssertEquals(t, s.IPVersion, 4)
   142  	th.AssertEquals(t, s.GatewayIP, "192.168.199.1")
   143  	th.AssertEquals(t, s.CIDR, "192.168.199.0/24")
   144  	th.AssertEquals(t, s.ID, "3b80198d-4f7b-4f77-9ef5-774d54e17126")
   145  	th.AssertEquals(t, s.SubnetPoolID, "b80340c7-9960-4f67-a99c-02501656284b")
   146  }
   147  
   148  func TestCreateNoGateway(t *testing.T) {
   149  	th.SetupHTTP()
   150  	defer th.TeardownHTTP()
   151  
   152  	th.Mux.HandleFunc("/v2.0/subnets", func(w http.ResponseWriter, r *http.Request) {
   153  		th.TestMethod(t, r, "POST")
   154  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   155  		th.TestHeader(t, r, "Content-Type", "application/json")
   156  		th.TestHeader(t, r, "Accept", "application/json")
   157  		th.TestJSONRequest(t, r, SubnetCreateWithNoGatewayRequest)
   158  
   159  		w.Header().Add("Content-Type", "application/json")
   160  		w.WriteHeader(http.StatusCreated)
   161  
   162  		fmt.Fprintf(w, SubnetCreateWithNoGatewayResponse)
   163  	})
   164  
   165  	var noGateway = ""
   166  	opts := subnets.CreateOpts{
   167  		NetworkID: "d32019d3-bc6e-4319-9c1d-6722fc136a23",
   168  		IPVersion: 4,
   169  		CIDR:      "192.168.1.0/24",
   170  		GatewayIP: &noGateway,
   171  		AllocationPools: []subnets.AllocationPool{
   172  			{
   173  				Start: "192.168.1.2",
   174  				End:   "192.168.1.254",
   175  			},
   176  		},
   177  		DNSNameservers: []string{},
   178  	}
   179  	s, err := subnets.Create(fake.ServiceClient(), opts).Extract()
   180  	th.AssertNoErr(t, err)
   181  
   182  	th.AssertEquals(t, s.Name, "")
   183  	th.AssertEquals(t, s.EnableDHCP, true)
   184  	th.AssertEquals(t, s.NetworkID, "d32019d3-bc6e-4319-9c1d-6722fc136a23")
   185  	th.AssertEquals(t, s.TenantID, "4fd44f30292945e481c7b8a0c8908869")
   186  	th.AssertDeepEquals(t, s.AllocationPools, []subnets.AllocationPool{
   187  		{
   188  			Start: "192.168.1.2",
   189  			End:   "192.168.1.254",
   190  		},
   191  	})
   192  	th.AssertDeepEquals(t, s.HostRoutes, []subnets.HostRoute{})
   193  	th.AssertEquals(t, s.IPVersion, 4)
   194  	th.AssertEquals(t, s.GatewayIP, "")
   195  	th.AssertEquals(t, s.CIDR, "192.168.1.0/24")
   196  	th.AssertEquals(t, s.ID, "54d6f61d-db07-451c-9ab3-b9609b6b6f0c")
   197  }
   198  
   199  func TestCreateDefaultGateway(t *testing.T) {
   200  	th.SetupHTTP()
   201  	defer th.TeardownHTTP()
   202  
   203  	th.Mux.HandleFunc("/v2.0/subnets", func(w http.ResponseWriter, r *http.Request) {
   204  		th.TestMethod(t, r, "POST")
   205  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   206  		th.TestHeader(t, r, "Content-Type", "application/json")
   207  		th.TestHeader(t, r, "Accept", "application/json")
   208  		th.TestJSONRequest(t, r, SubnetCreateWithDefaultGatewayRequest)
   209  
   210  		w.Header().Add("Content-Type", "application/json")
   211  		w.WriteHeader(http.StatusCreated)
   212  
   213  		fmt.Fprintf(w, SubnetCreateWithDefaultGatewayResponse)
   214  	})
   215  
   216  	opts := subnets.CreateOpts{
   217  		NetworkID: "d32019d3-bc6e-4319-9c1d-6722fc136a23",
   218  		IPVersion: 4,
   219  		CIDR:      "192.168.1.0/24",
   220  		AllocationPools: []subnets.AllocationPool{
   221  			{
   222  				Start: "192.168.1.2",
   223  				End:   "192.168.1.254",
   224  			},
   225  		},
   226  		DNSNameservers: []string{},
   227  	}
   228  	s, err := subnets.Create(fake.ServiceClient(), opts).Extract()
   229  	th.AssertNoErr(t, err)
   230  
   231  	th.AssertEquals(t, s.Name, "")
   232  	th.AssertEquals(t, s.EnableDHCP, true)
   233  	th.AssertEquals(t, s.NetworkID, "d32019d3-bc6e-4319-9c1d-6722fc136a23")
   234  	th.AssertEquals(t, s.TenantID, "4fd44f30292945e481c7b8a0c8908869")
   235  	th.AssertDeepEquals(t, s.AllocationPools, []subnets.AllocationPool{
   236  		{
   237  			Start: "192.168.1.2",
   238  			End:   "192.168.1.254",
   239  		},
   240  	})
   241  	th.AssertDeepEquals(t, s.HostRoutes, []subnets.HostRoute{})
   242  	th.AssertEquals(t, s.IPVersion, 4)
   243  	th.AssertEquals(t, s.GatewayIP, "192.168.1.1")
   244  	th.AssertEquals(t, s.CIDR, "192.168.1.0/24")
   245  	th.AssertEquals(t, s.ID, "54d6f61d-db07-451c-9ab3-b9609b6b6f0c")
   246  }
   247  
   248  func TestCreateIPv6RaAddressMode(t *testing.T) {
   249  	th.SetupHTTP()
   250  	defer th.TeardownHTTP()
   251  
   252  	th.Mux.HandleFunc("/v2.0/subnets", func(w http.ResponseWriter, r *http.Request) {
   253  		th.TestMethod(t, r, "POST")
   254  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   255  		th.TestHeader(t, r, "Content-Type", "application/json")
   256  		th.TestHeader(t, r, "Accept", "application/json")
   257  		th.TestJSONRequest(t, r, SubnetCreateWithIPv6RaAddressModeRequest)
   258  
   259  		w.Header().Add("Content-Type", "application/json")
   260  		w.WriteHeader(http.StatusCreated)
   261  
   262  		fmt.Fprintf(w, SubnetCreateWithIPv6RaAddressModeResponse)
   263  	})
   264  
   265  	var gatewayIP = "2001:db8:0:a::1"
   266  	opts := subnets.CreateOpts{
   267  		NetworkID:       "d32019d3-bc6e-4319-9c1d-6722fc136a22",
   268  		IPVersion:       6,
   269  		CIDR:            "2001:db8:0:a:0:0:0:0/64",
   270  		GatewayIP:       &gatewayIP,
   271  		IPv6AddressMode: "slaac",
   272  		IPv6RAMode:      "slaac",
   273  	}
   274  	s, err := subnets.Create(fake.ServiceClient(), opts).Extract()
   275  	th.AssertNoErr(t, err)
   276  
   277  	th.AssertEquals(t, s.Name, "")
   278  	th.AssertEquals(t, s.EnableDHCP, true)
   279  	th.AssertEquals(t, s.NetworkID, "d32019d3-bc6e-4319-9c1d-6722fc136a22")
   280  	th.AssertEquals(t, s.TenantID, "4fd44f30292945e481c7b8a0c8908869")
   281  	th.AssertEquals(t, s.IPVersion, 6)
   282  	th.AssertEquals(t, s.GatewayIP, "2001:db8:0:a::1")
   283  	th.AssertEquals(t, s.CIDR, "2001:db8:0:a:0:0:0:0/64")
   284  	th.AssertEquals(t, s.ID, "3b80198d-4f7b-4f77-9ef5-774d54e17126")
   285  	th.AssertEquals(t, s.IPv6AddressMode, "slaac")
   286  	th.AssertEquals(t, s.IPv6RAMode, "slaac")
   287  }
   288  
   289  func TestCreateWithNoCIDR(t *testing.T) {
   290  	th.SetupHTTP()
   291  	defer th.TeardownHTTP()
   292  
   293  	th.Mux.HandleFunc("/v2.0/subnets", func(w http.ResponseWriter, r *http.Request) {
   294  		th.TestMethod(t, r, "POST")
   295  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   296  		th.TestHeader(t, r, "Content-Type", "application/json")
   297  		th.TestHeader(t, r, "Accept", "application/json")
   298  		th.TestJSONRequest(t, r, SubnetCreateRequestWithNoCIDR)
   299  
   300  		w.Header().Add("Content-Type", "application/json")
   301  		w.WriteHeader(http.StatusCreated)
   302  
   303  		fmt.Fprintf(w, SubnetCreateResult)
   304  	})
   305  
   306  	opts := subnets.CreateOpts{
   307  		NetworkID:      "d32019d3-bc6e-4319-9c1d-6722fc136a22",
   308  		IPVersion:      4,
   309  		DNSNameservers: []string{"foo"},
   310  		HostRoutes: []subnets.HostRoute{
   311  			{NextHop: "bar"},
   312  		},
   313  		SubnetPoolID: "b80340c7-9960-4f67-a99c-02501656284b",
   314  	}
   315  	s, err := subnets.Create(fake.ServiceClient(), opts).Extract()
   316  	th.AssertNoErr(t, err)
   317  
   318  	th.AssertEquals(t, s.Name, "")
   319  	th.AssertEquals(t, s.EnableDHCP, true)
   320  	th.AssertEquals(t, s.NetworkID, "d32019d3-bc6e-4319-9c1d-6722fc136a22")
   321  	th.AssertEquals(t, s.TenantID, "4fd44f30292945e481c7b8a0c8908869")
   322  	th.AssertDeepEquals(t, s.DNSNameservers, []string{})
   323  	th.AssertDeepEquals(t, s.AllocationPools, []subnets.AllocationPool{
   324  		{
   325  			Start: "192.168.199.2",
   326  			End:   "192.168.199.254",
   327  		},
   328  	})
   329  	th.AssertDeepEquals(t, s.HostRoutes, []subnets.HostRoute{})
   330  	th.AssertEquals(t, s.IPVersion, 4)
   331  	th.AssertEquals(t, s.GatewayIP, "192.168.199.1")
   332  	th.AssertEquals(t, s.CIDR, "192.168.199.0/24")
   333  	th.AssertEquals(t, s.ID, "3b80198d-4f7b-4f77-9ef5-774d54e17126")
   334  	th.AssertEquals(t, s.SubnetPoolID, "b80340c7-9960-4f67-a99c-02501656284b")
   335  }
   336  
   337  func TestRequiredCreateOpts(t *testing.T) {
   338  	res := subnets.Create(fake.ServiceClient(), subnets.CreateOpts{})
   339  	if res.Err == nil {
   340  		t.Fatalf("Expected error, got none")
   341  	}
   342  
   343  	res = subnets.Create(fake.ServiceClient(), subnets.CreateOpts{NetworkID: "foo"})
   344  	if res.Err == nil {
   345  		t.Fatalf("Expected error, got none")
   346  	}
   347  
   348  	res = subnets.Create(fake.ServiceClient(), subnets.CreateOpts{NetworkID: "foo", CIDR: "bar", IPVersion: 40})
   349  	if res.Err == nil {
   350  		t.Fatalf("Expected error, got none")
   351  	}
   352  }
   353  
   354  func TestUpdate(t *testing.T) {
   355  	th.SetupHTTP()
   356  	defer th.TeardownHTTP()
   357  
   358  	th.Mux.HandleFunc("/v2.0/subnets/08eae331-0402-425a-923c-34f7cfe39c1b", func(w http.ResponseWriter, r *http.Request) {
   359  		th.TestMethod(t, r, "PUT")
   360  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   361  		th.TestHeader(t, r, "Content-Type", "application/json")
   362  		th.TestHeader(t, r, "Accept", "application/json")
   363  		th.TestJSONRequest(t, r, SubnetUpdateRequest)
   364  
   365  		w.Header().Add("Content-Type", "application/json")
   366  		w.WriteHeader(http.StatusCreated)
   367  
   368  		fmt.Fprintf(w, SubnetUpdateResponse)
   369  	})
   370  
   371  	opts := subnets.UpdateOpts{
   372  		Name:           "my_new_subnet",
   373  		DNSNameservers: []string{"foo"},
   374  		HostRoutes: []subnets.HostRoute{
   375  			{NextHop: "bar"},
   376  		},
   377  	}
   378  	s, err := subnets.Update(fake.ServiceClient(), "08eae331-0402-425a-923c-34f7cfe39c1b", opts).Extract()
   379  	th.AssertNoErr(t, err)
   380  
   381  	th.AssertEquals(t, s.Name, "my_new_subnet")
   382  	th.AssertEquals(t, s.ID, "08eae331-0402-425a-923c-34f7cfe39c1b")
   383  }
   384  
   385  func TestUpdateGateway(t *testing.T) {
   386  	th.SetupHTTP()
   387  	defer th.TeardownHTTP()
   388  
   389  	th.Mux.HandleFunc("/v2.0/subnets/08eae331-0402-425a-923c-34f7cfe39c1b", func(w http.ResponseWriter, r *http.Request) {
   390  		th.TestMethod(t, r, "PUT")
   391  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   392  		th.TestHeader(t, r, "Content-Type", "application/json")
   393  		th.TestHeader(t, r, "Accept", "application/json")
   394  		th.TestJSONRequest(t, r, SubnetUpdateGatewayRequest)
   395  
   396  		w.Header().Add("Content-Type", "application/json")
   397  		w.WriteHeader(http.StatusCreated)
   398  
   399  		fmt.Fprintf(w, SubnetUpdateGatewayResponse)
   400  	})
   401  
   402  	var gatewayIP = "10.0.0.1"
   403  	opts := subnets.UpdateOpts{
   404  		Name:      "my_new_subnet",
   405  		GatewayIP: &gatewayIP,
   406  	}
   407  	s, err := subnets.Update(fake.ServiceClient(), "08eae331-0402-425a-923c-34f7cfe39c1b", opts).Extract()
   408  	th.AssertNoErr(t, err)
   409  
   410  	th.AssertEquals(t, s.Name, "my_new_subnet")
   411  	th.AssertEquals(t, s.ID, "08eae331-0402-425a-923c-34f7cfe39c1b")
   412  	th.AssertEquals(t, s.GatewayIP, "10.0.0.1")
   413  }
   414  
   415  func TestUpdateRemoveGateway(t *testing.T) {
   416  	th.SetupHTTP()
   417  	defer th.TeardownHTTP()
   418  
   419  	th.Mux.HandleFunc("/v2.0/subnets/08eae331-0402-425a-923c-34f7cfe39c1b", func(w http.ResponseWriter, r *http.Request) {
   420  		th.TestMethod(t, r, "PUT")
   421  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   422  		th.TestHeader(t, r, "Content-Type", "application/json")
   423  		th.TestHeader(t, r, "Accept", "application/json")
   424  		th.TestJSONRequest(t, r, SubnetUpdateRemoveGatewayRequest)
   425  
   426  		w.Header().Add("Content-Type", "application/json")
   427  		w.WriteHeader(http.StatusCreated)
   428  
   429  		fmt.Fprintf(w, SubnetUpdateRemoveGatewayResponse)
   430  	})
   431  
   432  	var noGateway = ""
   433  	opts := subnets.UpdateOpts{
   434  		Name:      "my_new_subnet",
   435  		GatewayIP: &noGateway,
   436  	}
   437  	s, err := subnets.Update(fake.ServiceClient(), "08eae331-0402-425a-923c-34f7cfe39c1b", opts).Extract()
   438  	th.AssertNoErr(t, err)
   439  
   440  	th.AssertEquals(t, s.Name, "my_new_subnet")
   441  	th.AssertEquals(t, s.ID, "08eae331-0402-425a-923c-34f7cfe39c1b")
   442  	th.AssertEquals(t, s.GatewayIP, "")
   443  }
   444  
   445  func TestUpdateHostRoutes(t *testing.T) {
   446  	th.SetupHTTP()
   447  	defer th.TeardownHTTP()
   448  
   449  	th.Mux.HandleFunc("/v2.0/subnets/08eae331-0402-425a-923c-34f7cfe39c1b", func(w http.ResponseWriter, r *http.Request) {
   450  		th.TestMethod(t, r, "PUT")
   451  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   452  		th.TestHeader(t, r, "Content-Type", "application/json")
   453  		th.TestHeader(t, r, "Accept", "application/json")
   454  		th.TestJSONRequest(t, r, SubnetUpdateHostRoutesRequest)
   455  
   456  		w.Header().Add("Content-Type", "application/json")
   457  		w.WriteHeader(http.StatusCreated)
   458  
   459  		fmt.Fprintf(w, SubnetUpdateHostRoutesResponse)
   460  	})
   461  
   462  	HostRoutes := []subnets.HostRoute{
   463  		{
   464  			DestinationCIDR: "192.168.1.1/24",
   465  			NextHop:         "bar",
   466  		},
   467  	}
   468  
   469  	opts := subnets.UpdateOpts{
   470  		Name:       "my_new_subnet",
   471  		HostRoutes: HostRoutes,
   472  	}
   473  	s, err := subnets.Update(fake.ServiceClient(), "08eae331-0402-425a-923c-34f7cfe39c1b", opts).Extract()
   474  	th.AssertNoErr(t, err)
   475  
   476  	th.AssertEquals(t, s.Name, "my_new_subnet")
   477  	th.AssertEquals(t, s.ID, "08eae331-0402-425a-923c-34f7cfe39c1b")
   478  	th.AssertDeepEquals(t, s.HostRoutes, HostRoutes)
   479  }
   480  
   481  func TestUpdateRemoveHostRoutes(t *testing.T) {
   482  	th.SetupHTTP()
   483  	defer th.TeardownHTTP()
   484  
   485  	//	th.Mux.HandleFunc("/v2.0/subnets/08eae331-0402-425a-923c-34f7cfe39c1b", func(w http.ResponseWriter, r *http.Request) {
   486  	//		th.TestMethod(t, r, "PUT")
   487  	//		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   488  	//		th.TestHeader(t, r, "Content-Type", "application/json")
   489  	//		th.TestHeader(t, r, "Accept", "application/json")
   490  	//		th.TestJSONRequest(t, r, SubnetUpdateRemoveHostRoutesRequest)
   491  
   492  	//		w.Header().Add("Content-Type", "application/json")
   493  	//		w.WriteHeader(http.StatusCreated)
   494  
   495  	//		fmt.Fprintf(w, SubnetUpdateRemoveHostRoutesResponse)
   496  	//	})
   497  
   498  	//	noHostRoutes := []subnets.HostRoute{}
   499  	//	opts := subnets.UpdateOpts{
   500  	//		HostRoutes: noHostRoutes,
   501  	//	}
   502  	//	s, err := subnets.Update(fake.ServiceClient(), "08eae331-0402-425a-923c-34f7cfe39c1b", opts).Extract()
   503  	//	th.AssertNoErr(t, err)
   504  
   505  	//	th.AssertEquals(t, s.Name, "my_new_subnet")
   506  	//	th.AssertEquals(t, s.ID, "08eae331-0402-425a-923c-34f7cfe39c1b")
   507  	//	th.AssertDeepEquals(t, s.HostRoutes, noHostRoutes)
   508  }
   509  
   510  func TestUpdateAllocationPool(t *testing.T) {
   511  	th.SetupHTTP()
   512  	defer th.TeardownHTTP()
   513  
   514  	th.Mux.HandleFunc("/v2.0/subnets/08eae331-0402-425a-923c-34f7cfe39c1b", func(w http.ResponseWriter, r *http.Request) {
   515  		th.TestMethod(t, r, "PUT")
   516  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   517  		th.TestHeader(t, r, "Content-Type", "application/json")
   518  		th.TestHeader(t, r, "Accept", "application/json")
   519  		th.TestJSONRequest(t, r, SubnetUpdateAllocationPoolRequest)
   520  
   521  		w.Header().Add("Content-Type", "application/json")
   522  		w.WriteHeader(http.StatusCreated)
   523  
   524  		fmt.Fprintf(w, SubnetUpdateAllocationPoolResponse)
   525  	})
   526  
   527  	opts := subnets.UpdateOpts{
   528  		Name: "my_new_subnet",
   529  		AllocationPools: []subnets.AllocationPool{
   530  			{
   531  				Start: "10.1.0.2",
   532  				End:   "10.1.0.254",
   533  			},
   534  		},
   535  	}
   536  	s, err := subnets.Update(fake.ServiceClient(), "08eae331-0402-425a-923c-34f7cfe39c1b", opts).Extract()
   537  	th.AssertNoErr(t, err)
   538  
   539  	th.AssertEquals(t, s.Name, "my_new_subnet")
   540  	th.AssertEquals(t, s.ID, "08eae331-0402-425a-923c-34f7cfe39c1b")
   541  	th.AssertDeepEquals(t, s.AllocationPools, []subnets.AllocationPool{
   542  		{
   543  			Start: "10.1.0.2",
   544  			End:   "10.1.0.254",
   545  		},
   546  	})
   547  }
   548  
   549  func TestDelete(t *testing.T) {
   550  	th.SetupHTTP()
   551  	defer th.TeardownHTTP()
   552  
   553  	th.Mux.HandleFunc("/v2.0/subnets/08eae331-0402-425a-923c-34f7cfe39c1b", func(w http.ResponseWriter, r *http.Request) {
   554  		th.TestMethod(t, r, "DELETE")
   555  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   556  		w.WriteHeader(http.StatusNoContent)
   557  	})
   558  
   559  	res := subnets.Delete(fake.ServiceClient(), "08eae331-0402-425a-923c-34f7cfe39c1b")
   560  	th.AssertNoErr(t, res.Err)
   561  }