Fix firewall policies tests

This commit is contained in:
Guillaume Giamarchi 2015-02-18 01:00:48 +01:00 committed by Jon Perritt
parent c5e861c049
commit 54174dcc05
1 changed files with 14 additions and 27 deletions

View File

@ -2,7 +2,6 @@ package openstack
import ( import (
"fmt" "fmt"
"reflect"
"testing" "testing"
"time" "time"
@ -23,9 +22,7 @@ func TestAccOpenstackFirewallPolicy(t *testing.T) {
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckFirewallPolicyExists( testAccCheckFirewallPolicyExists(
"openstack_fw_policy_v2.accept_test", "openstack_fw_policy_v2.accept_test",
&policies.Policy{ "", "", 0),
Rules: []string{},
}),
), ),
}, },
resource.TestStep{ resource.TestStep{
@ -33,14 +30,7 @@ func TestAccOpenstackFirewallPolicy(t *testing.T) {
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckFirewallPolicyExists( testAccCheckFirewallPolicyExists(
"openstack_fw_policy_v2.accept_test", "openstack_fw_policy_v2.accept_test",
&policies.Policy{ "accept_test", "terraform acceptance test", 2),
Name: "accept_test",
Description: "terraform acceptance test",
Rules: []string{
"",
"",
},
}),
), ),
}, },
resource.TestStep{ resource.TestStep{
@ -48,7 +38,7 @@ func TestAccOpenstackFirewallPolicy(t *testing.T) {
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckFirewallPolicyExists( testAccCheckFirewallPolicyExists(
"openstack_fw_policy_v2.accept_test", "openstack_fw_policy_v2.accept_test",
&policies.Policy{}), "accept_test", "terraform acceptance test", 1),
), ),
}, },
}, },
@ -78,7 +68,7 @@ func testAccCheckOpenstackFirewallPolicyDestroy(s *terraform.State) error {
return nil return nil
} }
func testAccCheckFirewallPolicyExists(n string, expected *policies.Policy) resource.TestCheckFunc { func testAccCheckFirewallPolicyExists(n, name, description string, ruleCount int) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
@ -116,13 +106,16 @@ func testAccCheckFirewallPolicyExists(n string, expected *policies.Policy) resou
return err return err
} }
expected.ID = found.ID if name != found.Name {
// Erase the tenant id because we don't want to compare return fmt.Errorf("Expected name <%s>, but found <%s>", name, found.Name)
// it as long it is not present in the expected }
found.TenantID = ""
if !reflect.DeepEqual(expected, found) { if description != found.Description {
return fmt.Errorf("Expected:\n%#v\nFound:\n%#v", expected, found) return fmt.Errorf("Expected description <%s>, but found <%s>", description, found.Description)
}
if ruleCount != len(found.Rules) {
return fmt.Errorf("Expected rule count <%d>, but found <%d>", ruleCount, len(found.Rules))
} }
return nil return nil
@ -141,8 +134,7 @@ resource "openstack_fw_policy_v2" "accept_test" {
description = "terraform acceptance test" description = "terraform acceptance test"
rules = [ rules = [
"${openstack_fw_rule_v2.accept_test_udp_deny.id}", "${openstack_fw_rule_v2.accept_test_udp_deny.id}",
"${openstack_fw_rule_v2.accept_test_tcp_allow.id}", "${openstack_fw_rule_v2.accept_test_tcp_allow.id}"
"${openstack_fw_rule_v2.accept_test_icmp_allow.id}"
] ]
} }
@ -155,11 +147,6 @@ resource "openstack_fw_rule_v2" "accept_test_udp_deny" {
protocol = "udp" protocol = "udp"
action = "deny" action = "deny"
} }
resource "openstack_fw_rule_v2" "accept_test_icmp_allow" {
protocol = "icmp"
action = "allow"
}
` `
const testFirewallPolicyUpdateDeleteRule = ` const testFirewallPolicyUpdateDeleteRule = `