-
Notifications
You must be signed in to change notification settings - Fork 5
/
servers_test.go
128 lines (115 loc) · 2.77 KB
/
servers_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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package remy
import (
"encoding/json"
"fmt"
"testing"
)
var serversJSON = `{
"body": {
"items": [
{
"name": "adminserver",
"state": "RUNNING",
"health": " HEALTH_OK "
},
{
"name": "ms1",
"state": "SHUTDOWN",
"health": ""
}
]
},
"messages": [
]
}`
func TestUnmarshalServersJson(t *testing.T) {
wrapper, err := unmarshalWrapper([]byte(serversJSON))
if err != nil {
t.Error(err)
}
t.Log(wrapper)
var servers []Server
err = json.Unmarshal(wrapper.Body.Items, &servers)
if err != nil {
t.Error(err)
}
var serversJSONTests = []struct {
in string
out string
}{
{servers[0].Health, " HEALTH_OK "},
{servers[0].Name, "adminserver"},
{servers[0].State, "RUNNING"},
{servers[1].Name, "ms1"},
{servers[1].State, "SHUTDOWN"},
{servers[1].Health, ""},
}
for _, tt := range serversJSONTests {
if tt.in != tt.out {
t.Errorf("want %q, got %q", tt.out, tt.in)
}
}
}
var singleServer = `{
"body": {
"item": {
"name": "adminserver",
"clusterName": null,
"state": "RUNNING",
"currentMachine": "machine-0",
"weblogicVersion": "WebLogic Server 12.1.1.0.0 Thu May 5 01:17:16 2011 PDT",
"openSocketsCurrentCount": 2,
"health": "HEALTH_OK",
"heapSizeCurrent": 536870912,
"heapFreeCurrent": 39651944,
"heapSizeMax": 1073741824,
"javaVersion": "1.6.0_20",
"osName": "Linux",
"osVersion": "2.6.18-238.0.0.0.1.el5xen",
"jvmProcessorLoad": 0.25
}
},
"messages": [
]
}`
func TestUnmarshalSingleServer(t *testing.T) {
wrapper, err := unmarshalWrapper([]byte(singleServer))
if err != nil {
t.Error(err)
}
var server Server
if err := json.Unmarshal(wrapper.Body.Item, &server); err != nil {
t.Error(err)
}
// t.Log(wrapper)
var serversJSONTests = []struct {
in string
out string
}{
{server.Name, "adminserver"},
{server.ClusterName, ""},
{server.State, "RUNNING"},
{server.CurrentMachine, "machine-0"},
{server.WebLogicVersion, "WebLogic Server 12.1.1.0.0 Thu May 5 01:17:16 2011 PDT"},
{fmt.Sprint(server.OpenSocketsCurrentCount), "2"},
{server.Health, "HEALTH_OK"},
{fmt.Sprint(server.HeapSizeCurrent), "536870912"},
{fmt.Sprint(server.HeapFreeCurrent), "39651944"},
{server.JavaVersion, "1.6.0_20"},
{server.OsName, "Linux"},
{server.OsVersion, "2.6.18-238.0.0.0.1.el5xen"},
{fmt.Sprint(server.JvmProcessorLoad), "0.25"},
}
for _, tt := range serversJSONTests {
if tt.in != tt.out {
t.Errorf("want %q, got %q", tt.out, tt.in)
}
}
}
func TestGoStringerServer(t *testing.T) {
wrapper, _ := unmarshalWrapper([]byte(singleServer))
var server Server
json.Unmarshal(wrapper.Body.Item, &server)
fmt.Printf("%# v", &server)
// pretty.Printf("%# v", server)
}