You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.1KB

  1. package main
  2. import (
  3. "fmt"
  4. "runtime"
  5. "testing"
  6. )
  7. func SetupConfig() {
  8. APIConfig = WechatAPIConfig{
  9. "skdq8vklaurfqemfszuif",
  10. "cmtWK2teRnLOXyO5dw7lJkETv9jCeNAqYyguEu5D8gG",
  11. "wx876e233fde456b7b",
  12. "4a91aa328569b10a9fb97adeb8b0af58",
  13. "wechat_hitxy_access_token",
  14. "gh_f09231355c68"}
  15. }
  16. func AssertEqual(t *testing.T, a interface{}, b interface{}, message string) {
  17. if a == b {
  18. return
  19. }
  20. if len(message) == 0 {
  21. message = fmt.Sprintf("%v != %v", a, b)
  22. }
  23. message = fmt.Sprintf("%s : %s", MyCaller(), message)
  24. t.Fatal(message)
  25. }
  26. func TestDummy(t *testing.T) {
  27. t.Log("Testing common field")
  28. }
  29. // MyCaller returns the caller of the function that called it :)
  30. func MyCaller() string {
  31. // we get the callers as uintptrs - but we just need 1
  32. fpcs := make([]uintptr, 1)
  33. // skip 3 levels to get to the caller of whoever called Caller()
  34. n := runtime.Callers(3, fpcs)
  35. if n == 0 {
  36. return "n/a" // proper error her would be better
  37. }
  38. // get the info of the actual function that's in the pointer
  39. fun := runtime.FuncForPC(fpcs[0] - 1)
  40. if fun == nil {
  41. return "n/a"
  42. }
  43. // return its name
  44. return fun.Name()
  45. }