Move region list into a function so we can re-use it in tests
This commit is contained in:
parent
10991af675
commit
0cad32c696
@ -30,9 +30,7 @@ func TestAMIConfigPrepare_regions(t *testing.T) {
|
|||||||
t.Fatalf("shouldn't have err: %s", err)
|
t.Fatalf("shouldn't have err: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.AMIRegions = []string{"ap-northeast-1", "ap-northeast-2", "ap-southeast-1",
|
c.AMIRegions = listEC2Regions()
|
||||||
"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"}
|
|
||||||
if err := c.Prepare(nil); err != nil {
|
if err := c.Prepare(nil); err != nil {
|
||||||
t.Fatalf("shouldn't have err: %s", err)
|
t.Fatalf("shouldn't have err: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
// ValidateRegion returns true if the supplied region is a valid AWS
|
func listEC2Regions() []string {
|
||||||
// region and false if it's not.
|
return []string{
|
||||||
func ValidateRegion(region string) bool {
|
|
||||||
var regions = [12]string{
|
|
||||||
"ap-northeast-1",
|
"ap-northeast-1",
|
||||||
"ap-northeast-2",
|
"ap-northeast-2",
|
||||||
"ap-southeast-1",
|
"ap-southeast-1",
|
||||||
@ -17,8 +15,12 @@ func ValidateRegion(region string) bool {
|
|||||||
"us-west-1",
|
"us-west-1",
|
||||||
"us-west-2",
|
"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 {
|
if region == valid {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user