package main import ( "fmt" "log" "os" "runtime" "testing" ) func TestMain(m *testing.M) { log.Println("global setup for all test cases ... ") SetupConfig() code := m.Run() //Shutdown log.Println("global shutdown for all test cases ... ") os.Exit(code) } func SetupConfig() { APIConfig = WechatAPIConfig{ "skdq8vklaurfqemfszuif", "cmtWK2teRnLOXyO5dw7lJkETv9jCeNAqYyguEu5D8gG", "wx876e233fde456b7b", "4a91aa328569b10a9fb97adeb8b0af58", "/tmp/wechat_hitxy_token", "gh_f09231355c68"} CRMConfig = EspoCRMAPIConfig{ "https://c.hitxy.org.au/", "wechat", "crmwechat.api", "/tmp/", "http://192.168.1.39:65500/crmcache"} IntraAPIConfig = ConfigIntraAPI{ "cAT/ckkfjajvczxiaufodqdfakpozcczfas341fda.vfasdk/8934125", } GlobalPath = PathsConfig{"/tmp"} KFUsers.kfRenewList() } 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("%s : %s", MyCaller(), message) t.Fatal(message) } func TestDummy(t *testing.T) { t.Log("Testing common field") } // MyCaller returns the caller of the function that called it :) func MyCaller() string { // we get the callers as uintptrs - but we just need 1 fpcs := make([]uintptr, 1) // skip 3 levels to get to the caller of whoever called Caller() n := runtime.Callers(3, fpcs) if n == 0 { return "n/a" // proper error her would be better } // get the info of the actual function that's in the pointer fun := runtime.FuncForPC(fpcs[0] - 1) if fun == nil { return "n/a" } // return its name return fun.Name() }