packer-cn/clone/config_test.go

71 lines
1.7 KiB
Go
Raw Normal View History

package clone
2017-06-12 14:08:25 -04:00
import (
"testing"
"time"
)
2018-01-24 13:52:29 -05:00
func TestCloneConfig_MinimalConfig(t *testing.T) {
2017-06-12 14:08:25 -04:00
_, warns, errs := NewConfig(minimalConfig())
testConfigOk(t, warns, errs)
}
2018-01-24 13:52:29 -05:00
func TestCloneConfig_MandatoryParameters(t *testing.T) {
2017-07-01 21:18:46 -04:00
params := []string{"vcenter_server", "username", "password", "template", "vm_name", "host"}
for _, param := range params {
raw := minimalConfig()
raw[param] = ""
_, warns, err := NewConfig(raw)
testConfigErr(t, param, warns, err)
}
}
2018-01-24 13:52:29 -05:00
func TestCloneConfig_Timeout(t *testing.T) {
2017-06-12 14:08:25 -04:00
raw := minimalConfig()
raw["shutdown_timeout"] = "3m"
conf, warns, err := NewConfig(raw)
testConfigOk(t, warns, err)
2017-07-01 20:06:02 -04:00
if conf.ShutdownConfig.Timeout != 3 * time.Minute {
t.Fatalf("shutdown_timeout sould be equal 3 minutes, got %v", conf.ShutdownConfig.Timeout)
2017-06-12 14:08:25 -04:00
}
}
2018-01-24 13:52:29 -05:00
func TestCloneConfig_RAMReservation(t *testing.T) {
2017-07-01 17:50:01 -04:00
raw := minimalConfig()
raw["RAM_reservation"] = 1000
raw["RAM_reserve_all"] = true
_, warns, err := NewConfig(raw)
2017-07-01 21:18:46 -04:00
testConfigErr(t, "RAM_reservation", warns, err)
2017-07-01 17:50:01 -04:00
}
2017-06-12 14:08:25 -04:00
func minimalConfig() map[string]interface{} {
return map[string]interface{}{
"vcenter_server": "vcenter.domain.local",
2017-06-12 14:08:25 -04:00
"username": "root",
"password": "vmware",
"template": "ubuntu",
"vm_name": "vm1",
"host": "esxi1.domain.local",
"ssh_username": "root",
"ssh_password": "secret",
}
}
func testConfigOk(t *testing.T, warns []string, err error) {
if len(warns) > 0 {
2017-07-01 21:18:46 -04:00
t.Error("Should be no warnings: %#v", warns)
2017-06-12 14:08:25 -04:00
}
if err != nil {
2017-07-01 21:18:46 -04:00
t.Error("Unexpected error: %s", err)
2017-06-12 14:08:25 -04:00
}
}
2017-07-01 21:18:46 -04:00
func testConfigErr(t *testing.T, context string, warns []string, err error) {
2017-06-12 14:08:25 -04:00
if len(warns) > 0 {
2017-07-01 21:18:46 -04:00
t.Error("Should be no warnings: %#v", warns)
2017-06-12 14:08:25 -04:00
}
if err == nil {
2017-07-01 21:18:46 -04:00
t.Error("An error is not raised for", context)
2017-06-12 14:08:25 -04:00
}
}