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