-
Notifications
You must be signed in to change notification settings - Fork 1
/
nx_test.go
81 lines (73 loc) · 1.69 KB
/
nx_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
package nx
import (
"fmt"
"github.com/joho/godotenv"
"os"
"reflect"
"testing"
)
func init() {
if err := godotenv.Load(); err != nil {
panic(err)
}
}
// TestSystemStatus tests Nx System Status retrieval
func TestSystemStatus(t *testing.T) {
settings := Settings{
Protocol: getEnv("NX_PROTOCOL", ""),
Host: getEnv("NX_HOST", ""),
Name: getEnv("NX_NANE", ""),
User: getEnv("NX_USER", ""),
Pin: getEnv("NX_PIN", ""),
URL: getEnv("NX_PROTOCOL", "") + "://" +
getEnv("NX_HOST", "") + "/",
}
nx := NewAlarm(settings)
data, err := nx.SystemStatus()
if err != nil {
fmt.Println(err)
return
}
v := reflect.ValueOf(data.System)
if v.Kind() == reflect.Ptr {
v = v.Elem()
}
typeOfS := v.Type()
for i := 0; i < v.NumField(); i++ {
fmt.Printf("Field: %10s\tValue: %10v\n", typeOfS.Field(i).Name,
v.Field(i).Interface())
}
}
func TestZoneSatus(t *testing.T) {
settings := Settings{
Protocol: getEnv("NX_PROTOCOL", ""),
Host: getEnv("NX_HOST", ""),
Name: getEnv("NX_NANE", ""),
User: getEnv("NX_USER", ""),
Pin: getEnv("NX_PIN", ""),
URL: getEnv("NX_PROTOCOL", "") + "://" +
getEnv("NX_HOST", "") + "/",
}
nx := NewAlarm(settings)
data, err := nx.ZonesStatus()
if err != nil {
fmt.Println(err)
return
}
//zone names
for i, v := range data.Zones.Names {
zone := i + 1
status := ""
if i < len(data.Zones.Status) {
status = fmt.Sprintf("%+v", data.Zones.Status[i])
}
fmt.Println("zone: ", zone, v, "\t\t", status)
}
}
// returns Environment (string) variable or default value
func getEnv(key string, defaultVal string) string {
if value, exists := os.LookupEnv(key); exists {
return value
}
return defaultVal
}