forked from neogan74/go-zabbix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession_test.go
63 lines (51 loc) · 1.22 KB
/
session_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
package zabbix
import (
"os"
"strconv"
"testing"
"time"
)
var session *Session
func GetTestCredentials(t *testing.T) (username string, password string, url string, timeout time.Duration) {
url = os.Getenv("ZBX_URL")
if url == "" {
url = "http://192.168.33.11:8040/api_jsonrpc.php"
}
username = os.Getenv("ZBX_USERNAME")
if username == "" {
username = "Admin"
}
password = os.Getenv("ZBX_PASSWORD")
if password == "" {
password = "zabbix"
}
timeoutS := os.Getenv("ZBX_TIMEOUT")
if timeoutS == "" {
timeout = 5 * time.Second
} else {
timeoutI, err := strconv.Atoi(timeoutS)
if err != nil {
t.Fatalf("Error converting ZBX_TIMEOUT to int: %v", err)
}
timeout = time.Duration(timeoutI) * time.Second
}
return username, password, url, timeout
}
func GetTestSession(t *testing.T) *Session {
var err error
if session == nil {
username, password, url, timeout := GetTestCredentials(t)
session, err = NewSession(url, username, password, timeout)
if err != nil {
t.Fatalf("Error creating a session: %v", err)
}
}
return session
}
func TestSession(t *testing.T) {
s := GetTestSession(t)
v, err := s.GetVersion()
if err != nil || v == "" {
t.Errorf("No API version found for session")
}
}