forked from koffeinsource/go-imgur
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rateLimit_test.go
73 lines (57 loc) · 2.24 KB
/
rateLimit_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 imgur
import (
"net/http"
"os"
"testing"
)
func TestRateLimitImgurSimulated(t *testing.T) {
httpC, server := testHTTPClientJSON("{\"success\": true, \"status\": 200 }")
defer server.Close()
client, _ := NewClient(httpC, "testing", "")
rl, err := client.GetRateLimit()
if err != nil {
t.Errorf("GetRateLimit() failed with error: %v", err)
t.FailNow()
}
if rl.ClientLimit != 40 || rl.UserLimit != 10 || rl.UserRemaining != 2 || rl.ClientRemaining != 5 {
client.Log.Debugf("Found ClientLimit: %v and UserLimit: %v", rl.ClientLimit, rl.UserLimit)
t.Error("Client/User limits are wrong. Probably something broken. Or IMGUR changed their limits. Or you are not using a free account for testing. Sorry. No real good way to test this.")
}
}
func TestRateLimitRealRapidAPI(t *testing.T) {
key := os.Getenv("IMGURCLIENTID")
if key == "" {
t.Skip("IMGURCLIENTID environment variable not set.")
}
RapidAPIKey := os.Getenv("RapidAPIKEY")
if RapidAPIKey == "" {
t.Skip("RapidAPIKEY environment variable not set.")
}
client, _ := NewClient(new(http.Client), key, RapidAPIKey)
rl, err := client.GetRateLimit()
if err != nil {
t.Errorf("GetRateLimit() failed with error: %v", err)
t.FailNow()
}
// There seem to be not rate limites when using the paid API
if rl.ClientLimit != 0 || rl.UserLimit != 0 {
client.Log.Debugf("Found ClientLimit: %v and UserLimit: %v", rl.ClientLimit, rl.UserLimit)
t.Error("Client/User limits are wrong. Probably something broken. Or IMGUR changed their limits. Or you are using a free account for testing. Sorry. No real good way to test this.")
}
}
func TestRateLimitRealImgur(t *testing.T) {
key := os.Getenv("IMGURCLIENTID")
if key == "" {
t.Skip("IMGURCLIENTID environment variable not set.")
}
client, _ := NewClient(new(http.Client), key, "")
rl, err := client.GetRateLimit()
if err != nil {
t.Errorf("GetRateLimit() failed with error: %v", err)
t.FailNow()
}
if rl.ClientLimit != 12500 || rl.UserLimit != 500 {
client.Log.Debugf("Found ClientLimit: %v and UserLimit: %v", rl.ClientLimit, rl.UserLimit)
t.Error("Client/User limits are wrong. Probably something broken. Or IMGUR changed their limits. Or you are not using a free account for testing. Sorry. No real good way to test this.")
}
}