forked from docker/machine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
default_test_host.go
78 lines (65 loc) · 1.76 KB
/
default_test_host.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
package hosttest
import (
"github.com/docker/machine/drivers/none"
"github.com/docker/machine/libmachine/auth"
"github.com/docker/machine/libmachine/engine"
"github.com/docker/machine/libmachine/host"
"github.com/docker/machine/libmachine/swarm"
"github.com/docker/machine/libmachine/version"
)
const (
DefaultHostName = "test-host"
HostTestCaCert = "test-cert"
HostTestPrivateKey = "test-key"
)
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 GetTestDriverFlags() *DriverOptionsMock {
flags := &DriverOptionsMock{
Data: map[string]interface{}{
"name": DefaultHostName,
"url": "unix:///var/run/docker.sock",
"swarm": false,
"swarm-host": "",
"swarm-master": false,
"swarm-discovery": "",
},
}
return flags
}
func GetDefaultTestHost() (*host.Host, error) {
hostOptions := &host.Options{
EngineOptions: &engine.Options{},
SwarmOptions: &swarm.Options{},
AuthOptions: &auth.Options{
CaCertPath: HostTestCaCert,
CaPrivateKeyPath: HostTestPrivateKey,
},
}
driver := none.NewDriver(DefaultHostName, "/tmp/artifacts")
host := &host.Host{
ConfigVersion: version.ConfigVersion,
Name: DefaultHostName,
Driver: driver,
DriverName: "none",
HostOptions: hostOptions,
}
flags := GetTestDriverFlags()
if err := host.Driver.SetConfigFromFlags(flags); err != nil {
return nil, err
}
return host, nil
}