1
0
mirror of https://github.com/silenceper/wechat.git synced 2026-02-09 07:02:27 +08:00

add: 自定义获取 access token 方法

This commit is contained in:
zdpdpdp
2019-05-21 12:47:31 +08:00
parent eae6caadb2
commit 81f26cd6dc
3 changed files with 43 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
package context
import (
"sync"
"testing"
)
func TestContext_SetCustomAccessTokenFunc(t *testing.T) {
ctx := Context{
accessTokenLock: new(sync.RWMutex),
}
f := func(ctx *Context) (accessToken string, err error) {
return "fake token", nil
}
ctx.SetGetAccessTokenFunc(f)
res, err := ctx.GetAccessToken()
if res != "fake token" || err != nil {
t.Error("expect fake token but error")
}
}
func TestContext_NoSetCustomAccessTokenFunc(t *testing.T) {
ctx := Context{
accessTokenLock: new(sync.RWMutex),
}
if ctx.accessTokenFunc != nil {
t.Error("error accessTokenFunc")
}
}