From 81913c58fbef03218fad9b1011ed591a246ab2e7 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 21 Oct 2014 10:57:55 -0700 Subject: [PATCH] providers/aws: fixing faililng test --- builtin/providers/aws/structure_test.go | 16 +++++++++++----- helper/schema/set.go | 11 +++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/builtin/providers/aws/structure_test.go b/builtin/providers/aws/structure_test.go index 7621535fb..e230cdf91 100644 --- a/builtin/providers/aws/structure_test.go +++ b/builtin/providers/aws/structure_test.go @@ -5,6 +5,8 @@ import ( "testing" "github.com/hashicorp/terraform/flatmap" + "github.com/hashicorp/terraform/helper/hashcode" + "github.com/hashicorp/terraform/helper/schema" "github.com/mitchellh/goamz/ec2" "github.com/mitchellh/goamz/elb" ) @@ -33,16 +35,20 @@ func testConf() map[string]string { } func Test_expandIPPerms(t *testing.T) { + hash := func(v interface{}) int { + return hashcode.String(v.(string)) + } + expanded := []interface{}{ map[string]interface{}{ "protocol": "icmp", "from_port": 1, "to_port": -1, "cidr_blocks": []interface{}{"0.0.0.0/0"}, - "security_groups": []interface{}{ + "security_groups": schema.NewSet(hash, []interface{}{ "sg-11111", "foo/sg-22222", - }, + }), }, map[string]interface{}{ "protocol": "icmp", @@ -60,13 +66,13 @@ func Test_expandIPPerms(t *testing.T) { ToPort: -1, SourceIPs: []string{"0.0.0.0/0"}, SourceGroups: []ec2.UserSecurityGroup{ - ec2.UserSecurityGroup{ - Id: "sg-11111", - }, ec2.UserSecurityGroup{ OwnerId: "foo", Id: "sg-22222", }, + ec2.UserSecurityGroup{ + Id: "sg-11111", + }, }, }, ec2.IPPerm{ diff --git a/helper/schema/set.go b/helper/schema/set.go index 21e329f22..92966ea59 100644 --- a/helper/schema/set.go +++ b/helper/schema/set.go @@ -14,6 +14,17 @@ type Set struct { once sync.Once } +// NewSet is a convenience method for creating a new set with the given +// items. +func NewSet(f SchemaSetFunc, items []interface{}) *Set { + s := &Set{F: f} + for _, i := range items { + s.Add(i) + } + + return s +} + // Add adds an item to the set if it isn't already in the set. func (s *Set) Add(item interface{}) { s.add(item)