github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/compute/v2/extensions/usage/testing/requests_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/huaweicloud/golangsdk/openstack/compute/v2/extensions/usage"
     7  	"github.com/huaweicloud/golangsdk/pagination"
     8  	th "github.com/huaweicloud/golangsdk/testhelper"
     9  	"github.com/huaweicloud/golangsdk/testhelper/client"
    10  )
    11  
    12  func TestGetTenant(t *testing.T) {
    13  	th.SetupHTTP()
    14  	defer th.TeardownHTTP()
    15  	HandleGetSingleTenantSuccessfully(t)
    16  
    17  	count := 0
    18  	err := usage.SingleTenant(client.ServiceClient(), FirstTenantID, nil).EachPage(func(page pagination.Page) (bool, error) {
    19  		count++
    20  
    21  		actual, err := usage.ExtractSingleTenant(page)
    22  		th.AssertNoErr(t, err)
    23  		th.AssertDeepEquals(t, &SingleTenantUsageResults, actual)
    24  
    25  		return true, nil
    26  	})
    27  	th.AssertNoErr(t, err)
    28  	th.AssertEquals(t, count, 1)
    29  }
    30  
    31  func TestAllTenants(t *testing.T) {
    32  	th.SetupHTTP()
    33  	defer th.TeardownHTTP()
    34  	HandleGetAllTenantsSuccessfully(t)
    35  
    36  	getOpts := usage.AllTenantsOpts{
    37  		Detailed: true,
    38  	}
    39  
    40  	count := 0
    41  	err := usage.AllTenants(client.ServiceClient(), getOpts).EachPage(func(page pagination.Page) (bool, error) {
    42  		count++
    43  
    44  		actual, err := usage.ExtractAllTenants(page)
    45  		th.AssertNoErr(t, err)
    46  		th.AssertDeepEquals(t, AllTenantsUsageResult, actual)
    47  
    48  		return true, nil
    49  	})
    50  	th.AssertNoErr(t, err)
    51  	th.AssertEquals(t, count, 1)
    52  }