-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstats_test.go
153 lines (107 loc) · 3.44 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// Copyright 2019 nic.at GmbH. All rights reserved.
//
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package rc0go
import (
"encoding/json"
"fmt"
"net/http"
"reflect"
"testing"
)
func TestZoneStatsService_Magnitude(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
wantMagnitude := &Magnitude{
Magnitude: "4.2",
Date: "2018-3-2",
}
_json, _ := json.Marshal([]interface{}{wantMagnitude})
mux.HandleFunc(RC0ZoneStatsMagnitude, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
_, _ = fmt.Fprint(w, string(_json))
})
gotMagnitudes, err := client.ZoneStats.Magnitude("testzone1.at")
if err != nil {
t.Errorf("ZoneStats.Magnitude returned error: %v", err)
}
if magCount := len(gotMagnitudes); magCount != 1 {
t.Errorf("ZoneStats.Magnitude returned %v magnitudes instead of 1", magCount)
}
if !reflect.DeepEqual(gotMagnitudes[0], wantMagnitude) {
t.Errorf("ZoneStats.Magnitude returned %+v, want %+v", gotMagnitudes[0], wantMagnitude)
}
}
func TestZoneStatsService_NXDomains(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
wantNXDomains := &NXDomain{
Type: "A",
Count: 2034555,
Name: "wwww.testzone1.at.",
}
_json, _ := json.Marshal([]interface{}{wantNXDomains})
mux.HandleFunc(RC0ZoneStatsNXDomains, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
_, _ = fmt.Fprint(w, string(_json))
})
gotNXDomains, err := client.ZoneStats.NXDomains("testzone1.at")
if err != nil {
t.Errorf("ZoneStats.NXDomains returned error: %v", err)
}
if nxdCount := len(gotNXDomains); nxdCount != 1 {
t.Errorf("ZoneStats.NXDomains returned %v nxdomains instead of 1", nxdCount)
}
if !reflect.DeepEqual(gotNXDomains[0], wantNXDomains) {
t.Errorf("ZoneStats.NXDomains returned %+v, want %+v", gotNXDomains[0], wantNXDomains)
}
}
func TestZoneStatsService_QNames(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
wantQName := &Query{
Name: "wwww.testzone1.at.",
Type: "A",
Count: 2034555,
}
_json, _ := json.Marshal([]interface{}{wantQName})
mux.HandleFunc(RC0ZoneStatsQNames, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
_, _ = fmt.Fprint(w, string(_json))
})
gotQNames, err := client.ZoneStats.QNames("testzone1.at")
if err != nil {
t.Errorf("ZoneStats.QNames returned error: %v", err)
}
if qnCount := len(gotQNames); qnCount != 1 {
t.Errorf("ZoneStats.QNames returned %v qnames instead of 1", qnCount)
}
if !reflect.DeepEqual(gotQNames[0], wantQName) {
t.Errorf("ZoneStats.QNames returned %+v, want %+v", gotQNames[0], wantQName)
}
}
func TestZoneStatsService_Queries(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
wantQueries := &PerDay{
Date: "2018-3-25",
Queries: 312355,
NXDomains: 2132,
}
_json, _ := json.Marshal([]interface{}{wantQueries})
mux.HandleFunc(RC0ZoneStatsQueries, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
_, _ = fmt.Fprint(w, string(_json))
})
gotQueries, err := client.ZoneStats.Queries("testzone1.at")
if err != nil {
t.Errorf("ZoneStats.Queries returned error: %v", err)
}
if qCount := len(gotQueries); qCount != 1 {
t.Errorf("ZoneStats.Queries returned %v queries instead of 1", qCount)
}
if !reflect.DeepEqual(gotQueries[0], wantQueries) {
t.Errorf("ZoneStats.Queries returned %+v, want %+v", gotQueries[0], wantQueries)
}
}