-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhighscores_test.go
96 lines (69 loc) · 2.37 KB
/
highscores_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
package Go_Runescape
import (
"testing"
"strconv"
"github.com/kingpulse/Go-Runescape/highscore_constants"
"net/http"
)
//TestPlayerHighScores is some basic tests to check if the player information is being correctly downloaded.
//(Primarily to test CI to be honest).
//Player names that are passed in as parameters to the GetPlayerHighscores function are
//#1 players as of 30/01/2018
func TestPlayerHighScores(t *testing.T) {
//Creating http client to use for requests
testClient := http.DefaultClient
/*
TESTING RS3 Player
*/
hs, err := GetPlayerHighscores("le me", highscore_constants.RS3PLAYER, testClient)
levelsCheck(t, hs, "RS3")
if err != nil {
t.Error("Failed to GetPlayerHighscores. Error: " + err.Error())
}
/*
TESTING OSRS Player
*/
hs, err = GetPlayerHighscores("Lynx Titan", highscore_constants.OSRSPLAYER, testClient)
levelsCheck(t, hs, "OSRS")
if err != nil {
t.Error("Failed to GetPlayerHighscores. Error: " + err.Error())
}
//Testing failure during GET()
failureGetClient := failGetHttpClient{}
_, err = GetPlayerHighscores("Lynx Titan", highscore_constants.OSRSPLAYER, failureGetClient)
if err == nil {
t.Error("GetPlayerHighscores failed to return errors from GET request.")
}
}
func levelsCheck(t *testing.T, hs PlayerHighscores, playerType string) {
if hs.Levels == nil || hs.Ranks == nil || hs.XP == nil {
t.Error("Failed to get " + playerType + " player highscore_constants object.")
}
//Checking that levels are correct.
for _, val := range hs.Levels {
if val < 99 {
t.Error("Incorrect levels are being grabbed for " + playerType + " players.")
}
}
}
func TestPlayerRanks(t *testing.T) {
//Creating default http client to send requests.
testClient := http.DefaultClient
strengthRankings, err := GetRankings(highscore_constants.STRENGTH, 0, 5, testClient)
if err != nil {
t.Error("Failed to get player rankings for strength.")
}
if strengthRankings[0].Rank != strconv.Itoa(1) {
t.Error("Failed to get top player ranking in strength.")
}
failureClient := failGetHttpClient{}
_, err = GetRankings(highscore_constants.STRENGTH, 0, 5, failureClient)
if err == nil {
t.Error("GetRankings failed to return errors from GET request.")
}
ijClient := invalidJsonHttpClient{}
_, err = GetRankings(highscore_constants.STRENGTH, 0, 5, ijClient)
if err == nil {
t.Error("GetRaknings failed to recognise json errors.")
}
}