Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

77 lines
1.6KB

  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. IntraAPIConfig = ConfigIntraAPI{
  31. "cAT/ckkfjajvczxiaufodqdfakpozcczfas341fda.vfasdk/8934125",
  32. }
  33. GlobalPath = PathsConfig{"/tmp"}
  34. KFUsers.kfRenewList()
  35. }
  36. func AssertEqual(t *testing.T, a interface{}, b interface{}, message string) {
  37. if a == b {
  38. return
  39. }
  40. if len(message) == 0 {
  41. message = fmt.Sprintf("%v != %v", a, b)
  42. }
  43. message = fmt.Sprintf("%s : %s", MyCaller(), message)
  44. t.Fatal(message)
  45. }
  46. func TestDummy(t *testing.T) {
  47. t.Log("Testing common field")
  48. }
  49. // MyCaller returns the caller of the function that called it :)
  50. func MyCaller() string {
  51. // we get the callers as uintptrs - but we just need 1
  52. fpcs := make([]uintptr, 1)
  53. // skip 3 levels to get to the caller of whoever called Caller()
  54. n := runtime.Callers(3, fpcs)
  55. if n == 0 {
  56. return "n/a" // proper error her would be better
  57. }
  58. // get the info of the actual function that's in the pointer
  59. fun := runtime.FuncForPC(fpcs[0] - 1)
  60. if fun == nil {
  61. return "n/a"
  62. }
  63. // return its name
  64. return fun.Name()
  65. }