Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

53 lines
1.4KB

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