builder/amazonebs: Finish basic validation
This commit is contained in:
parent
4223e5bcca
commit
4fa27e6a30
|
@ -68,6 +68,10 @@ func (b *Builder) Prepare(raw interface{}) (err error) {
|
|||
errs = append(errs, errors.New("An instance_type must be specified"))
|
||||
}
|
||||
|
||||
if b.config.Region == "" {
|
||||
errs = append(errs, errors.New("A region must be specified"))
|
||||
}
|
||||
|
||||
if b.config.SSHUsername == "" {
|
||||
errs = append(errs, errors.New("An ssh_username must be specified"))
|
||||
}
|
||||
|
@ -76,9 +80,6 @@ func (b *Builder) Prepare(raw interface{}) (err error) {
|
|||
return &packer.MultiError{errs}
|
||||
}
|
||||
|
||||
// TODO: config validation and asking for fields:
|
||||
// * region (exists and valid)
|
||||
|
||||
log.Printf("Config: %+v", b.config)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ func testConfig() map[string]interface{} {
|
|||
"secret_key": "bar",
|
||||
"source_ami": "foo",
|
||||
"instance_type": "foo",
|
||||
"region": "foo",
|
||||
"ssh_username": "root",
|
||||
}
|
||||
}
|
||||
|
@ -83,6 +84,30 @@ func TestBuilderPrepare_InstanceType(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestBuilderPrepare_Region(t *testing.T) {
|
||||
var b Builder
|
||||
config := testConfig()
|
||||
|
||||
// Test good
|
||||
config["region"] = "foo"
|
||||
err := b.Prepare(config)
|
||||
if err != nil {
|
||||
t.Fatalf("should not have error: %s", err)
|
||||
}
|
||||
|
||||
if b.config.Region != "foo" {
|
||||
t.Errorf("invalid: %s", b.config.Region)
|
||||
}
|
||||
|
||||
// Test bad
|
||||
delete(config, "region")
|
||||
b = Builder{}
|
||||
err = b.Prepare(config)
|
||||
if err == nil {
|
||||
t.Fatal("should have error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuilderPrepare_SecretKey(t *testing.T) {
|
||||
var b Builder
|
||||
config := testConfig()
|
||||
|
|
Loading…
Reference in New Issue