-
Notifications
You must be signed in to change notification settings - Fork 5
/
clusters_test.go
126 lines (119 loc) · 3.2 KB
/
clusters_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
package remy
import (
"encoding/json"
"fmt"
"testing"
)
var singleCluster = `{
"body": {
"item": {
"name": "mycluster1",
"servers": [
{
"name": "ms1",
"state": "RUNNING",
"health": "OK",
"clusterMaster": false,
"dropOutFrequency": "Never",
"resendRequestsCount": 0,
"fragmentsSentCount": 3708,
"fragmentsReceivedCount": 3631
},
{
"name": "ms2",
"state": "RUNNING",
"health": "OK"
}
]
}
},
"messages": []
}`
func TestUnmarshalSingleCluster(t *testing.T) {
wrapper, err := unmarshalWrapper([]byte(singleCluster))
if err != nil {
t.Error(err)
}
var cluster Cluster
if err := json.Unmarshal(wrapper.Body.Item, &cluster); err != nil {
t.Error(err)
}
if len(cluster.Servers) == 0 {
t.Errorf("Servers in wrapper.Body.Item is 0, should be 2")
}
var serversJSONTests = []struct {
in string
out string
}{
{cluster.Name, "mycluster1"},
{cluster.Servers[0].Name, "ms1"},
{cluster.Servers[0].State, "RUNNING"},
{cluster.Servers[0].Health, "OK"},
{fmt.Sprint(cluster.Servers[0].IsClusterMaster), "false"},
{cluster.Servers[0].DropOutFrequency, "Never"},
{fmt.Sprint(cluster.Servers[0].ResendRequestsCount), "0"},
{fmt.Sprint(cluster.Servers[0].FragmentsSentCount), "3708"},
{fmt.Sprint(cluster.Servers[0].FragmentsReceivedCount), "3631"},
{cluster.Servers[1].Name, "ms2"},
{cluster.Servers[1].State, "RUNNING"},
{cluster.Servers[1].Health, "OK"},
{cluster.Servers[1].DropOutFrequency, ""},
}
for _, tt := range serversJSONTests {
if tt.in != tt.out {
t.Errorf("want %q, got %q", tt.out, tt.in)
}
}
}
var clusters = `{
"body": {
"items": [
{
"name": "mycluster1",
"servers": [
{
"name": "ms1",
"state": "RUNNING",
"health": "HEALTH_OK"
},
{
"name": "ms2",
"state": "RUNNING",
"health": "HEALTH_OVERLOADED"
}
]
}
]
},
"messages": []
}`
func TestUnmarshalMultipleClusters(t *testing.T) {
wrapper, err := unmarshalWrapper([]byte(clusters))
if err != nil {
t.Error(err)
}
var clusters []Cluster
if err := json.Unmarshal(wrapper.Body.Items, &clusters); err != nil {
t.Error(err)
}
if len(clusters) == 0 {
t.Errorf("Clusters count should be 1, was 0")
}
var serversJSONTests = []struct {
in string
out string
}{
{clusters[0].Name, "mycluster1"},
{clusters[0].Servers[0].Name, "ms1"},
{clusters[0].Servers[0].State, "RUNNING"},
{clusters[0].Servers[0].Health, "HEALTH_OK"},
{clusters[0].Servers[1].Name, "ms2"},
{clusters[0].Servers[1].State, "RUNNING"},
{clusters[0].Servers[1].Health, "HEALTH_OVERLOADED"},
}
for _, tt := range serversJSONTests {
if tt.in != tt.out {
t.Errorf("want %q, got %q", tt.out, tt.in)
}
}
}