github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/acceptance/openstack/dcaas/v2/virtual_gateway_test.go (about) 1 package v2 2 3 import ( 4 "os" 5 "strings" 6 "testing" 7 8 "github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients" 9 "github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools" 10 dc_endpoint_group "github.com/opentelekomcloud/gophertelekomcloud/openstack/dcaas/v2/dc-endpoint-group" 11 "github.com/opentelekomcloud/gophertelekomcloud/openstack/dcaas/v2/virtual-gateway" 12 th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" 13 ) 14 15 func TestVirtualGatewayListing(t *testing.T) { 16 client, err := clients.NewDCaaSV2Client() 17 th.AssertNoErr(t, err) 18 19 opts := virtual_gateway.ListOpts{} 20 vgwList, err := virtual_gateway.List(client, opts) 21 th.AssertNoErr(t, err) 22 23 for _, vgw := range vgwList { 24 tools.PrintResource(t, vgw) 25 } 26 } 27 28 func TestVirtualGatewayLifecycle(t *testing.T) { 29 if os.Getenv("OS_VPC_ID") == "" { 30 t.Skip("OS_VPC_ID necessary for this test") 31 } 32 client, err := clients.NewDCaaSV2Client() 33 th.AssertNoErr(t, err) 34 35 egName := strings.ToLower(tools.RandomString("test-acc-dc-eg-", 5)) 36 egCreateOpts := dc_endpoint_group.CreateOpts{ 37 TenantId: client.ProjectID, 38 Name: egName, 39 Endpoints: []string{"10.2.0.0/24", "10.3.0.0/24"}, 40 Type: "cidr", 41 } 42 43 eg, err := dc_endpoint_group.Create(client, egCreateOpts) 44 th.AssertNoErr(t, err) 45 46 // Cleanup 47 t.Cleanup(func() { 48 err = dc_endpoint_group.Delete(client, eg.ID) 49 th.AssertNoErr(t, err) 50 }) 51 52 // Create a virtual gateway 53 name := strings.ToLower(tools.RandomString("test-virtual-gateway", 5)) 54 createOpts := virtual_gateway.CreateOpts{ 55 Name: name, 56 Type: "default", 57 VpcId: os.Getenv("OS_VPC_ID"), 58 Description: "test-virtual-interface", 59 LocalEndpointGroupId: eg.ID, 60 } 61 62 created, err := virtual_gateway.Create(client, createOpts) 63 th.AssertNoErr(t, err) 64 65 _, err = virtual_gateway.Get(client, created.ID) 66 th.AssertNoErr(t, err) 67 68 updateOpts := virtual_gateway.UpdateOpts{ 69 Name: tools.RandomString(name, 3), 70 Description: "test-virtual-interface-updated", 71 } 72 _ = virtual_gateway.Update(client, created.ID, updateOpts) 73 th.AssertNoErr(t, err) 74 75 opts := virtual_gateway.ListOpts{} 76 _, err = virtual_gateway.List(client, opts) 77 th.AssertNoErr(t, err) 78 79 t.Cleanup(func() { 80 err = virtual_gateway.Delete(client, created.ID) 81 th.AssertNoErr(t, err) 82 }) 83 }