Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

53 lines
1.3KB

  1. package main
  2. import (
  3. "encoding/json"
  4. "io/ioutil"
  5. "os"
  6. "testing"
  7. )
  8. //get accesstoken from wechat server or local cache file
  9. func TestAccessToken(t *testing.T) {
  10. token, err := GetAccessToken()
  11. if err != nil {
  12. t.Error("Cannot get AccessToken From Tencent Wechat Server")
  13. }
  14. AssertEqual(t, token, WechatAccessToken.AccessToken, "Global accesstoken is not uptodate")
  15. }
  16. //save token to a file and read it back
  17. func TestTokenStorage(t *testing.T) {
  18. var s AuthToken
  19. s.AccessToken = "s0wf65p-KMzvYtH8qPu2qSX_EXLE2NaBgFHl7MZwedc7Kv_hdO0FG1QeUmBYJAGmQqJinPwFr67MRZwJee4rDnGVwhbuIfKs29N4ZJSXFP8fbAheuas08UuRe13UsdCtWSMcAFAGCW"
  20. s.ExpireIn = 7200
  21. msg, _ := json.Marshal(s)
  22. file, _ := ioutil.TempFile(os.TempDir(), "wechat_token_")
  23. defer os.Remove(file.Name())
  24. writeTokenToFile([]byte(msg), file.Name())
  25. token, _ := readTokenFromFile(file.Name())
  26. AssertEqual(t, s, token, "read token should be correct")
  27. }
  28. //read config, make sure its not empty
  29. func TestReadConfig(t *testing.T) {
  30. if APIConfig.AppSecret == "" {
  31. t.Error("AppSecret not available")
  32. }
  33. if APIConfig.Appid == "" {
  34. t.Error("AppId not available")
  35. }
  36. if APIConfig.AuthTokenSaveTo == "" {
  37. t.Error("where to save accesstoken is unknown")
  38. }
  39. if APIConfig.EncodingAESKey == "" {
  40. t.Error("unknown AesEncryptionKey")
  41. }
  42. if APIConfig.Token == "" {
  43. t.Error("hidden shared secret token is empty")
  44. }
  45. }