github.com/gophercloud/gophercloud@v1.11.0/internal/acceptance/openstack/networking/v2/extensions/subnetpools/subnetpools_test.go (about) 1 //go:build acceptance || networking || subnetpools 2 // +build acceptance networking subnetpools 3 4 package v2 5 6 import ( 7 "testing" 8 9 "github.com/gophercloud/gophercloud/internal/acceptance/clients" 10 "github.com/gophercloud/gophercloud/internal/acceptance/tools" 11 "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/subnetpools" 12 th "github.com/gophercloud/gophercloud/testhelper" 13 ) 14 15 func TestSubnetPoolsCRUD(t *testing.T) { 16 client, err := clients.NewNetworkV2Client() 17 th.AssertNoErr(t, err) 18 19 // Create a subnetpool 20 subnetPool, err := CreateSubnetPool(t, client) 21 th.AssertNoErr(t, err) 22 defer DeleteSubnetPool(t, client, subnetPool.ID) 23 24 tools.PrintResource(t, subnetPool) 25 26 newName := tools.RandomString("TESTACC-", 8) 27 newDescription := "" 28 updateOpts := &subnetpools.UpdateOpts{ 29 Name: newName, 30 Description: &newDescription, 31 } 32 33 _, err = subnetpools.Update(client, subnetPool.ID, updateOpts).Extract() 34 th.AssertNoErr(t, err) 35 36 newSubnetPool, err := subnetpools.Get(client, subnetPool.ID).Extract() 37 th.AssertNoErr(t, err) 38 39 tools.PrintResource(t, newSubnetPool) 40 th.AssertEquals(t, newSubnetPool.Name, newName) 41 th.AssertEquals(t, newSubnetPool.Description, newDescription) 42 43 allPages, err := subnetpools.List(client, nil).AllPages() 44 th.AssertNoErr(t, err) 45 46 allSubnetPools, err := subnetpools.ExtractSubnetPools(allPages) 47 th.AssertNoErr(t, err) 48 49 var found bool 50 for _, subnetpool := range allSubnetPools { 51 if subnetpool.ID == newSubnetPool.ID { 52 found = true 53 } 54 } 55 56 th.AssertEquals(t, found, true) 57 }