-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpvp_matches_test.go
101 lines (89 loc) · 2.31 KB
/
pvp_matches_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
package poeapi
import (
"log"
"testing"
)
func TestGetPVPMatches(t *testing.T) {
c := client{
host: testHost,
useSSL: false,
useCache: false,
limiter: newRateLimiter(UnlimitedRate, UnlimitedRate),
httpClient: testClient,
}
_, err := c.GetPVPMatches(GetPVPMatchesOptions{
Type: "season",
Season: "EUPvPSeason1",
Realm: "pc",
})
if err != nil {
t.Fatalf("failed to get pvp matches: %v", err)
}
}
func TestValidateGetPVPMatchesOptions(t *testing.T) {
opts := GetPVPMatchesOptions{
Type: "season",
Season: "EUPvPSeason1",
Realm: "pc",
}
if err := validateGetPVPMatchesOptions(opts); err != nil {
log.Fatalf("failed to validate pvp options: %v", err)
}
}
func TestValidateGetPVPMatchesOptionsWithInvalidSeason(t *testing.T) {
opts := GetPVPMatchesOptions{
Type: "season",
Season: "",
Realm: "pc",
}
if err := validateGetPVPMatchesOptions(opts); err != ErrInvalidSeason {
log.Fatal("failed to detect invalid pvp season")
}
}
func TestValidateGetPVPMatchesOptionsWithInvalidRealm(t *testing.T) {
opts := GetPVPMatchesOptions{
Type: "season",
Season: "EUPvPSeason1",
Realm: "toaster",
}
if err := validateGetPVPMatchesOptions(opts); err != ErrInvalidRealm {
log.Fatal("failed to detect invalid pvp realm")
}
}
func TestGetPVPMatchesWithInvalidOptions(t *testing.T) {
c := client{
host: testHost,
useSSL: false,
useCache: false,
limiter: newRateLimiter(UnlimitedRate, UnlimitedRate),
httpClient: testClient,
}
_, err := c.GetPVPMatches(GetPVPMatchesOptions{
Type: "season",
Season: "",
Realm: "pc",
})
if err != ErrInvalidSeason {
t.Fatal("failed to detect invalid season in pvp matches test")
}
}
func TestParsePVPMatchesResponse(t *testing.T) {
resp, err := loadFixture("fixtures/pvp-matches.json")
if err != nil {
t.Fatalf("failed to read fixture for pvp matches test: %v", err)
}
_, err = parsePVPMatchesResponse(resp)
if err != nil {
t.Fatalf("failed to parse pvp matches response: %v", err)
}
}
func TestParsePVPMatchesResponseWithInvalidJSON(t *testing.T) {
resp, err := loadFixture("fixtures/invalid.json")
if err != nil {
t.Fatalf("failed to read fixture for pvp matches test: %v", err)
}
_, err = parsePVPMatchesResponse(resp)
if err == nil {
t.Fatal("failed to detect invalid pvp matches json")
}
}