github.com/gophercloud/gophercloud@v1.11.0/internal/acceptance/openstack/baremetal/noauth/allocations_test.go (about) 1 //go:build acceptance || baremetal || allocations 2 // +build acceptance baremetal allocations 3 4 package noauth 5 6 import ( 7 "testing" 8 9 "github.com/gophercloud/gophercloud/internal/acceptance/clients" 10 v1 "github.com/gophercloud/gophercloud/internal/acceptance/openstack/baremetal/v1" 11 "github.com/gophercloud/gophercloud/openstack/baremetal/v1/allocations" 12 "github.com/gophercloud/gophercloud/pagination" 13 th "github.com/gophercloud/gophercloud/testhelper" 14 ) 15 16 func TestAllocationsCreateDestroy(t *testing.T) { 17 clients.RequireLong(t) 18 19 client, err := clients.NewBareMetalV1NoAuthClient() 20 th.AssertNoErr(t, err) 21 22 client.Microversion = "1.52" 23 24 allocation, err := v1.CreateAllocation(t, client) 25 th.AssertNoErr(t, err) 26 defer v1.DeleteAllocation(t, client, allocation) 27 28 found := false 29 err = allocations.List(client, allocations.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { 30 allocationList, err := allocations.ExtractAllocations(page) 31 if err != nil { 32 return false, err 33 } 34 35 for _, a := range allocationList { 36 if a.UUID == allocation.UUID { 37 found = true 38 return true, nil 39 } 40 } 41 42 return false, nil 43 }) 44 th.AssertNoErr(t, err) 45 th.AssertEquals(t, found, true) 46 }