-
Notifications
You must be signed in to change notification settings - Fork 0
/
profitbricks_test.go
118 lines (98 loc) · 2.74 KB
/
profitbricks_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
package profitbricks
import (
"io/ioutil"
"os"
"testing"
//"github.com/profitbricks/profitbricks-sdk-go"
"fmt"
)
const (
testStoreDir = ".store-test"
machineTestName = "docker machine unit tests public 8"
)
type DriverOptionsMock struct {
Data map[string]interface{}
}
func (d DriverOptionsMock) String(key string) string {
return d.Data[key].(string)
}
func (d DriverOptionsMock) StringSlice(key string) []string {
return d.Data[key].([]string)
}
func (d DriverOptionsMock) Int(key string) int {
return d.Data[key].(int)
}
func (d DriverOptionsMock) Bool(key string) bool {
return d.Data[key].(bool)
}
func cleanup() error {
return os.RemoveAll(testStoreDir)
}
func getTestStorePath() (string, error) {
tmpDir, err := ioutil.TempDir("", "machine-test-")
if err != nil {
return "", err
}
os.Setenv("MACHINE_STORAGE_PATH", tmpDir)
return tmpDir, nil
}
func getDefaultTestDriverFlags() *DriverOptionsMock {
return &DriverOptionsMock{
Data: map[string]interface{}{
"profitbricks-endpoint": "https://api.profitbricks.com/rest/v2",
"profitbricks-user-name": "[email protected]",
"profitbricks-password": "password",
"profitbricks-disk-size": 5,
"profitbricks-image": "Ubuntu-15.10-server-2016-03-01",
"profitbricks-cores": 1,
"profitbricks-ram": 1024,
"profitbricks-location": "us/lasdev",
"profitbricks-ssh-key": `ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCoLVLHON4BSK3D8L4H79aFo+0cj7VM2NiRR/K9wrfkK/XiTc7FlEU4Bs8WLZcsIOxbCGWn2zKZmrLaxYlY+/3aJrxDxXYCy8lRUMnqcQ2JCFY6tpZt/DylPhS9L6qYNpJ0F4FlqRsWxsjpF8TDdJi64k2JFJ8TkvX36P2/kqyFfI+N0/axgjhqV3BgNgApvMt9jxWB5gi8LgDpw9b+bHeMS7TrAVDE7bzT86dmfbTugtiME8cIday8YcRb4xAFgRH8XJVOcE3cs390V/dhgCKy1P5+TjQMjKbFIy2LJoxb7bd38kAl1yafZUIhI7F77i7eoRidKV71BpOZsaPEbWUP jasmin@Jasmins-MBP`,
"swarm-master": true,
"swarm-host": "2",
"swarm-discovery": "3",
},
}
}
func getTestDriver() (*Driver, error) {
storePath, err := getTestStorePath()
if err != nil {
return nil, err
}
defer cleanup()
d := NewDriver(machineTestName, storePath)
/*if err != nil {
return nil, err
}*/
d.SetConfigFromFlags(getDefaultTestDriverFlags())
drv := d.(*Driver)
return drv, nil
}
func TestCreate(t *testing.T) {
d, _ := getTestDriver()
//d.SSHKey, _ = d.createSSHKey("/Users/jasmin/.ssh/id_rsa.pub")
createerr := d.Create()
if createerr != nil {
t.Error(createerr)
}
state, err := d.GetState()
fmt.Println(state)
if err != nil {
t.Error(err)
}
}
func TestGetMachineName(t *testing.T) {
d, _ := getTestDriver()
if d.MachineName == "" {
t.Fatal("Machine name not suplied.")
}
fmt.Println(d.GetMachineName())
}
func TestKill(t *testing.T) {
d, _ := getTestDriver()
d.Kill()
}
func TestRemove(t *testing.T) {
d, _ := getTestDriver()
d.Remove()
}