github.com/gophercloud/gophercloud@v1.11.0/openstack/identity/v3/regions/testing/requests_test.go (about) 1 package testing 2 3 import ( 4 "testing" 5 6 "github.com/gophercloud/gophercloud/openstack/identity/v3/regions" 7 "github.com/gophercloud/gophercloud/pagination" 8 th "github.com/gophercloud/gophercloud/testhelper" 9 "github.com/gophercloud/gophercloud/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 var description = "First West sub-region of RegionOne" 81 updateOpts := regions.UpdateOpts{ 82 Description: &description, 83 /* 84 // Due to a bug in Keystone, the Extra column of the Region table 85 // is not updatable, see: https://bugs.launchpad.net/keystone/+bug/1729933 86 // The following lines should be uncommented once the fix is merged. 87 88 Extra: map[string]interface{}{ 89 "email": "1stwestsupport@example.com", 90 }, 91 */ 92 } 93 94 actual, err := regions.Update(client.ServiceClient(), "RegionOne-West", updateOpts).Extract() 95 th.AssertNoErr(t, err) 96 th.CheckDeepEquals(t, SecondRegionUpdated, *actual) 97 } 98 99 func TestDeleteRegion(t *testing.T) { 100 th.SetupHTTP() 101 defer th.TeardownHTTP() 102 HandleDeleteRegionSuccessfully(t) 103 104 res := regions.Delete(client.ServiceClient(), "RegionOne-West") 105 th.AssertNoErr(t, res.Err) 106 }