-
Notifications
You must be signed in to change notification settings - Fork 3
/
stats_test.go
105 lines (87 loc) · 1.98 KB
/
stats_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
package gosnowth
import (
"context"
"net/http"
"net/http/httptest"
"net/url"
"strings"
"testing"
)
const statsTestData = `{
"application": {
"_type": "s",
"_value": "snowth"
},
"identity": {
"_type": "s",
"_value": "bb6f7162-4828-11df-bab8-6bac200dcc2a"
},
"version": {
"_type": "s",
"_value": "v52bcc96a9a1a41acd96352b9b63e59cba2b6a8a9\/65ab82cb7281e76e96b2fedafdc6594d50437d91"
},
"topology": {
"next": {
"_type": "s",
"_value": "-"
},
"current": {
"_type": "s",
"_value": "294cbd39999c2270964029691e8bc5e231a867d525ccba62181dc8988ff218dc"
}
},
"semver": {
"_type": "s",
"_value": "0.1.1570000000"
}
}`
func TestGetStats(t *testing.T) {
t.Parallel()
ms := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter,
r *http.Request,
) {
if r.RequestURI == "/state" {
_, _ = w.Write([]byte(stateTestData))
return
}
if r.RequestURI == "/stats.json" {
_, _ = w.Write([]byte(statsTestData))
return
}
if strings.HasPrefix(r.RequestURI, "/find/1/tags?query=test") {
_, _ = w.Write([]byte(tagsTestData))
return
}
}))
defer ms.Close()
sc, err := NewClient(context.Background(),
&Config{Servers: []string{ms.URL}})
if err != nil {
t.Fatal("Unable to create snowth client", err)
}
u, err := url.Parse(ms.URL)
if err != nil {
t.Fatal("Invalid test URL")
}
node := &SnowthNode{url: u}
res, err := sc.GetStats(node)
if err != nil {
t.Fatal(err)
}
exp := "bb6f7162-4828-11df-bab8-6bac200dcc2a"
if res.Identity() != exp {
t.Errorf("Expected identity: %v, got: %v", exp, res.Identity())
}
exp = "0.1.1570000000"
if res.SemVer() != exp {
t.Errorf("Expected version: %v, got: %v", exp, res.SemVer())
}
exp = "294cbd39999c2270964029691e8bc5e231a867d525ccba62181dc8988ff218dc"
if res.CurrentTopology() != exp {
t.Errorf("Expected current: %v, got: %v", exp, res.CurrentTopology())
}
exp = "-"
if res.NextTopology() != exp {
t.Errorf("Expected next: %v, got: %v", exp, res.NextTopology())
}
}