This repository has been archived by the owner on Sep 14, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
zapi_system_test.go
87 lines (63 loc) · 1.57 KB
/
zapi_system_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
package zevenetlb
import (
"os"
"strings"
"testing"
)
func createTestSession(t *testing.T) *ZapiSession {
return createTestSessionEx(t, "")
}
func createTestSessionEx(t *testing.T, apiKey string) *ZapiSession {
// retrieve api key if undefined
if apiKey == "" {
apiKey = os.Getenv("ZAPI_KEY")
if apiKey == "" {
t.Fatal("Failed to retrieve ZAPI key from environment variable ZAPI_KEY")
}
}
// retrieve host name
host := os.Getenv("ZAPI_HOSTNAME")
if host == "" {
host = "lb-cluster.konsorten.net:444"
}
// retrieve api version
zapiVersion := os.Getenv("ZAPI_VERSION")
// create the session
session, err := Connect(host, apiKey, &ConfigOptions{ZapiVersion: zapiVersion})
if err != nil {
t.Fatalf("Failed to connect to Zevenet API: %v", err)
}
return session
}
func TestInvalidHost(t *testing.T) {
_, err := Connect("d0esn0tex1st", "inval1dAp1K3y", nil)
if err == nil {
t.Fatal("Error expected")
}
if !strings.Contains(err.Error(), "no such host") {
t.Fatalf("Wrong error message returned: %v", err)
}
}
func TestPing(t *testing.T) {
session := createTestSession(t)
success, msg := session.Ping()
if !success {
t.Fatalf("Ping failed: %v", msg)
}
}
func TestGetSystemVersion(t *testing.T) {
session := createTestSession(t)
res, err := session.GetSystemVersion()
if err != nil {
t.Fatal(err)
}
t.Logf("Version: %v", res)
}
func TestIsCommunityEdition(t *testing.T) {
session := createTestSession(t)
res, err := session.GetSystemVersion()
if err != nil {
t.Fatal(err)
}
t.Logf("Is Community Edition: %v", res.IsCommunityEdition())
}