-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathconfig_test.go
More file actions
108 lines (97 loc) · 2.63 KB
/
Copy pathconfig_test.go
File metadata and controls
108 lines (97 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// © Broadcom. All Rights Reserved.
// The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
// SPDX-License-Identifier: MPL-2.0
package clone
import (
"strings"
"testing"
"time"
)
func TestCloneConfig_MinimalConfig(t *testing.T) {
c := new(Config)
warns, errs := c.Prepare(minimalConfig())
testConfigOk(t, warns, errs)
}
func TestCloneConfig_MandatoryParameters(t *testing.T) {
params := []string{"vcenter_server", "username", "password", "template", "vm_name", "host"}
for _, param := range params {
raw := minimalConfig()
raw[param] = ""
c := new(Config)
warns, err := c.Prepare(raw)
testConfigErr(t, param, warns, err)
}
}
func TestCloneConfig_Timeout(t *testing.T) {
raw := minimalConfig()
raw["shutdown_timeout"] = "3m"
conf := new(Config)
warns, err := conf.Prepare(raw)
testConfigOk(t, warns, err)
if conf.Timeout != 3*time.Minute {
t.Fatalf("unexpected result: expected '3m', but returned '%v'", conf.Timeout)
}
}
func TestCloneConfig_DisableIpWaitRequiresHost(t *testing.T) {
raw := minimalConfig()
raw["disable_ip_wait"] = true
c := new(Config)
_, err := c.Prepare(raw)
testConfigErr(t, "disable_ip_wait", nil, err)
}
func TestCloneConfig_DisableIpWaitWithSSHHost(t *testing.T) {
raw := minimalConfig()
raw["disable_ip_wait"] = true
raw["ssh_host"] = "192.168.1.10"
c := new(Config)
warns, err := c.Prepare(raw)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
found := false
for _, w := range warns {
if strings.Contains(w, "disable_ip_wait") {
found = true
break
}
}
if !found {
t.Fatalf("expected disable_ip_wait warning, got %#v", warns)
}
}
func TestCloneConfig_RAMReservation(t *testing.T) {
raw := minimalConfig()
raw["RAM_reservation"] = 1000
raw["RAM_reserve_all"] = true
c := new(Config)
warns, err := c.Prepare(raw)
testConfigErr(t, "RAM_reservation", warns, err)
}
func minimalConfig() map[string]interface{} {
return map[string]interface{}{
"vcenter_server": "vc01.example.com",
"username": "administrator@vsphere.local",
"password": "VMw@re1!",
"template": "ubuntu",
"vm_name": "vm-01",
"host": "esx01.example.com",
"ssh_username": "root",
"ssh_password": "VMw@re1!",
}
}
func testConfigOk(t *testing.T, warns []string, err error) {
if len(warns) > 0 {
t.Errorf("unexpected warning: %#v", warns)
}
if err != nil {
t.Errorf("unexpected error: %s", err)
}
}
func testConfigErr(t *testing.T, context string, warns []string, err error) {
if len(warns) > 0 {
t.Errorf("unexpected warning: %#v", warns)
}
if err == nil {
t.Errorf("unexpected result: expected '%s', but returned 'nil'", context)
}
}