-
Notifications
You must be signed in to change notification settings - Fork 227
/
Test.go
58 lines (48 loc) · 1.04 KB
/
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
package api_test
import (
"crypto/tls"
pxapi "github.com/Telmate/proxmox-api-go/proxmox"
)
type Test struct {
APIurl string
UserID string
Password string
OTP string
HttpHeaders string
RequireSSL bool
_client *pxapi.Client
}
func (test *Test) CreateClient() (err error) {
if test.APIurl == "" {
test.APIurl = "https://127.0.0.1:8006/api2/json"
}
if test.UserID == "" {
test.UserID = "root@pam"
}
if test.Password == "" {
test.Password = "root"
}
tlsConfig := &tls.Config{InsecureSkipVerify: true}
if test.RequireSSL {
tlsConfig = nil
}
test._client, err = pxapi.NewClient(test.APIurl, nil, test.HttpHeaders, tlsConfig, "", 300)
return err
}
func (test *Test) GetClient() (client *pxapi.Client) {
return test._client
}
func (test *Test) Login() (err error) {
if test._client == nil {
err = test.CreateClient()
if err != nil {
return err
}
}
err = test._client.Login(test.UserID, test.Password, test.OTP)
return err
}
func (test *Test) CreateTest() (err error) {
err = test.Login()
return err
}