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

     1  package testing
     2  
     3  import (
     4  	"errors"
     5  	"testing"
     6  
     7  	"github.com/huaweicloud/golangsdk"
     8  	"github.com/huaweicloud/golangsdk/openstack/compute/v2/extensions/quotasets"
     9  	th "github.com/huaweicloud/golangsdk/testhelper"
    10  	"github.com/huaweicloud/golangsdk/testhelper/client"
    11  )
    12  
    13  func TestGet(t *testing.T) {
    14  	th.SetupHTTP()
    15  	defer th.TeardownHTTP()
    16  	HandleGetSuccessfully(t)
    17  	actual, err := quotasets.Get(client.ServiceClient(), FirstTenantID).Extract()
    18  	th.AssertNoErr(t, err)
    19  	th.CheckDeepEquals(t, &FirstQuotaSet, actual)
    20  }
    21  
    22  func TestGetDetail(t *testing.T) {
    23  	th.SetupHTTP()
    24  	defer th.TeardownHTTP()
    25  	HandleGetDetailSuccessfully(t)
    26  	actual, err := quotasets.GetDetail(client.ServiceClient(), FirstTenantID).Extract()
    27  	th.CheckDeepEquals(t, FirstQuotaDetailsSet, actual)
    28  	th.AssertNoErr(t, err)
    29  }
    30  
    31  func TestUpdate(t *testing.T) {
    32  	th.SetupHTTP()
    33  	defer th.TeardownHTTP()
    34  	HandlePutSuccessfully(t)
    35  	actual, err := quotasets.Update(client.ServiceClient(), FirstTenantID, UpdatedQuotaSet).Extract()
    36  	th.AssertNoErr(t, err)
    37  	th.CheckDeepEquals(t, &FirstQuotaSet, actual)
    38  }
    39  
    40  func TestPartialUpdate(t *testing.T) {
    41  	th.SetupHTTP()
    42  	defer th.TeardownHTTP()
    43  	HandlePartialPutSuccessfully(t)
    44  	opts := quotasets.UpdateOpts{Cores: golangsdk.IntToPointer(200), Force: true}
    45  	actual, err := quotasets.Update(client.ServiceClient(), FirstTenantID, opts).Extract()
    46  	th.AssertNoErr(t, err)
    47  	th.CheckDeepEquals(t, &FirstQuotaSet, actual)
    48  }
    49  
    50  func TestDelete(t *testing.T) {
    51  	th.SetupHTTP()
    52  	defer th.TeardownHTTP()
    53  	HandleDeleteSuccessfully(t)
    54  	_, err := quotasets.Delete(client.ServiceClient(), FirstTenantID).Extract()
    55  	th.AssertNoErr(t, err)
    56  }
    57  
    58  type ErrorUpdateOpts quotasets.UpdateOpts
    59  
    60  func (opts ErrorUpdateOpts) ToComputeQuotaUpdateMap() (map[string]interface{}, error) {
    61  	return nil, errors.New("This is an error")
    62  }
    63  
    64  func TestErrorInToComputeQuotaUpdateMap(t *testing.T) {
    65  	opts := &ErrorUpdateOpts{}
    66  	th.SetupHTTP()
    67  	defer th.TeardownHTTP()
    68  	HandlePutSuccessfully(t)
    69  	_, err := quotasets.Update(client.ServiceClient(), FirstTenantID, opts).Extract()
    70  	if err == nil {
    71  		t.Fatal("Error handling failed")
    72  	}
    73  }