packer-cn/builder/osc/common/access_config_test.go

46 lines
1.0 KiB
Go
Raw Normal View History

2019-01-28 13:29:26 -05:00
package common
import (
"testing"
)
func testAccessConfig() *AccessConfig {
return &AccessConfig{}
2019-01-28 13:29:26 -05:00
}
func TestAccessConfigPrepare_Region(t *testing.T) {
c := testAccessConfig()
c.RawRegion = "us-east-12"
2020-10-13 13:54:25 -04:00
err := c.ValidateOSCRegion(c.RawRegion)
2019-01-28 13:29:26 -05:00
if err == nil {
t.Fatalf("should have region validation err: %s", c.RawRegion)
}
c.RawRegion = "us-east-1"
2020-10-13 16:16:01 -04:00
err = c.ValidateOSCRegion(c.RawRegion)
2020-10-13 13:54:25 -04:00
if err == nil {
t.Fatalf("should have region validation err: %s", c.RawRegion)
}
2019-01-28 13:29:26 -05:00
c.RawRegion = "custom"
2020-10-13 13:54:25 -04:00
err = c.ValidateOSCRegion(c.RawRegion)
2019-01-28 13:29:26 -05:00
if err == nil {
t.Fatalf("should have region validation err: %s", c.RawRegion)
}
c.RawRegion = "custom"
c.SkipValidation = true
// testing whole prepare func here; this is checking that validation is
// skipped, so we don't need a mock connection
if err := c.Prepare(nil); err != nil {
t.Fatalf("shouldn't have err: %s", err)
}
c.SkipValidation = false
c.RawRegion = ""
if err := c.Prepare(nil); err != nil {
t.Fatalf("shouldn't have err: %s", err)
}
}