Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

74 lines
1.5KB

  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "os"
  6. "runtime"
  7. "testing"
  8. )
  9. func TestMain(m *testing.M) {
  10. log.Println("global setup for all test cases ... ")
  11. SetupConfig()
  12. code := m.Run()
  13. //Shutdown
  14. log.Println("global shutdown for all test cases ... ")
  15. os.Exit(code)
  16. }
  17. func SetupConfig() {
  18. APIConfig = WechatAPIConfig{
  19. "skdq8vklaurfqemfszuif",
  20. "cmtWK2teRnLOXyO5dw7lJkETv9jCeNAqYyguEu5D8gG",
  21. "wx876e233fde456b7b",
  22. "4a91aa328569b10a9fb97adeb8b0af58",
  23. "/tmp/wechat_hitxy_token",
  24. "gh_f09231355c68"}
  25. CRMConfig = EspoCRMAPIConfig{
  26. "https://c.hitxy.org.au/",
  27. "wechat",
  28. "crmwechat.api",
  29. "/tmp/"}
  30. GlobalPath = PathsConfig{"/tmp"}
  31. KFUsers.kfRenewList()
  32. }
  33. func AssertEqual(t *testing.T, a interface{}, b interface{}, message string) {
  34. if a == b {
  35. return
  36. }
  37. if len(message) == 0 {
  38. message = fmt.Sprintf("%v != %v", a, b)
  39. }
  40. message = fmt.Sprintf("%s : %s", MyCaller(), message)
  41. t.Fatal(message)
  42. }
  43. func TestDummy(t *testing.T) {
  44. t.Log("Testing common field")
  45. }
  46. // MyCaller returns the caller of the function that called it :)
  47. func MyCaller() string {
  48. // we get the callers as uintptrs - but we just need 1
  49. fpcs := make([]uintptr, 1)
  50. // skip 3 levels to get to the caller of whoever called Caller()
  51. n := runtime.Callers(3, fpcs)
  52. if n == 0 {
  53. return "n/a" // proper error her would be better
  54. }
  55. // get the info of the actual function that's in the pointer
  56. fun := runtime.FuncForPC(fpcs[0] - 1)
  57. if fun == nil {
  58. return "n/a"
  59. }
  60. // return its name
  61. return fun.Name()
  62. }