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