github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/acceptance/openstack/networking/v2/fw_rule_test.go (about) 1 package v2 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/networking/v2/extensions/fwaas_v2/rules" 10 th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" 11 ) 12 13 func TestFwRuleLifecycle(t *testing.T) { 14 client, err := clients.NewNetworkV2Client() 15 th.AssertNoErr(t, err) 16 17 t.Logf("Attempting to create BandwidthV2") 18 ruleName := tools.RandomString("band-create", 3) 19 createOpts := rules.CreateOpts{ 20 Name: ruleName, 21 Protocol: "tcp", 22 Action: "deny", 23 DestinationPort: "23", 24 Enabled: pointerto.Bool(true), 25 } 26 27 rule, err := rules.Create(client, createOpts).Extract() 28 th.AssertNoErr(t, err) 29 t.Cleanup(func() { 30 t.Logf("Attempting to delete FwaasV2: %s", rule.ID) 31 err := rules.Delete(client, rule.ID).ExtractErr() 32 th.AssertNoErr(t, err) 33 t.Logf("Deleted FwaasV2: %s", rule.ID) 34 }) 35 th.AssertEquals(t, createOpts.Name, rule.Name) 36 th.AssertEquals(t, createOpts.DestinationPort, rule.DestinationPort) 37 t.Logf("Created FwaasV2: %s", rule.ID) 38 39 t.Logf("Attempting to update FwaasV2: %s", rule.ID) 40 updateOpts := rules.UpdateOpts{ 41 Protocol: pointerto.String("icmp"), 42 } 43 updatedRule, err := rules.Update(client, rule.ID, updateOpts).Extract() 44 th.AssertNoErr(t, err) 45 t.Logf("Updated FwaasV2: %s", rule.ID) 46 th.AssertEquals(t, updatedRule.Protocol, *updateOpts.Protocol) 47 48 t.Logf("Attempting to create Ipv6") 49 ipv6RuleName := tools.RandomString("ipv6-create", 3) 50 createIpv6Opts := rules.CreateOpts{ 51 Protocol: "tcp", 52 Action: "deny", 53 Name: ipv6RuleName, 54 IPVersion: 6, 55 DestinationIPAddress: "2001:db8::", 56 Enabled: pointerto.Bool(true), 57 } 58 59 rule6, err := rules.Create(client, createIpv6Opts).Extract() 60 th.AssertNoErr(t, err) 61 th.AssertEquals(t, rule6.IPVersion, 6) 62 }