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