-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcloudsigma_test.go
143 lines (118 loc) · 3.97 KB
/
cloudsigma_test.go
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package cloudsigma
import (
"testing"
"github.com/docker/machine/libmachine/drivers"
"github.com/stretchr/testify/assert"
)
func TestCloudsigma_SetConfigFromFlags_emptyPassword(t *testing.T) {
driver := NewDriver("default", "path")
checkFlags := &drivers.CheckDriverOptions{
FlagsValues: map[string]interface{}{
"cloudsigma-username": "[email protected]",
},
CreateFlags: driver.GetCreateFlags(),
}
err := driver.SetConfigFromFlags(checkFlags)
assert.Error(t, err)
}
func TestCloudsigma_SetConfigFromFlags_emptyUsername(t *testing.T) {
driver := NewDriver("default", "path")
checkFlags := &drivers.CheckDriverOptions{
FlagsValues: map[string]interface{}{
"cloudsigma-password": "password",
},
CreateFlags: driver.GetCreateFlags(),
}
err := driver.SetConfigFromFlags(checkFlags)
assert.Error(t, err)
}
func TestCloudsigma_SetConfigFromFlags(t *testing.T) {
driver := NewDriver("default", "path")
checkFlags := &drivers.CheckDriverOptions{
FlagsValues: map[string]interface{}{
"cloudsigma-password": "password",
"cloudsigma-username": "[email protected]",
},
CreateFlags: driver.GetCreateFlags(),
}
err := driver.SetConfigFromFlags(checkFlags)
assert.NoError(t, err)
assert.Empty(t, checkFlags.InvalidFlags)
assert.Equal(t, driver.ResolveStorePath("id_rsa"), driver.GetSSHKeyPath())
}
func TestCloudsigma_SetConfigFromFlags_CustomSSHUserAndPort(t *testing.T) {
driver := NewDriver("default", "path")
checkFlags := &drivers.CheckDriverOptions{
FlagsValues: map[string]interface{}{
"cloudsigma-password": "password",
"cloudsigma-ssh-port": 2222,
"cloudsigma-ssh-user": "ssh_user",
"cloudsigma-username": "[email protected]",
},
CreateFlags: driver.GetCreateFlags(),
}
err := driver.SetConfigFromFlags(checkFlags)
assert.NoError(t, err)
sshPort, err := driver.GetSSHPort()
assert.Equal(t, "ssh_user", driver.GetSSHUsername())
assert.Equal(t, 2222, sshPort)
assert.NoError(t, err)
}
func TestCloudsigma_SetConfigFromFlags_CustomServerParameter(t *testing.T) {
driver := NewDriver("default", "path")
checkFlags := &drivers.CheckDriverOptions{
FlagsValues: map[string]interface{}{
"cloudsigma-api-location": "wdc",
"cloudsigma-cpu": 1500,
"cloudsigma-drive-name": "",
"cloudsigma-drive-size": 15,
"cloudsigma-drive-uuid": "generated-uuid",
"cloudsigma-memory": 512,
"cloudsigma-password": "password",
"cloudsigma-static-ip": "192.168.0.1",
"cloudsigma-username": "[email protected]",
},
CreateFlags: driver.GetCreateFlags(),
}
err := driver.SetConfigFromFlags(checkFlags)
assert.NoError(t, err)
assert.Equal(t, "wdc", driver.APILocation)
assert.Equal(t, 1500, driver.CPU)
assert.Equal(t, "", driver.DriveName)
assert.Equal(t, 15, driver.DriveSize)
assert.Equal(t, "generated-uuid", driver.DriveUUID)
assert.Equal(t, 512, driver.Memory)
assert.Equal(t, "192.168.0.1", driver.StaticIP)
}
func TestCloudsigma_SetConfigFromFlags_ExclusiveOptions(t *testing.T) {
driver := NewDriver("default", "path")
checkFlags := &drivers.CheckDriverOptions{
FlagsValues: map[string]interface{}{
"cloudsigma-drive-name": "debian",
"cloudsigma-drive-uuid": "generated-uuid",
"cloudsigma-password": "password",
"cloudsigma-username": "[email protected]",
},
CreateFlags: driver.GetCreateFlags(),
}
err := driver.SetConfigFromFlags(checkFlags)
assert.Error(t, err)
}
func TestCloudsigma_PreCreateCheck_InvalidIPAddress(t *testing.T) {
driver := NewDriver("default", "path")
checkFlags := &drivers.CheckDriverOptions{
FlagsValues: map[string]interface{}{
"cloudsigma-password": "password",
"cloudsigma-static-ip": "999.999.888.777",
"cloudsigma-username": "[email protected]",
},
CreateFlags: driver.GetCreateFlags(),
}
_ = driver.SetConfigFromFlags(checkFlags)
err := driver.PreCreateCheck()
assert.Error(t, err)
}
func TestCloudsigma_DriverName(t *testing.T) {
driver := NewDriver("default", "path")
assert.Equal(t, "cloudsigma", driver.DriverName())
}