-
Notifications
You must be signed in to change notification settings - Fork 3
/
rackhd_test.go
129 lines (98 loc) · 2.91 KB
/
rackhd_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
package rackhd
import (
"testing"
"github.com/docker/machine/libmachine/drivers"
"github.com/stretchr/testify/assert"
)
func TestDriverName(t *testing.T) {
// create the Driver
d := NewDriver("default", "path")
if "rackhd" != d.DriverName() {
t.FailNow()
}
}
func testSetDefaults(t *testing.T) {
// create the Driver
d := NewDriver("default", "path")
checkFlags := &drivers.CheckDriverOptions{
FlagsValues: map[string]interface{}{
"rackhd-sku-id": "aabbccdd",
},
CreateFlags: d.GetCreateFlags(),
}
err := d.SetConfigFromFlags(checkFlags)
assert.NoError(t, err)
assert.Empty(t, checkFlags.InvalidFlags)
assert.Equal(t, "http", d.Transport)
assert.Equal(t, "root", d.SSHUser)
assert.Equal(t, "root", d.SSHPassword)
assert.Equal(t, 22, d.SSHPort)
// Not part of the default, but check to see that it's set
assert.Equal(t, "aabbccdd", d.SkuID)
}
func TestSetEndpoint(t *testing.T) {
// create the Driver
d := NewDriver("default", "path")
checkFlags := &drivers.CheckDriverOptions{
FlagsValues: map[string]interface{}{
"rackhd-endpoint": "localhost:9090",
"rackhd-node-id": "aabbccdd",
},
CreateFlags: d.GetCreateFlags(),
}
err := d.SetConfigFromFlags(checkFlags)
assert.NoError(t, err)
assert.Empty(t, checkFlags.InvalidFlags)
assert.Equal(t, "localhost:9090", d.Endpoint)
}
func TestNodeOrSkuIDRequired(t *testing.T) {
// create the Driver
d := NewDriver("default", "path")
checkFlags := &drivers.CheckDriverOptions{
FlagsValues: map[string]interface{}{
"rackhd-endpoint": "localhost:9090",
},
CreateFlags: d.GetCreateFlags(),
}
err := d.SetConfigFromFlags(checkFlags)
assert.Error(t, err, "Should error if no SKU or Node ID is given")
}
func TestOnlyNodeOrSkuIDAllowed(t *testing.T) {
// create the Driver
d := NewDriver("default", "path")
checkFlags := &drivers.CheckDriverOptions{
FlagsValues: map[string]interface{}{
"rackhd-node-id": "aabbccdd",
"rackhd-sku-id": "eeffgghh",
},
CreateFlags: d.GetCreateFlags(),
}
err := d.SetConfigFromFlags(checkFlags)
assert.Error(t, err, "Should error if both SKU and Node ID is given")
}
func TestOnlyNodeOrSkuNameAllowed(t *testing.T) {
// create the Driver
d := NewDriver("default", "path")
checkFlags := &drivers.CheckDriverOptions{
FlagsValues: map[string]interface{}{
"rackhd-node-id": "aabbccdd",
"rackhd-sku-name": "test sku",
},
CreateFlags: d.GetCreateFlags(),
}
err := d.SetConfigFromFlags(checkFlags)
assert.Error(t, err, "Should error if both SKU Name and Node ID are given")
}
func TestOnlySkuNameOrSkuIDAllowed(t *testing.T) {
// create the Driver
d := NewDriver("default", "path")
checkFlags := &drivers.CheckDriverOptions{
FlagsValues: map[string]interface{}{
"rackhd-sku-id": "aabbccdd",
"rackhd-sku-name": "test sku",
},
CreateFlags: d.GetCreateFlags(),
}
err := d.SetConfigFromFlags(checkFlags)
assert.Error(t, err, "Should error if both SKU Name and ID are given")
}