github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/identity/v3/limits/testing/requests_test.go (about) 1 package testing 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/vnpaycloud-console/gophercloud/v2/openstack/identity/v3/limits" 8 "github.com/vnpaycloud-console/gophercloud/v2/pagination" 9 th "github.com/vnpaycloud-console/gophercloud/v2/testhelper" 10 "github.com/vnpaycloud-console/gophercloud/v2/testhelper/client" 11 ) 12 13 func TestGetEnforcementModel(t *testing.T) { 14 th.SetupHTTP() 15 defer th.TeardownHTTP() 16 HandleGetEnforcementModelSuccessfully(t) 17 18 actual, err := limits.GetEnforcementModel(context.TODO(), client.ServiceClient()).Extract() 19 th.AssertNoErr(t, err) 20 th.CheckDeepEquals(t, Model, *actual) 21 } 22 23 func TestListLimits(t *testing.T) { 24 th.SetupHTTP() 25 defer th.TeardownHTTP() 26 HandleListLimitsSuccessfully(t) 27 28 count := 0 29 err := limits.List(client.ServiceClient(), nil).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) { 30 count++ 31 32 actual, err := limits.ExtractLimits(page) 33 th.AssertNoErr(t, err) 34 35 th.CheckDeepEquals(t, ExpectedLimitsSlice, actual) 36 37 return true, nil 38 }) 39 th.AssertNoErr(t, err) 40 th.CheckEquals(t, count, 1) 41 } 42 43 func TestListLimitsAllPages(t *testing.T) { 44 th.SetupHTTP() 45 defer th.TeardownHTTP() 46 HandleListLimitsSuccessfully(t) 47 48 allPages, err := limits.List(client.ServiceClient(), nil).AllPages(context.TODO()) 49 th.AssertNoErr(t, err) 50 actual, err := limits.ExtractLimits(allPages) 51 th.AssertNoErr(t, err) 52 th.CheckDeepEquals(t, ExpectedLimitsSlice, actual) 53 } 54 55 func TestCreateLimits(t *testing.T) { 56 th.SetupHTTP() 57 defer th.TeardownHTTP() 58 HandleCreateLimitSuccessfully(t) 59 60 createOpts := limits.BatchCreateOpts{ 61 limits.CreateOpts{ 62 ServiceID: "9408080f1970482aa0e38bc2d4ea34b7", 63 ProjectID: "3a705b9f56bb439381b43c4fe59dccce", 64 RegionID: "RegionOne", 65 ResourceName: "snapshot", 66 ResourceLimit: 5, 67 }, 68 limits.CreateOpts{ 69 ServiceID: "9408080f1970482aa0e38bc2d4ea34b7", 70 DomainID: "edbafc92be354ffa977c58aa79c7bdb2", 71 ResourceName: "volume", 72 ResourceLimit: 11, 73 Description: "Number of volumes for project 3a705b9f56bb439381b43c4fe59dccce", 74 }, 75 } 76 77 actual, err := limits.BatchCreate(context.TODO(), client.ServiceClient(), createOpts).Extract() 78 th.AssertNoErr(t, err) 79 th.CheckDeepEquals(t, ExpectedLimitsSlice, actual) 80 } 81 82 func TestGetLimit(t *testing.T) { 83 th.SetupHTTP() 84 defer th.TeardownHTTP() 85 HandleGetLimitSuccessfully(t) 86 87 actual, err := limits.Get(context.TODO(), client.ServiceClient(), "25a04c7a065c430590881c646cdcdd58").Extract() 88 th.AssertNoErr(t, err) 89 th.CheckDeepEquals(t, FirstLimit, *actual) 90 } 91 92 func TestUpdateLimit(t *testing.T) { 93 th.SetupHTTP() 94 defer th.TeardownHTTP() 95 HandleUpdateLimitSuccessfully(t) 96 97 var description = "Number of snapshots for project 3a705b9f56bb439381b43c4fe59dccce" 98 var resourceLimit = 5 99 updateOpts := limits.UpdateOpts{ 100 Description: &description, 101 ResourceLimit: &resourceLimit, 102 } 103 104 actual, err := limits.Update(context.TODO(), client.ServiceClient(), "3229b3849f584faea483d6851f7aab05", updateOpts).Extract() 105 th.AssertNoErr(t, err) 106 th.CheckDeepEquals(t, SecondLimitUpdated, *actual) 107 } 108 109 func TestDeleteLimit(t *testing.T) { 110 th.SetupHTTP() 111 defer th.TeardownHTTP() 112 HandleDeleteLimitSuccessfully(t) 113 114 err := limits.Delete(context.TODO(), client.ServiceClient(), "3229b3849f584faea483d6851f7aab05").ExtractErr() 115 th.AssertNoErr(t, err) 116 }