Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/aws: updating the tests and refactoring the code a little #682

Merged
merged 1 commit into from
Dec 16, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion builtin/providers/aws/resource_aws_elb.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func resourceAwsElbRead(d *schema.ResourceData, meta interface{}) error {
d.Set("name", lb.LoadBalancerName)
d.Set("dns_name", lb.DNSName)
d.Set("internal", lb.Scheme == "internal")
d.Set("availability_zones", flattenAvailabilityZones(lb.AvailabilityZones))
d.Set("availability_zones", lb.AvailabilityZones)
d.Set("instances", flattenInstances(lb.Instances))
d.Set("listener", flattenListeners(lb.Listeners))
d.Set("security_groups", lb.SecurityGroups)
Expand Down
15 changes: 10 additions & 5 deletions builtin/providers/aws/resource_aws_elb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"reflect"
"sort"
"testing"

"github.com/hashicorp/terraform/helper/resource"
Expand All @@ -28,11 +29,11 @@ func TestAccAWSELB_basic(t *testing.T) {
resource.TestCheckResourceAttr(
"aws_elb.bar", "name", "foobar-terraform-test"),
resource.TestCheckResourceAttr(
"aws_elb.bar", "availability_zones.0", "us-west-2a"),
"aws_elb.bar", "availability_zones.2487133097", "us-west-2a"),
resource.TestCheckResourceAttr(
"aws_elb.bar", "availability_zones.1", "us-west-2b"),
"aws_elb.bar", "availability_zones.221770259", "us-west-2b"),
resource.TestCheckResourceAttr(
"aws_elb.bar", "availability_zones.2", "us-west-2c"),
"aws_elb.bar", "availability_zones.2050015877", "us-west-2c"),
resource.TestCheckResourceAttr(
"aws_elb.bar", "listener.206423021.instance_port", "8000"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -150,7 +151,9 @@ func testAccCheckAWSELBDestroy(s *terraform.State) error {

func testAccCheckAWSELBAttributes(conf *elb.LoadBalancer) resource.TestCheckFunc {
return func(s *terraform.State) error {
if conf.AvailabilityZones[0].AvailabilityZone != "us-west-2a" {
zones := []string{"us-west-2a", "us-west-2b", "us-west-2c"}
sort.StringSlice(conf.AvailabilityZones).Sort()
if !reflect.DeepEqual(conf.AvailabilityZones, zones) {
return fmt.Errorf("bad availability_zones")
}

Expand Down Expand Up @@ -182,7 +185,9 @@ func testAccCheckAWSELBAttributes(conf *elb.LoadBalancer) resource.TestCheckFunc

func testAccCheckAWSELBAttributesHealthCheck(conf *elb.LoadBalancer) resource.TestCheckFunc {
return func(s *terraform.State) error {
if conf.AvailabilityZones[0].AvailabilityZone != "us-west-2a" {
zones := []string{"us-west-2a", "us-west-2b", "us-west-2c"}
sort.StringSlice(conf.AvailabilityZones).Sort()
if !reflect.DeepEqual(conf.AvailabilityZones, zones) {
return fmt.Errorf("bad availability_zones")
}

Expand Down
9 changes: 0 additions & 9 deletions builtin/providers/aws/structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,6 @@ func flattenInstances(list []elb.Instance) []string {
return result
}

// Flattens an array of AvailabilityZones into a []string
func flattenAvailabilityZones(list []elb.AvailabilityZone) []string {
result := make([]string, 0, len(list))
for _, z := range list {
result = append(result, z.AvailabilityZone)
}
return result
}

// Flattens an array of Listeners into a []map[string]interface{}
func flattenListeners(list []elb.Listener) []map[string]interface{} {
result := make([]map[string]interface{}, 0, len(list))
Expand Down