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.

53 satır
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. }
  14. func AssertEqual(t *testing.T, a interface{}, b interface{}, message string) {
  15. if a == b {
  16. return
  17. }
  18. if len(message) == 0 {
  19. message = fmt.Sprintf("%v != %v", a, b)
  20. }
  21. message = fmt.Sprintf("%s : %s", MyCaller(), message)
  22. t.Fatal(message)
  23. }
  24. func TestDummy(t *testing.T) {
  25. t.Log("Testing common field")
  26. }
  27. // MyCaller returns the caller of the function that called it :)
  28. func MyCaller() string {
  29. // we get the callers as uintptrs - but we just need 1
  30. fpcs := make([]uintptr, 1)
  31. // skip 3 levels to get to the caller of whoever called Caller()
  32. n := runtime.Callers(3, fpcs)
  33. if n == 0 {
  34. return "n/a" // proper error her would be better
  35. }
  36. // get the info of the actual function that's in the pointer
  37. fun := runtime.FuncForPC(fpcs[0] - 1)
  38. if fun == nil {
  39. return "n/a"
  40. }
  41. // return its name
  42. return fun.Name()
  43. }