user_auth_test.go
1.1 KB
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
package userAuth
import (
"fmt"
"github.com/tiptok/gocomm/pkg/redis"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant"
"testing"
)
func initRedis() {
redisSource := fmt.Sprintf("%v:%v", constant.REDIS_HOST, constant.REDIS_PORT)
err := redis.InitWithDb(100, redisSource, constant.REDIS_AUTH, "0")
if err != nil {
panic(err)
}
}
func TestRedisUserAuth(t *testing.T) {
initRedis()
userAuth := NewRedisUserAuth(WithUserId(1),
WithAccessToken("abc"),
WithRefreshToken("cdf"),
)
err := userAuth.AddAuth()
if err != nil {
t.Fatal(err)
}
_, err = userAuth.GetAuth()
if err != nil {
t.Fatal("get auth", err)
}
if !userAuth.Exist() {
t.Fatal("except:true")
}
if err = userAuth.Check(NewOptions(WithAccessToken("abc"))); err != nil {
t.Fatal("check accessToken:", err)
}
if err = userAuth.Check(NewOptions(WithRefreshToken("cdf"))); err != nil {
t.Fatal("check refreshToken:", err)
}
if err = userAuth.RemoveAuth(); err != nil {
t.Fatal("remove:", err)
}
if userAuth.field() != "1" {
t.Fatal("except:1")
}
if userAuth.Exist() {
t.Fatal("except:false")
}
}