-
Notifications
You must be signed in to change notification settings - Fork 7
/
profiles_test.go
159 lines (113 loc) · 5.12 KB
/
profiles_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
154
155
156
157
158
159
// profiles_test.go
package minecraft
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestProfiles(t *testing.T) {
// This will also effectively test GetUUID
Convey("Test GetAPIProfile", t, func() {
Convey("clone1018 should match d9135e082f2244c89cb0bee234155292", func() {
apiProfile, err := mcProd.GetAPIProfile("clone1018")
So(err, ShouldBeNil)
So(apiProfile.UUID, ShouldEqual, "d9135e082f2244c89cb0bee234155292")
})
Convey("CLone1018 should equal clone1018", func() {
apiProfile, err := mcProd.GetAPIProfile("CLone1018")
So(err, ShouldBeNil)
So(apiProfile.Username, ShouldEqual, "clone1018")
})
Convey("skmkj88200aklk should gracefully error", func() {
apiProfile, err := mcProd.GetAPIProfile("skmkj88200aklk")
So(err, ShouldNotBeNil)
So(err.Error(), ShouldEqual, "unable to GetAPIProfile: user not found")
So(apiProfile, ShouldResemble, APIProfileResponse{})
})
Convey("bad_string/ should cause an HTTP error", func() {
apiProfile, err := mcProd.GetAPIProfile("bad_string/")
So(err, ShouldNotBeNil)
So(err.Error(), ShouldEqual, "unable to GetAPIProfile: apiRequest HTTP 404 Not Found")
So(apiProfile, ShouldResemble, APIProfileResponse{})
})
})
// Must be careful to not request same profile from session server more than once per ~30 seconds
Convey("Test GetSessionProfile", t, func() {
Convey("5c115ca73efd41178213a0aff8ef11e0 should equal LukeHandle", func() {
// LukeHandle
sessionProfile, err := mcProd.GetSessionProfile("5c115ca73efd41178213a0aff8ef11e0")
So(err, ShouldBeNil)
So(sessionProfile.Username, ShouldEqual, "LukeHandle")
})
Convey("bad_string/ should cause an HTTP error", func() {
sessionProfile, err := mcProd.GetSessionProfile("bad_string/")
So(err, ShouldNotBeNil)
So(err.Error(), ShouldEqual, "unable to GetSessionProfile: apiRequest HTTP 404 Not Found")
So(sessionProfile, ShouldResemble, SessionProfileResponse{})
})
})
// Test a lot of what we did above, but this is a wrapper function that includes
// common logic for solving the issues of being supplied with UUID and
// Usernames and returning a uniform response (UUID of certain format)
Convey("Test NormalizePlayerForUUID", t, func() {
Convey("clone1018 should match d9135e082f2244c89cb0bee234155292", func() {
playerUUID, err := mcProd.NormalizePlayerForUUID("clone1018")
So(err, ShouldBeNil)
So(playerUUID, ShouldEqual, "d9135e082f2244c89cb0bee234155292")
})
Convey("CLone1018 should match d9135e082f2244c89cb0bee234155292", func() {
playerUUID, err := mcProd.NormalizePlayerForUUID("clone1018")
So(err, ShouldBeNil)
So(playerUUID, ShouldEqual, "d9135e082f2244c89cb0bee234155292")
})
Convey("d9135e08-2f22-44c8-9cb0-bee234155292 should match d9135e082f2244c89cb0bee234155292", func() {
playerUUID, err := mcProd.NormalizePlayerForUUID("d9135e082f2244c89cb0bee234155292")
So(err, ShouldBeNil)
So(playerUUID, ShouldEqual, "d9135e082f2244c89cb0bee234155292")
})
Convey("d9135e082f2244c89cb0bee234155292 should match d9135e082f2244c89cb0bee234155292", func() {
playerUUID, err := mcProd.NormalizePlayerForUUID("d9135e082f2244c89cb0bee234155292")
So(err, ShouldBeNil)
So(playerUUID, ShouldEqual, "d9135e082f2244c89cb0bee234155292")
})
Convey("skmkj88200aklk should gracefully error", func() {
playerUUID, err := mcProd.NormalizePlayerForUUID("skmkj88200aklk")
So(err, ShouldNotBeNil)
So(err.Error(), ShouldEqual, "unable to GetAPIProfile: user not found")
So(playerUUID, ShouldBeBlank)
})
Convey("TooLongForAUsername should gracefully error", func() {
playerUUID, err := mcProd.NormalizePlayerForUUID("TooLongForAUsername")
So(err, ShouldNotBeNil)
So(err.Error(), ShouldEqual, "unable to NormalizePlayerForUUID due to invalid Username/UUID")
So(playerUUID, ShouldBeBlank)
})
})
Convey("Test Profile Rate Limit detection", t, func() {
Convey("GetAPIProfile should detect Rate Limit", func() {
apiProfile, err := mcTest.GetAPIProfile("RateLimitAPI")
So(err, ShouldNotBeNil)
So(err.Error(), ShouldEqual, "unable to GetAPIProfile: rate limited")
So(apiProfile, ShouldResemble, APIProfileResponse{})
})
Convey("GetSessionProfile should detect Rate Limit", func() {
sessionProfile, err := mcTest.GetSessionProfile("00000000000000000000000000000001")
So(err, ShouldNotBeNil)
So(err.Error(), ShouldEqual, "unable to GetSessionProfile: rate limited")
So(sessionProfile, ShouldResemble, SessionProfileResponse{})
})
})
Convey("Test Profile Bad JSON", t, func() {
Convey("GetAPIProfile should error decoding", func() {
apiProfile, err := mcTest.GetAPIProfile("MalformedAPI")
So(err, ShouldNotBeNil)
So(err.Error(), ShouldEqual, "decoding GetAPIProfile failed: unexpected EOF")
So(apiProfile, ShouldResemble, APIProfileResponse{})
})
Convey("GetSessionProfile should error decoding", func() {
sessionProfile, err := mcTest.GetSessionProfile("00000000000000000000000000000003")
So(err, ShouldNotBeNil)
So(err.Error(), ShouldEqual, "decoding GetSessionProfile failed: unexpected EOF")
So(sessionProfile, ShouldResemble, SessionProfileResponse{})
})
})
}