diff --git a/common_test.go b/common_test.go new file mode 100644 index 0000000..89a68e3 --- /dev/null +++ b/common_test.go @@ -0,0 +1,29 @@ +package main + +import ( + "fmt" + "testing" +) + +func SetupConfig() { + APIConfig = WechatAPIConfig{ + "skdq8vklaurfqemfszuif", + "cmtWK2teRnLOXyO5dw7lJkETv9jCeNAqYyguEu5D8gG", + "wx876e233fde456b7b", + "4a91aa328569b10a9fb97adeb8b0af58"} +} + +func AssertEqual(t *testing.T, a interface{}, b interface{}, message string) { + if a == b { + return + } + if len(message) == 0 { + message = fmt.Sprintf("%v != %v", a, b) + } + message = fmt.Sprintf("%v != %v", a, b) + t.Fatal(message) +} + +func TestDummy(t *testing.T) { + t.Log("Testing common field") +} diff --git a/encrypt_test.go b/encrypt_test.go index 0a698c4..b111ed3 100644 --- a/encrypt_test.go +++ b/encrypt_test.go @@ -4,14 +4,6 @@ import ( "testing" ) -func SetupConfig() { - APIConfig = WechatAPIConfig{ - "skdq8vklaurfqemfszuif", - "cmtWK2teRnLOXyO5dw7lJkETv9jCeNAqYyguEu5D8gG", - "wx876e233fde456b7b", - "4a91aa328569b10a9fb97adeb8b0af58"} -} - func TestEncodingMesage(t *testing.T) { SetupConfig() diff --git a/inMsg_test.go b/inMsg_test.go index 3a7c7c2..57145a8 100644 --- a/inMsg_test.go +++ b/inMsg_test.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "testing" ) @@ -16,24 +15,13 @@ func TestReadCommonHeader(t *testing.T) { ` h := ReadCommonHeader(msg) - assertEqual(t, h.ToUserName, "gh_f09231355c68", "ToUserName failed") - assertEqual(t, h.FromUserName, "oUN420bxqFqlx0ZQHciUOesZO3PE", "FromUserName failed") - assertEqual(t, h.CreateTime, int64(1492972518), "CreateTime Failed") - assertEqual(t, h.MsgType, "event", "MsgType failed") + AssertEqual(t, h.ToUserName, "gh_f09231355c68", "ToUserName failed") + AssertEqual(t, h.FromUserName, "oUN420bxqFqlx0ZQHciUOesZO3PE", "FromUserName failed") + AssertEqual(t, h.CreateTime, int64(1492972518), "CreateTime Failed") + AssertEqual(t, h.MsgType, "event", "MsgType failed") } -func assertEqual(t *testing.T, a interface{}, b interface{}, message string) { - if a == b { - return - } - if len(message) == 0 { - message = fmt.Sprintf("%v != %v", a, b) - } - message = fmt.Sprintf("%v != %v", a, b) - t.Fatal(message) -} - func TestTxtMsg(t *testing.T) { msg := ` @@ -45,9 +33,9 @@ func TestTxtMsg(t *testing.T) { ` h := ReadCommonHeader(msg) m := ReadTextMsg(msg) - assertEqual(t, m.Content, "this is a test", "Content is not right") - assertEqual(t, h.MsgType, "text", "") - assertEqual(t, m.MsgId, int64(1234567890123456), "") + AssertEqual(t, m.Content, "this is a test", "Content is not right") + AssertEqual(t, h.MsgType, "text", "") + AssertEqual(t, m.MsgId, int64(1234567890123456), "") } /*