github.com/leeclow-ops/gophercloud@v1.2.1/acceptance/openstack/networking/v2/extensions/fwaas_v2/rule_test.go (about) 1 //go:build acceptance || networking || fwaas_v2 2 // +build acceptance networking fwaas_v2 3 4 package fwaas_v2 5 6 import ( 7 "fmt" 8 "strconv" 9 "testing" 10 11 "github.com/leeclow-ops/gophercloud/acceptance/clients" 12 "github.com/leeclow-ops/gophercloud/acceptance/tools" 13 "github.com/leeclow-ops/gophercloud/openstack/networking/v2/extensions/fwaas_v2/rules" 14 th "github.com/leeclow-ops/gophercloud/testhelper" 15 ) 16 17 func TestRuleCRUD(t *testing.T) { 18 clients.SkipReleasesAbove(t, "stable/ussuri") 19 20 client, err := clients.NewNetworkV2Client() 21 th.AssertNoErr(t, err) 22 23 rule, err := CreateRule(t, client) 24 th.AssertNoErr(t, err) 25 defer DeleteRule(t, client, rule.ID) 26 27 tools.PrintResource(t, rule) 28 29 ruleDescription := "Some rule description" 30 ruleSourcePortInt := strconv.Itoa(tools.RandomInt(1, 100)) 31 ruleSourcePort := fmt.Sprintf("%s:%s", ruleSourcePortInt, ruleSourcePortInt) 32 ruleProtocol := rules.ProtocolTCP 33 updateOpts := rules.UpdateOpts{ 34 Description: &ruleDescription, 35 Protocol: &ruleProtocol, 36 SourcePort: &ruleSourcePort, 37 } 38 39 ruleUpdated, err := rules.Update(client, rule.ID, updateOpts).Extract() 40 th.AssertNoErr(t, err) 41 th.AssertEquals(t, ruleUpdated.Description, ruleDescription) 42 th.AssertEquals(t, ruleUpdated.SourcePort, ruleSourcePortInt) 43 th.AssertEquals(t, ruleUpdated.Protocol, string(ruleProtocol)) 44 45 newRule, err := rules.Get(client, rule.ID).Extract() 46 th.AssertNoErr(t, err) 47 48 tools.PrintResource(t, newRule) 49 50 allPages, err := rules.List(client, nil).AllPages() 51 th.AssertNoErr(t, err) 52 53 allRules, err := rules.ExtractRules(allPages) 54 th.AssertNoErr(t, err) 55 56 t.Logf("Attempting to find rule %s\n", newRule.ID) 57 var found bool 58 for _, rule := range allRules { 59 if rule.ID == newRule.ID { 60 found = true 61 t.Logf("Found rule %s\n", newRule.ID) 62 } 63 } 64 65 th.AssertEquals(t, found, true) 66 }