Move region list into a function so we can re-use it in tests

This commit is contained in:
Chris Bednarski 2016-01-12 19:03:21 -08:00
parent 10991af675
commit 0cad32c696
2 changed files with 8 additions and 8 deletions

View File

@ -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)
}

View File

@ -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
}