github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/identity/v3/regions/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/regions"
     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 TestListRegions(t *testing.T) {
    14  	th.SetupHTTP()
    15  	defer th.TeardownHTTP()
    16  	HandleListRegionsSuccessfully(t)
    17  
    18  	count := 0
    19  	err := regions.List(client.ServiceClient(), nil).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) {
    20  		count++
    21  
    22  		actual, err := regions.ExtractRegions(page)
    23  		th.AssertNoErr(t, err)
    24  
    25  		th.CheckDeepEquals(t, ExpectedRegionsSlice, actual)
    26  
    27  		return true, nil
    28  	})
    29  	th.AssertNoErr(t, err)
    30  	th.CheckEquals(t, count, 1)
    31  }
    32  
    33  func TestListRegionsAllPages(t *testing.T) {
    34  	th.SetupHTTP()
    35  	defer th.TeardownHTTP()
    36  	HandleListRegionsSuccessfully(t)
    37  
    38  	allPages, err := regions.List(client.ServiceClient(), nil).AllPages(context.TODO())
    39  	th.AssertNoErr(t, err)
    40  	actual, err := regions.ExtractRegions(allPages)
    41  	th.AssertNoErr(t, err)
    42  	th.CheckDeepEquals(t, ExpectedRegionsSlice, actual)
    43  	th.AssertEquals(t, ExpectedRegionsSlice[1].Extra["email"], "westsupport@example.com")
    44  }
    45  
    46  func TestGetRegion(t *testing.T) {
    47  	th.SetupHTTP()
    48  	defer th.TeardownHTTP()
    49  	HandleGetRegionSuccessfully(t)
    50  
    51  	actual, err := regions.Get(context.TODO(), client.ServiceClient(), "RegionOne-West").Extract()
    52  
    53  	th.AssertNoErr(t, err)
    54  	th.CheckDeepEquals(t, SecondRegion, *actual)
    55  }
    56  
    57  func TestCreateRegion(t *testing.T) {
    58  	th.SetupHTTP()
    59  	defer th.TeardownHTTP()
    60  	HandleCreateRegionSuccessfully(t)
    61  
    62  	createOpts := regions.CreateOpts{
    63  		ID:          "RegionOne-West",
    64  		Description: "West sub-region of RegionOne",
    65  		Extra: map[string]any{
    66  			"email": "westsupport@example.com",
    67  		},
    68  		ParentRegionID: "RegionOne",
    69  	}
    70  
    71  	actual, err := regions.Create(context.TODO(), client.ServiceClient(), createOpts).Extract()
    72  	th.AssertNoErr(t, err)
    73  	th.CheckDeepEquals(t, SecondRegion, *actual)
    74  }
    75  
    76  func TestUpdateRegion(t *testing.T) {
    77  	th.SetupHTTP()
    78  	defer th.TeardownHTTP()
    79  	HandleUpdateRegionSuccessfully(t)
    80  
    81  	var description = "First West sub-region of RegionOne"
    82  	updateOpts := regions.UpdateOpts{
    83  		Description: &description,
    84  		/*
    85  			// Due to a bug in Keystone, the Extra column of the Region table
    86  			// is not updatable, see: https://bugs.launchpad.net/keystone/+bug/1729933
    87  			// The following lines should be uncommented once the fix is merged.
    88  
    89  			Extra: map[string]any{
    90  				"email": "1stwestsupport@example.com",
    91  			},
    92  		*/
    93  	}
    94  
    95  	actual, err := regions.Update(context.TODO(), client.ServiceClient(), "RegionOne-West", updateOpts).Extract()
    96  	th.AssertNoErr(t, err)
    97  	th.CheckDeepEquals(t, SecondRegionUpdated, *actual)
    98  }
    99  
   100  func TestDeleteRegion(t *testing.T) {
   101  	th.SetupHTTP()
   102  	defer th.TeardownHTTP()
   103  	HandleDeleteRegionSuccessfully(t)
   104  
   105  	res := regions.Delete(context.TODO(), client.ServiceClient(), "RegionOne-West")
   106  	th.AssertNoErr(t, res.Err)
   107  }