2017-06-12 14:08:25 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMinimalConfig(t *testing.T) {
|
|
|
|
_, warns, errs := NewConfig(minimalConfig())
|
|
|
|
testConfigOk(t, warns, errs)
|
|
|
|
}
|
|
|
|
|
2017-07-01 21:18:46 -04:00
|
|
|
func TestMandatoryParameters(t *testing.T) {
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-12 14:08:25 -04:00
|
|
|
func TestTimeout(t *testing.T) {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-01 17:50:01 -04:00
|
|
|
func TestRAMReservation(t *testing.T) {
|
|
|
|
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{}{
|
2017-07-01 11:54:10 -04:00
|
|
|
"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
|
|
|
}
|
|
|
|
}
|