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