-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathleague_rule_test.go
73 lines (62 loc) · 1.87 KB
/
league_rule_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
package poeapi
import "testing"
func TestGetLeagueRule(t *testing.T) {
c := client{
host: testHost,
useSSL: false,
useCache: false,
limiter: newRateLimiter(UnlimitedRate, UnlimitedRate),
httpClient: testClient,
}
opts := GetLeagueRuleOptions{ID: "TurboMonsters"}
_, err := c.GetLeagueRule(opts)
if err != nil {
t.Fatalf("failed to get league rule: %v", err)
}
}
func TestGetLeagueRuleWithInvalidOptions(t *testing.T) {
c := client{
host: testHost,
useSSL: false,
useCache: false,
limiter: newRateLimiter(UnlimitedRate, UnlimitedRate),
httpClient: testClient,
}
opts := GetLeagueRuleOptions{ID: ""}
_, err := c.GetLeagueRule(opts)
if err != ErrInvalidLeagueRuleID {
t.Fatal("failed to detect invalid league rule option in league rule request")
}
}
func TestParseLeagueRuleResponse(t *testing.T) {
resp, err := loadFixture("fixtures/league-rule.json")
if err != nil {
t.Fatalf("failed to read fixture for league rule test: %v", err)
}
_, err = parseLeagueRuleResponse(resp)
if err != nil {
t.Fatalf("failed to parse league rule response: %v", err)
}
}
func TestParseLeagueRuleResponseWithInvalidJSON(t *testing.T) {
resp, err := loadFixture("fixtures/invalid.json")
if err != nil {
t.Fatalf("failed to read fixture for league rule test: %v", err)
}
_, err = parseLeagueRuleResponse(resp)
if err == nil {
t.Fatal("failed to detect invalid league rule json")
}
}
func TestValidateLeagueRuleOptions(t *testing.T) {
opts := GetLeagueRuleOptions{ID: "test"}
if err := validateLeagueRuleOptions(opts); err != nil {
t.Fatalf("failed to validate league rule options: %v", err)
}
}
func TestValidateLeagueRuleOptionsWithInvalidID(t *testing.T) {
opts := GetLeagueRuleOptions{ID: ""}
if err := validateLeagueRuleOptions(opts); err != ErrInvalidLeagueRuleID {
t.Fatal("failed to detect invalid league rule option")
}
}