-
Notifications
You must be signed in to change notification settings - Fork 31
/
rate_limits_test.go
53 lines (45 loc) · 1.36 KB
/
rate_limits_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
package stream_chat
import (
"context"
"testing"
"github.com/stretchr/testify/require"
)
func TestClient_GetRateLimits(t *testing.T) {
c := initClient(t)
ctx := context.Background()
t.Run("get all limits", func(t *testing.T) {
limits, err := c.GetRateLimits(ctx)
require.NoError(t, err)
require.NotEmpty(t, limits.Android)
require.NotEmpty(t, limits.Web)
require.NotEmpty(t, limits.IOS)
require.NotEmpty(t, limits.ServerSide)
})
t.Run("get only a single platform", func(t *testing.T) {
limits, err := c.GetRateLimits(ctx, WithServerSide())
require.NoError(t, err)
require.Empty(t, limits.Android)
require.Empty(t, limits.Web)
require.Empty(t, limits.IOS)
require.NotEmpty(t, limits.ServerSide)
})
t.Run("get only a few endpoints", func(t *testing.T) {
limits, err := c.GetRateLimits(ctx,
WithServerSide(),
WithAndroid(),
WithEndpoints(
"GetRateLimits",
"SendMessage",
),
)
require.NoError(t, err)
require.Empty(t, limits.Web)
require.Empty(t, limits.IOS)
require.NotEmpty(t, limits.Android)
require.Len(t, limits.Android, 2)
require.Equal(t, limits.Android["GetRateLimits"].Limit, limits.Android["GetRateLimits"].Remaining)
require.NotEmpty(t, limits.ServerSide)
require.Len(t, limits.ServerSide, 2)
require.Greater(t, limits.ServerSide["GetRateLimits"].Limit, limits.ServerSide["GetRateLimits"].Remaining)
})
}