github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/blockstorage/v2/quotasets/testing/requests_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"context"
     5  	"errors"
     6  	"testing"
     7  
     8  	"github.com/vnpaycloud-console/gophercloud/v2/openstack/blockstorage/v2/quotasets"
     9  	th "github.com/vnpaycloud-console/gophercloud/v2/testhelper"
    10  	"github.com/vnpaycloud-console/gophercloud/v2/testhelper/client"
    11  )
    12  
    13  func TestGet(t *testing.T) {
    14  	th.SetupHTTP()
    15  	defer th.TeardownHTTP()
    16  
    17  	uriQueryParms := map[string]string{}
    18  	HandleSuccessfulRequest(t, "GET", "/os-quota-sets/"+FirstTenantID, getExpectedJSONBody, uriQueryParms)
    19  	actual, err := quotasets.Get(context.TODO(), client.ServiceClient(), FirstTenantID).Extract()
    20  	th.AssertNoErr(t, err)
    21  	th.CheckDeepEquals(t, &getExpectedQuotaSet, actual)
    22  }
    23  
    24  func TestGetUsage(t *testing.T) {
    25  	th.SetupHTTP()
    26  	defer th.TeardownHTTP()
    27  
    28  	uriQueryParms := map[string]string{"usage": "true"}
    29  	HandleSuccessfulRequest(t, "GET", "/os-quota-sets/"+FirstTenantID, getUsageExpectedJSONBody, uriQueryParms)
    30  	actual, err := quotasets.GetUsage(context.TODO(), client.ServiceClient(), FirstTenantID).Extract()
    31  	th.AssertNoErr(t, err)
    32  	th.CheckDeepEquals(t, getUsageExpectedQuotaSet, actual)
    33  }
    34  
    35  func TestFullUpdate(t *testing.T) {
    36  	th.SetupHTTP()
    37  	defer th.TeardownHTTP()
    38  
    39  	uriQueryParms := map[string]string{}
    40  	HandleSuccessfulRequest(t, "PUT", "/os-quota-sets/"+FirstTenantID, fullUpdateExpectedJSONBody, uriQueryParms)
    41  	actual, err := quotasets.Update(context.TODO(), client.ServiceClient(), FirstTenantID, fullUpdateOpts).Extract()
    42  	th.AssertNoErr(t, err)
    43  	th.CheckDeepEquals(t, &fullUpdateExpectedQuotaSet, actual)
    44  }
    45  
    46  func TestPartialUpdate(t *testing.T) {
    47  	th.SetupHTTP()
    48  	defer th.TeardownHTTP()
    49  
    50  	uriQueryParms := map[string]string{}
    51  	HandleSuccessfulRequest(t, "PUT", "/os-quota-sets/"+FirstTenantID, partialUpdateExpectedJSONBody, uriQueryParms)
    52  	actual, err := quotasets.Update(context.TODO(), client.ServiceClient(), FirstTenantID, partialUpdateOpts).Extract()
    53  	th.AssertNoErr(t, err)
    54  	th.CheckDeepEquals(t, &partiualUpdateExpectedQuotaSet, actual)
    55  }
    56  
    57  type ErrorUpdateOpts quotasets.UpdateOpts
    58  
    59  func (opts ErrorUpdateOpts) ToBlockStorageQuotaUpdateMap() (map[string]any, error) {
    60  	return nil, errors.New("This is an error")
    61  }
    62  
    63  func TestErrorInToBlockStorageQuotaUpdateMap(t *testing.T) {
    64  	opts := &ErrorUpdateOpts{}
    65  	th.SetupHTTP()
    66  	defer th.TeardownHTTP()
    67  	HandleSuccessfulRequest(t, "PUT", "/os-quota-sets/"+FirstTenantID, "", nil)
    68  	_, err := quotasets.Update(context.TODO(), client.ServiceClient(), FirstTenantID, opts).Extract()
    69  	if err == nil {
    70  		t.Fatal("Error handling failed")
    71  	}
    72  }
    73  
    74  func TestDelete(t *testing.T) {
    75  	th.SetupHTTP()
    76  	defer th.TeardownHTTP()
    77  	HandleDeleteSuccessfully(t)
    78  
    79  	err := quotasets.Delete(context.TODO(), client.ServiceClient(), FirstTenantID).ExtractErr()
    80  	th.AssertNoErr(t, err)
    81  }