From 0cad32c69630910a4f42b5c5a0c8d2780503528f Mon Sep 17 00:00:00 2001 From: Chris Bednarski Date: Tue, 12 Jan 2016 19:03:21 -0800 Subject: [PATCH] Move region list into a function so we can re-use it in tests --- builder/amazon/common/ami_config_test.go | 4 +--- builder/amazon/common/regions.go | 12 +++++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/builder/amazon/common/ami_config_test.go b/builder/amazon/common/ami_config_test.go index 1e8ecc9f1..54210fca9 100644 --- a/builder/amazon/common/ami_config_test.go +++ b/builder/amazon/common/ami_config_test.go @@ -30,9 +30,7 @@ func TestAMIConfigPrepare_regions(t *testing.T) { t.Fatalf("shouldn't have err: %s", err) } - c.AMIRegions = []string{"ap-northeast-1", "ap-northeast-2", "ap-southeast-1", - "ap-southeast-2", "cn-north-1", "eu-central-1", "eu-west-1", "sa-east-1", - "us-east-1", "us-gov-west-1", "us-west-1", "us-west-2"} + c.AMIRegions = listEC2Regions() if err := c.Prepare(nil); err != nil { t.Fatalf("shouldn't have err: %s", err) } diff --git a/builder/amazon/common/regions.go b/builder/amazon/common/regions.go index 2096a715a..b4b6f7d67 100644 --- a/builder/amazon/common/regions.go +++ b/builder/amazon/common/regions.go @@ -1,9 +1,7 @@ package common -// ValidateRegion returns true if the supplied region is a valid AWS -// region and false if it's not. -func ValidateRegion(region string) bool { - var regions = [12]string{ +func listEC2Regions() []string { + return []string{ "ap-northeast-1", "ap-northeast-2", "ap-southeast-1", @@ -17,8 +15,12 @@ func ValidateRegion(region string) bool { "us-west-1", "us-west-2", } +} - for _, valid := range regions { +// ValidateRegion returns true if the supplied region is a valid AWS +// region and false if it's not. +func ValidateRegion(region string) bool { + for _, valid := range listEC2Regions() { if region == valid { return true }