github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/identity/v3/groups/testing/requests_test.go (about) 1 package testing 2 3 import ( 4 "testing" 5 6 "github.com/huaweicloud/golangsdk/openstack/identity/v3/groups" 7 "github.com/huaweicloud/golangsdk/pagination" 8 th "github.com/huaweicloud/golangsdk/testhelper" 9 "github.com/huaweicloud/golangsdk/testhelper/client" 10 ) 11 12 func TestListGroups(t *testing.T) { 13 th.SetupHTTP() 14 defer th.TeardownHTTP() 15 HandleListGroupsSuccessfully(t) 16 17 count := 0 18 err := groups.List(client.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) { 19 count++ 20 21 actual, err := groups.ExtractGroups(page) 22 th.AssertNoErr(t, err) 23 24 th.CheckDeepEquals(t, ExpectedGroupsSlice, actual) 25 26 return true, nil 27 }) 28 th.AssertNoErr(t, err) 29 th.CheckEquals(t, count, 1) 30 } 31 32 func TestListGroupsAllPages(t *testing.T) { 33 th.SetupHTTP() 34 defer th.TeardownHTTP() 35 HandleListGroupsSuccessfully(t) 36 37 allPages, err := groups.List(client.ServiceClient(), nil).AllPages() 38 th.AssertNoErr(t, err) 39 actual, err := groups.ExtractGroups(allPages) 40 th.AssertNoErr(t, err) 41 th.CheckDeepEquals(t, ExpectedGroupsSlice, actual) 42 th.AssertEquals(t, ExpectedGroupsSlice[0].Extra["email"], "support@localhost") 43 th.AssertEquals(t, ExpectedGroupsSlice[1].Extra["email"], "support@example.com") 44 } 45 46 func TestGetGroup(t *testing.T) { 47 th.SetupHTTP() 48 defer th.TeardownHTTP() 49 HandleGetGroupSuccessfully(t) 50 51 actual, err := groups.Get(client.ServiceClient(), "9fe1d3").Extract() 52 53 th.AssertNoErr(t, err) 54 th.CheckDeepEquals(t, SecondGroup, *actual) 55 th.AssertEquals(t, SecondGroup.Extra["email"], "support@example.com") 56 } 57 58 func TestCreateGroup(t *testing.T) { 59 th.SetupHTTP() 60 defer th.TeardownHTTP() 61 HandleCreateGroupSuccessfully(t) 62 63 createOpts := groups.CreateOpts{ 64 Name: "support", 65 DomainID: "1789d1", 66 Description: "group for support users", 67 Extra: map[string]interface{}{ 68 "email": "support@example.com", 69 }, 70 } 71 72 actual, err := groups.Create(client.ServiceClient(), createOpts).Extract() 73 th.AssertNoErr(t, err) 74 th.CheckDeepEquals(t, SecondGroup, *actual) 75 } 76 77 func TestUpdateGroup(t *testing.T) { 78 th.SetupHTTP() 79 defer th.TeardownHTTP() 80 HandleUpdateGroupSuccessfully(t) 81 82 updateOpts := groups.UpdateOpts{ 83 Description: "L2 Support Team", 84 Extra: map[string]interface{}{ 85 "email": "supportteam@example.com", 86 }, 87 } 88 89 actual, err := groups.Update(client.ServiceClient(), "9fe1d3", updateOpts).Extract() 90 th.AssertNoErr(t, err) 91 th.CheckDeepEquals(t, SecondGroupUpdated, *actual) 92 } 93 94 func TestDeleteGroup(t *testing.T) { 95 th.SetupHTTP() 96 defer th.TeardownHTTP() 97 HandleDeleteGroupSuccessfully(t) 98 99 res := groups.Delete(client.ServiceClient(), "9fe1d3") 100 th.AssertNoErr(t, res.Err) 101 }