Skip to content

Commit 40a09cc

Browse files
committed
add test for rate limit
1 parent 8e8d299 commit 40a09cc

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

data.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type IRData interface {
1010
IsLoggedIn() bool
1111
GetLoginExpiration() time.Time
1212

13+
RateLimit() *RateLimit
1314
Car() DataCar
1415
CarClass() DataCarClass
1516
Constant() DataConstant
@@ -50,6 +51,10 @@ func (d *irdata) GetLoginExpiration() time.Time {
5051
return d.expiration
5152
}
5253

54+
func (d *irdata) RateLimit() *RateLimit {
55+
return d.rateLimit
56+
}
57+
5358
func (d *irdata) get(url string) (resp *http.Response, err error) {
5459
if err = d.Reauthenticate(); err != nil {
5560
return nil, err

ratelimit_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package irdata
2+
3+
import (
4+
"github.com/stretchr/testify/assert"
5+
"testing"
6+
"time"
7+
)
8+
9+
func TestRateLimitUpdates(t *testing.T) {
10+
api := DefaultClient.Season()
11+
assert.NotNil(t, api)
12+
13+
_, err := api.RaceGuide()
14+
assert.Nil(t, err)
15+
16+
rl := DefaultClient.RateLimit()
17+
assert.NotNil(t, rl)
18+
19+
remaining := rl.Remaining()
20+
total := rl.TotalLimit()
21+
reset := rl.ResetAt()
22+
23+
assert.True(t, reset.After(time.Now()))
24+
25+
_, err = api.RaceGuide()
26+
assert.Nil(t, err)
27+
28+
assert.NotEqual(t, remaining, total, "remaining rate limit should not be equal to total")
29+
assert.NotEqual(t, rl.Remaining(), remaining, "remaining rate limit should not be equal to remaining on previous request")
30+
assert.True(t, reset.After(time.Now()))
31+
}

0 commit comments

Comments
 (0)