github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/compute/v2/extensions/servergroups/testing/requests_test.go (about) 1 package testing 2 3 import ( 4 "testing" 5 6 "github.com/huaweicloud/golangsdk/openstack/compute/v2/extensions/servergroups" 7 "github.com/huaweicloud/golangsdk/pagination" 8 th "github.com/huaweicloud/golangsdk/testhelper" 9 "github.com/huaweicloud/golangsdk/testhelper/client" 10 ) 11 12 func TestList(t *testing.T) { 13 th.SetupHTTP() 14 defer th.TeardownHTTP() 15 HandleListSuccessfully(t) 16 17 count := 0 18 err := servergroups.List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { 19 count++ 20 actual, err := servergroups.ExtractServerGroups(page) 21 th.AssertNoErr(t, err) 22 th.CheckDeepEquals(t, ExpectedServerGroupSlice, actual) 23 24 return true, nil 25 }) 26 th.AssertNoErr(t, err) 27 th.CheckEquals(t, 1, count) 28 } 29 30 func TestCreate(t *testing.T) { 31 th.SetupHTTP() 32 defer th.TeardownHTTP() 33 HandleCreateSuccessfully(t) 34 35 actual, err := servergroups.Create(client.ServiceClient(), servergroups.CreateOpts{ 36 Name: "test", 37 Policies: []string{"anti-affinity"}, 38 }).Extract() 39 th.AssertNoErr(t, err) 40 th.CheckDeepEquals(t, &CreatedServerGroup, actual) 41 } 42 43 func TestGet(t *testing.T) { 44 th.SetupHTTP() 45 defer th.TeardownHTTP() 46 HandleGetSuccessfully(t) 47 48 actual, err := servergroups.Get(client.ServiceClient(), "4d8c3732-a248-40ed-bebc-539a6ffd25c0").Extract() 49 th.AssertNoErr(t, err) 50 th.CheckDeepEquals(t, &FirstServerGroup, actual) 51 } 52 53 func TestDelete(t *testing.T) { 54 th.SetupHTTP() 55 defer th.TeardownHTTP() 56 HandleDeleteSuccessfully(t) 57 58 err := servergroups.Delete(client.ServiceClient(), "616fb98f-46ca-475e-917e-2563e5a8cd19").ExtractErr() 59 th.AssertNoErr(t, err) 60 } 61 62 func TestAddMember(t *testing.T) { 63 th.SetupHTTP() 64 defer th.TeardownHTTP() 65 HandleAddMemberSuccessfully(t) 66 67 err := servergroups.UpdateMember(client.ServiceClient(), servergroups.MemberOpts{ 68 InstanceUUid: "d194d539-07b0-446e-b52c-e639e618e49d", 69 }, "add_member", "616fb98f-46ca-475e-917e-2563e5a8cd19").ExtractErr() 70 th.AssertNoErr(t, err) 71 } 72 73 func TestRemoveMember(t *testing.T) { 74 th.SetupHTTP() 75 defer th.TeardownHTTP() 76 HandleRemoveMemberSuccessfully(t) 77 78 err := servergroups.UpdateMember(client.ServiceClient(), servergroups.MemberOpts{ 79 InstanceUUid: "d194d539-07b0-446e-b52c-e639e618e49d", 80 }, "remove_member", "616fb98f-46ca-475e-917e-2563e5a8cd19").ExtractErr() 81 th.AssertNoErr(t, err) 82 }