github.com/leeclow-ops/gophercloud@v1.2.1/openstack/identity/v3/limits/testing/requests_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/leeclow-ops/gophercloud/openstack/identity/v3/limits"
     7  	"github.com/leeclow-ops/gophercloud/pagination"
     8  	th "github.com/leeclow-ops/gophercloud/testhelper"
     9  	"github.com/leeclow-ops/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  }