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