add tests; fix a couple issues caught by said tests
This commit is contained in:
parent
9edd98f7b0
commit
98857c42cf
|
@ -56,6 +56,10 @@ func NewConfig(raws ...interface{}) (*Config, error) {
|
|||
c.SSHSourceList = "seciplist:/oracle/public/public-internet"
|
||||
}
|
||||
|
||||
if c.Comm.SSHUsername == "" {
|
||||
c.Comm.SSHUsername = "opc"
|
||||
}
|
||||
|
||||
// Validate that all required fields are present
|
||||
var errs *packer.MultiError
|
||||
required := map[string]string{
|
||||
|
@ -76,5 +80,9 @@ func NewConfig(raws ...interface{}) (*Config, error) {
|
|||
errs = packer.MultiErrorAppend(errs, es...)
|
||||
}
|
||||
|
||||
if errs != nil && len(errs.Errors) > 0 {
|
||||
return nil, errs
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
package classic
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func testConfig() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"identity_domain": "abc12345",
|
||||
"username": "test@hashicorp.com",
|
||||
"password": "testpassword123",
|
||||
"api_endpoint": "https://api-test.compute.test.oraclecloud.com/",
|
||||
"image_list": "/oracle/public/myimage",
|
||||
"shape": "oc3",
|
||||
"image_name": "TestImageName",
|
||||
"ssh_username": "opc",
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigAutoFillsSourceList(t *testing.T) {
|
||||
tc := testConfig()
|
||||
conf, err := NewConfig(tc)
|
||||
if err != nil {
|
||||
t.Fatalf("Should not have error: %s", err.Error())
|
||||
}
|
||||
if conf.SSHSourceList != "seciplist:/oracle/public/public-internet" {
|
||||
t.Fatalf("conf.SSHSourceList should have been "+
|
||||
"\"seciplist:/oracle/public/public-internet\" but is \"%s\"",
|
||||
conf.SSHSourceList)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigValidationCatchesMissing(t *testing.T) {
|
||||
required := []string{
|
||||
"username",
|
||||
"password",
|
||||
"api_endpoint",
|
||||
"identity_domain",
|
||||
"image_list",
|
||||
"shape",
|
||||
}
|
||||
for _, key := range required {
|
||||
tc := testConfig()
|
||||
delete(tc, key)
|
||||
_, err := NewConfig(tc)
|
||||
if err == nil {
|
||||
t.Fatalf("Test should have failed when config lacked %s!", key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidationsIgnoresOptional(t *testing.T) {
|
||||
tc := testConfig()
|
||||
delete(tc, "ssh_username")
|
||||
_, err := NewConfig(tc)
|
||||
if err != nil {
|
||||
t.Fatalf("Test shouldn't care if ssh_username is missing: err: %#v", err.Error())
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue