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