forked from go-lark/lark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_auth_test.go
53 lines (47 loc) · 1.35 KB
/
api_auth_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 lark
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestAuthAccessTokenInternal(t *testing.T) {
bot := newTestBot()
resp, err := bot.GetAccessTokenInternal(true)
if assert.NoError(t, err) {
assert.Equal(t, 0, resp.Code)
assert.NotEmpty(t, resp.AppAccessToken)
t.Log(resp.AppAccessToken)
assert.NotEmpty(t, resp.Expire)
}
}
func TestAuthTenantAccessTokenInternal(t *testing.T) {
bot := newTestBot()
resp, err := bot.GetTenantAccessTokenInternal(true)
if assert.NoError(t, err) {
assert.Equal(t, 0, resp.Code)
assert.NotEmpty(t, resp.TenantAppAccessToken)
t.Log(resp.TenantAppAccessToken)
assert.NotEmpty(t, resp.Expire)
}
}
func TestHeartbeat(t *testing.T) {
bot := newTestBot()
assert.Nil(t, bot.heartbeat)
assert.Nil(t, bot.startHeartbeat(time.Second*1))
assert.NotEmpty(t, bot.tenantAccessToken)
assert.Equal(t, int64(1), bot.heartbeatCounter)
time.Sleep(2 * time.Second)
assert.Equal(t, int64(2), bot.heartbeatCounter)
bot.StopHeartbeat()
time.Sleep(2 * time.Second)
assert.Equal(t, int64(2), bot.heartbeatCounter)
// restart heartbeat
assert.Nil(t, bot.startHeartbeat(time.Second*1))
time.Sleep(2 * time.Second)
assert.Equal(t, int64(4), bot.heartbeatCounter)
}
func TestInvalidHeartbeat(t *testing.T) {
bot := NewNotificationBot("")
err := bot.StartHeartbeat()
assert.Error(t, err, ErrBotTypeError)
}