forked from zabbix-tools/go-zabbix
-
Notifications
You must be signed in to change notification settings - Fork 2
/
session_test.go
50 lines (39 loc) · 885 Bytes
/
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
package zabbix
import (
"os"
"testing"
)
var session *Session
func GetTestCredentials() (username string, password string, url string) {
url = os.Getenv("ZBX_URL")
if url == "" {
url = "http://localhost:8080/api_jsonrpc.php"
}
username = os.Getenv("ZBX_USERNAME")
if username == "" {
username = "Admin"
}
password = os.Getenv("ZBX_PASSWORD")
if password == "" {
password = "zabbix"
}
return username, password, url
}
func GetTestSession(t *testing.T) *Session {
var err error
if session == nil {
username, password, url := GetTestCredentials()
session, err = NewSession(url, username, password)
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")
}
}