1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
//go:build acceptance || networking || layer3 || addressscopes
// +build acceptance networking layer3 addressscopes
package layer3
import (
"testing"
"github.com/gophercloud/gophercloud/acceptance/clients"
"github.com/gophercloud/gophercloud/acceptance/tools"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/addressscopes"
th "github.com/gophercloud/gophercloud/testhelper"
)
func TestAddressScopesCRUD(t *testing.T) {
client, err := clients.NewNetworkV2Client()
th.AssertNoErr(t, err)
// Create an address-scope
addressScope, err := CreateAddressScope(t, client)
th.AssertNoErr(t, err)
defer DeleteAddressScope(t, client, addressScope.ID)
tools.PrintResource(t, addressScope)
newName := tools.RandomString("TESTACC-", 8)
updateOpts := &addressscopes.UpdateOpts{
Name: &newName,
}
_, err = addressscopes.Update(client, addressScope.ID, updateOpts).Extract()
th.AssertNoErr(t, err)
newAddressScope, err := addressscopes.Get(client, addressScope.ID).Extract()
th.AssertNoErr(t, err)
tools.PrintResource(t, newAddressScope)
th.AssertEquals(t, newAddressScope.Name, newName)
allPages, err := addressscopes.List(client, nil).AllPages()
th.AssertNoErr(t, err)
allAddressScopes, err := addressscopes.ExtractAddressScopes(allPages)
th.AssertNoErr(t, err)
var found bool
for _, addressScope := range allAddressScopes {
if addressScope.ID == newAddressScope.ID {
found = true
}
}
th.AssertEquals(t, found, true)
}
|