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