Bläddra i källkod

Test case for accessToken

master
Patrick Peng Sun 8 år sedan
förälder
incheckning
933ec2fb8d
1 ändrade filer med 49 tillägg och 0 borttagningar
  1. +49
    -0
      accessToken_test.go

+ 49
- 0
accessToken_test.go Visa fil

@@ -0,0 +1,49 @@
package main

import (
"encoding/json"
"io/ioutil"
"os"
"testing"
)

func TestAccessToken(t *testing.T) {
readConfig()
token, err := GetAccessToken()
if err != nil {
t.Error("Cannot get AccessToken From Tencent Wechat Server")
}

AssertEqual(t, token, WechatAccessToken.AccessToken, "Global accesstoken is not uptodate")
}

func TestTokenStorage(t *testing.T) {
var s AuthToken
s.AccessToken = "s0wf65p-KMzvYtH8qPu2qSX_EXLE2NaBgFHl7MZwedc7Kv_hdO0FG1QeUmBYJAGmQqJinPwFr67MRZwJee4rDnGVwhbuIfKs29N4ZJSXFP8fbAheuas08UuRe13UsdCtWSMcAFAGCW"
s.ExpireIn = 7200
msg, _ := json.Marshal(s)
file, _ := ioutil.TempFile(os.TempDir(), "wechat_token_")
defer os.Remove(file.Name())
writeTokenToFile([]byte(msg), file.Name())
token, _ := readTokenFromFile(file.Name())
AssertEqual(t, s, token, "read token should be correct")
}

func TestReadConfig(t *testing.T) {
readConfig()
if APIConfig.AppSecret == "" {
t.Error("AppSecret not available")
}
if APIConfig.Appid == "" {
t.Error("AppId not available")
}
if APIConfig.AuthTokenSaveTo == "" {
t.Error("where to save accesstoken is unknown")
}
if APIConfig.EncodingAESKey == "" {
t.Error("unknown AesEncryptionKey")
}
if APIConfig.Token == "" {
t.Error("hidden shared secret token is empty")
}
}

Laddar…
Avbryt
Spara