github.com/gophercloud/gophercloud@v1.11.0/internal/acceptance/openstack/baremetal/httpbasic/allocations_test.go (about)

     1  //go:build acceptance || baremetal || allocations
     2  // +build acceptance baremetal allocations
     3  
     4  package httpbasic
     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  	clients.RequireIronicHTTPBasic(t)
    19  
    20  	client, err := clients.NewBareMetalV1HTTPBasic()
    21  	th.AssertNoErr(t, err)
    22  
    23  	client.Microversion = "1.52"
    24  
    25  	allocation, err := v1.CreateAllocation(t, client)
    26  	th.AssertNoErr(t, err)
    27  	defer v1.DeleteAllocation(t, client, allocation)
    28  
    29  	found := false
    30  	err = allocations.List(client, allocations.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
    31  		allocationList, err := allocations.ExtractAllocations(page)
    32  		if err != nil {
    33  			return false, err
    34  		}
    35  
    36  		for _, a := range allocationList {
    37  			if a.UUID == allocation.UUID {
    38  				found = true
    39  				return true, nil
    40  			}
    41  		}
    42  
    43  		return false, nil
    44  	})
    45  	th.AssertNoErr(t, err)
    46  	th.AssertEquals(t, found, true)
    47  }