access_token_test.go 596 B

123456789101112131415161718192021222324252627282930
  1. package context
  2. import (
  3. "sync"
  4. "testing"
  5. )
  6. func TestContext_SetCustomAccessTokenFunc(t *testing.T) {
  7. ctx := Context{
  8. accessTokenLock: new(sync.RWMutex),
  9. }
  10. f := func(ctx *Context) (accessToken string, err error) {
  11. return "fake token", nil
  12. }
  13. ctx.SetGetAccessTokenFunc(f)
  14. res, err := ctx.GetAccessToken()
  15. if res != "fake token" || err != nil {
  16. t.Error("expect fake token but error")
  17. }
  18. }
  19. func TestContext_NoSetCustomAccessTokenFunc(t *testing.T) {
  20. ctx := Context{
  21. accessTokenLock: new(sync.RWMutex),
  22. }
  23. if ctx.accessTokenFunc != nil {
  24. t.Error("error accessTokenFunc")
  25. }
  26. }