-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstats_test.go
66 lines (51 loc) · 1.6 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
package listennotes
import (
"net/http"
"testing"
)
func TestParseStatsGoodValues(t *testing.T) {
headers := http.Header{}
headers.Set(ResponseHeaderKeyFreeQuota, "10")
headers.Set(ResponseHeaderKeyUsage, "11")
headers.Set(ResponseHeaderKeyLatencySeconds, "12.3")
headers.Set(ResponseHeaderKeyNextBillingDate, "2020-09-26T17:27:33.110641+00:00")
resp := &http.Response{
Header: headers,
}
stats := parseStats(resp)
if stats.FreeQuota != 10 {
t.Errorf("FreeQuota did not parse correctly: %v", stats.FreeQuota)
}
if stats.Usage != 11 {
t.Errorf("Usage did not parse correctly: %v", stats.Usage)
}
if stats.LatencySeconds != 12.3 {
t.Errorf("LatencySeconds did not parse correctly: %v", stats.LatencySeconds)
}
if stats.NextBillingDate.Month() != 9 {
t.Errorf("NextBillingDate did not parse correctly: %v", stats.NextBillingDate)
}
}
func TestParseStatsBadValues(t *testing.T) {
headers := http.Header{}
headers.Set(ResponseHeaderKeyFreeQuota, "a")
headers.Set(ResponseHeaderKeyUsage, "b")
headers.Set(ResponseHeaderKeyLatencySeconds, "c")
headers.Set(ResponseHeaderKeyNextBillingDate, "d")
resp := &http.Response{
Header: headers,
}
stats := parseStats(resp)
if stats.FreeQuota != 0 {
t.Errorf("FreeQuota did not parse correctly: %v", stats.FreeQuota)
}
if stats.Usage != 0 {
t.Errorf("Usage did not parse correctly: %v", stats.Usage)
}
if stats.LatencySeconds != 0 {
t.Errorf("LatencySeconds did not parse correctly: %v", stats.LatencySeconds)
}
if !stats.NextBillingDate.IsZero() {
t.Errorf("NextBillingDate did not parse correctly: %v", stats.NextBillingDate)
}
}