github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/acceptance/openstack/apigw/v2/group_test.go (about) 1 package v2 2 3 import ( 4 "os" 5 "testing" 6 7 golangsdk "github.com/opentelekomcloud/gophertelekomcloud" 8 "github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients" 9 "github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools" 10 "github.com/opentelekomcloud/gophertelekomcloud/openstack/apigw/v2/group" 11 th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" 12 ) 13 14 func TestGroupLifecycle(t *testing.T) { 15 gatewayId := os.Getenv("GATEWAY_ID") 16 17 if gatewayId == "" { 18 t.Skip("`GATEWAY_ID` need to be defined") 19 } 20 client, err := clients.NewAPIGWClient() 21 th.AssertNoErr(t, err) 22 23 createResp := CreateGroup(client, t, gatewayId) 24 25 t.Cleanup(func() { 26 th.AssertNoErr(t, group.Delete(client, gatewayId, createResp.ID)) 27 }) 28 29 updateOpts := group.UpdateOpts{ 30 GroupID: createResp.ID, 31 Name: createResp.Name + "-updated", 32 Description: "test updated", 33 GatewayID: gatewayId, 34 } 35 36 _, err = group.Update(client, updateOpts) 37 th.AssertNoErr(t, err) 38 39 getResp, err := group.Get(client, gatewayId, createResp.ID) 40 th.AssertNoErr(t, err) 41 42 tools.PrintResource(t, getResp) 43 } 44 45 func TestGroupList(t *testing.T) { 46 gatewayId := os.Getenv("GATEWAY_ID") 47 48 if gatewayId == "" { 49 t.Skip("`GATEWAY_ID` need to be defined") 50 } 51 52 client, err := clients.NewAPIGWClient() 53 th.AssertNoErr(t, err) 54 55 listResp, err := group.List(client, group.ListOpts{ 56 GatewayID: gatewayId, 57 }) 58 th.AssertNoErr(t, err) 59 tools.PrintResource(t, listResp) 60 } 61 62 func CreateGroup(client *golangsdk.ServiceClient, t *testing.T, id string) *group.GroupResp { 63 name := tools.RandomString("apigw_group-", 3) 64 65 createOpts := group.CreateOpts{ 66 Name: name, 67 Description: "test", 68 GatewayID: id, 69 } 70 71 createResp, err := group.Create(client, createOpts) 72 th.AssertNoErr(t, err) 73 return createResp 74 }