2018-01-26 17:27:18 -05:00
|
|
|
package classic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2018-03-30 16:01:48 -04:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2018-01-26 17:27:18 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func testConfig() map[string]interface{} {
|
|
|
|
return map[string]interface{}{
|
2018-01-31 13:47:19 -05:00
|
|
|
"identity_domain": "abc12345",
|
|
|
|
"username": "test@hashicorp.com",
|
|
|
|
"password": "testpassword123",
|
|
|
|
"api_endpoint": "https://api-test.compute.test.oraclecloud.com/",
|
|
|
|
"dest_image_list": "/Config-thing/myuser/myimage",
|
|
|
|
"source_image_list": "/oracle/public/whatever",
|
|
|
|
"shape": "oc3",
|
|
|
|
"image_name": "TestImageName",
|
|
|
|
"ssh_username": "opc",
|
2018-01-26 17:27:18 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigAutoFillsSourceList(t *testing.T) {
|
|
|
|
tc := testConfig()
|
2019-12-17 05:25:56 -05:00
|
|
|
var conf Config
|
|
|
|
err := conf.Prepare(tc)
|
2018-01-26 17:27:18 -05:00
|
|
|
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",
|
2018-01-31 13:47:19 -05:00
|
|
|
"dest_image_list",
|
|
|
|
"source_image_list",
|
2018-01-26 17:27:18 -05:00
|
|
|
"shape",
|
2019-03-29 18:05:51 -04:00
|
|
|
"ssh_username",
|
2018-01-26 17:27:18 -05:00
|
|
|
}
|
|
|
|
for _, key := range required {
|
|
|
|
tc := testConfig()
|
|
|
|
delete(tc, key)
|
2019-12-17 05:25:56 -05:00
|
|
|
var c Config
|
|
|
|
err := c.Prepare(tc)
|
2018-01-26 17:27:18 -05:00
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("Test should have failed when config lacked %s!", key)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-30 16:01:48 -04:00
|
|
|
func TestConfigValidatesObjects(t *testing.T) {
|
|
|
|
var objectTests = []struct {
|
|
|
|
object string
|
|
|
|
valid bool
|
|
|
|
}{
|
|
|
|
{"foo-BAR.0_9", true},
|
|
|
|
{"%", false},
|
|
|
|
{"Matt...?", false},
|
|
|
|
{"/Config-thing/myuser/myimage", true},
|
|
|
|
}
|
2018-04-02 14:12:07 -04:00
|
|
|
for _, s := range []string{"dest_image_list", "image_name"} {
|
|
|
|
for _, tt := range objectTests {
|
|
|
|
tc := testConfig()
|
|
|
|
tc[s] = tt.object
|
2019-12-17 05:25:56 -05:00
|
|
|
var c Config
|
|
|
|
err := c.Prepare(tc)
|
2018-04-02 14:12:07 -04:00
|
|
|
if tt.valid {
|
|
|
|
assert.NoError(t, err, tt.object)
|
|
|
|
} else {
|
|
|
|
assert.Error(t, err, tt.object)
|
|
|
|
}
|
2018-03-30 16:01:48 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|