forked from chyroc/go-aliyundrive
-
Notifications
You must be signed in to change notification settings - Fork 4
/
aliyundrive_test.go
46 lines (37 loc) · 1.03 KB
/
aliyundrive_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
package aliyundrive
import (
"context"
"github.com/go-redis/redis/v8"
"github.com/mingcheng/aliyundrive/store"
"github.com/stretchr/testify/assert"
"os"
"testing"
)
func NewDrive(t *testing.T) *AliyunDrive {
redisAddr := os.Getenv("REDIS_ADDR")
assert.NotEmpty(t, redisAddr)
client, err := store.NewRedisStore(&redis.Options{
Addr: redisAddr,
})
assert.NoError(t, err)
assert.NotNil(t, client)
// using `JSON.parse(localStorage.token).refresh_token`
// to get token from web browser console
refreshToken, err := client.Get(context.TODO(), KeyRefreshToken)
if err != nil || len(refreshToken) == 0 {
refreshToken = []byte(os.Getenv("REFRESH_TOKEN"))
assert.NotEmpty(t, refreshToken)
}
assert.NotEmpty(t, refreshToken)
cli := New(WithStore(client))
if !cli.IsLogin(context.TODO()) {
token, err := cli.RefreshToken(context.TODO(), &RefreshTokenReq{
RefreshToken: string(refreshToken),
})
assert.NoError(t, err)
assert.NotNil(t, token)
assert.NotEmpty(t, token.RefreshToken)
}
assert.NotNil(t, cli)
return cli
}