Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

50 lignes
1.2KB

  1. package main
  2. import (
  3. "encoding/json"
  4. "io/ioutil"
  5. "os"
  6. "testing"
  7. )
  8. func TestAccessToken(t *testing.T) {
  9. readConfig()
  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. func TestTokenStorage(t *testing.T) {
  17. var s AuthToken
  18. s.AccessToken = "s0wf65p-KMzvYtH8qPu2qSX_EXLE2NaBgFHl7MZwedc7Kv_hdO0FG1QeUmBYJAGmQqJinPwFr67MRZwJee4rDnGVwhbuIfKs29N4ZJSXFP8fbAheuas08UuRe13UsdCtWSMcAFAGCW"
  19. s.ExpireIn = 7200
  20. msg, _ := json.Marshal(s)
  21. file, _ := ioutil.TempFile(os.TempDir(), "wechat_token_")
  22. defer os.Remove(file.Name())
  23. writeTokenToFile([]byte(msg), file.Name())
  24. token, _ := readTokenFromFile(file.Name())
  25. AssertEqual(t, s, token, "read token should be correct")
  26. }
  27. func TestReadConfig(t *testing.T) {
  28. readConfig()
  29. if APIConfig.AppSecret == "" {
  30. t.Error("AppSecret not available")
  31. }
  32. if APIConfig.Appid == "" {
  33. t.Error("AppId not available")
  34. }
  35. if APIConfig.AuthTokenSaveTo == "" {
  36. t.Error("where to save accesstoken is unknown")
  37. }
  38. if APIConfig.EncodingAESKey == "" {
  39. t.Error("unknown AesEncryptionKey")
  40. }
  41. if APIConfig.Token == "" {
  42. t.Error("hidden shared secret token is empty")
  43. }
  44. }