forked from lnxbil/docker-machine-driver-proxmox-ve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testconfig_test.go
77 lines (65 loc) · 1.81 KB
/
testconfig_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
package dockermachinedriverproxmoxve_test
// Test Proxmox VE instance configuration
// as a singleton according to http://marcio.io/2015/07/singleton-pattern-in-go/
import (
"encoding/json"
"io/ioutil"
"log"
"os"
"sync"
"testing"
dockermachinedriverproxmoxve "github.com/lnxbil/docker-machine-driver-proxmox-ve"
)
// ProxmoxConfig represents all needed login information
type ProxmoxConfig struct {
Host string `json:"host"`
User string `json:"user"`
Password string `json:"password"`
Realm string `json:"realm"`
Node string `json:"node"`
}
var instance *ProxmoxConfig
var once sync.Once
// GetProxmoxConfigInstance loads default config
func GetProxmoxConfigInstance() *ProxmoxConfig {
once.Do(func() {
content, err := ioutil.ReadFile("testconfig.json")
if err != nil {
log.Fatal(err)
os.Exit(1)
}
var config ProxmoxConfig
json.Unmarshal(content, &config)
instance = &config
})
return instance
}
// GetProxmoxAccess gets working proxmox ve access information
func GetProxmoxAccess() (string, string, string, string) {
i := GetProxmoxConfigInstance()
return i.User, i.Password, i.Realm, i.Host
}
// GetProxmoxNode return the defined test node
func GetProxmoxNode() string {
i := GetProxmoxConfigInstance()
return i.Node
}
// GetProxmoxRealm return the defined test realm
func GetProxmoxRealm() string {
i := GetProxmoxConfigInstance()
return i.Realm
}
// GetProxmoxHost return the defined test host
func GetProxmoxHost() string {
i := GetProxmoxConfigInstance()
return i.Host
}
// EstablishConnection returns an open and test-checked Proxmox VE API connection
func EstablishConnection(t *testing.T) *dockermachinedriverproxmoxve.ProxmoxVE {
c, err := dockermachinedriverproxmoxve.GetProxmoxVEConnectionByValues(GetProxmoxAccess())
if err != nil {
t.Log(c)
t.Fatal(err)
}
return c
}