github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/acceptance/openstack/elb/v3/loadbalancers_test.go (about) 1 package v3 2 3 import ( 4 "testing" 5 6 "github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients" 7 "github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools" 8 "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/pointerto" 9 "github.com/opentelekomcloud/gophertelekomcloud/openstack/elb/v3/loadbalancers" 10 th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" 11 ) 12 13 func TestLoadBalancerList(t *testing.T) { 14 client, err := clients.NewElbV3Client() 15 th.AssertNoErr(t, err) 16 17 listOpts := loadbalancers.ListOpts{} 18 loadbalancerPages, err := loadbalancers.List(client, listOpts).AllPages() 19 th.AssertNoErr(t, err) 20 21 loadbalancerList, err := loadbalancers.ExtractLoadbalancers(loadbalancerPages) 22 th.AssertNoErr(t, err) 23 24 for _, lb := range loadbalancerList { 25 tools.PrintResource(t, lb) 26 } 27 } 28 29 func TestLoadBalancerLifecycle(t *testing.T) { 30 client, err := clients.NewElbV3Client() 31 th.AssertNoErr(t, err) 32 33 loadbalancerID := createLoadBalancer(t, client) 34 defer deleteLoadbalancer(t, client, loadbalancerID) 35 36 t.Logf("Attempting to update ELBv3 LoadBalancer: %s", loadbalancerID) 37 lbName := tools.RandomString("update-lb-", 3) 38 emptyDescription := "" 39 updateOptsDpE := loadbalancers.UpdateOpts{ 40 Name: lbName, 41 Description: &emptyDescription, 42 DeletionProtectionEnable: pointerto.Bool(true), 43 } 44 _, err = loadbalancers.Update(client, loadbalancerID, updateOptsDpE).Extract() 45 th.AssertNoErr(t, err) 46 t.Logf("Updated ELBv3 LoadBalancer: %s", loadbalancerID) 47 48 err = loadbalancers.Delete(client, loadbalancerID).ExtractErr() 49 if err != nil { 50 t.Logf("Cannot delete, Deletion Protection enabled for ELBv3 LoadBalancer: %s", loadbalancerID) 51 } 52 53 updateOptsDpD := loadbalancers.UpdateOpts{ 54 Name: lbName, 55 Description: &emptyDescription, 56 DeletionProtectionEnable: pointerto.Bool(false), 57 } 58 _, err = loadbalancers.Update(client, loadbalancerID, updateOptsDpD).Extract() 59 th.AssertNoErr(t, err) 60 t.Logf("Updated ELBv3 LoadBalancer: %s", loadbalancerID) 61 62 newLoadbalancer, err := loadbalancers.Get(client, loadbalancerID).Extract() 63 th.AssertNoErr(t, err) 64 th.AssertEquals(t, updateOptsDpD.Name, newLoadbalancer.Name) 65 th.AssertEquals(t, emptyDescription, newLoadbalancer.Description) 66 th.AssertEquals(t, false, newLoadbalancer.DeletionProtectionEnable) 67 }