package main

import (
	"fmt"
	"runtime"
	"testing"
)

func SetupConfig() {
	APIConfig = WechatAPIConfig{
		"skdq8vklaurfqemfszuif",
		"cmtWK2teRnLOXyO5dw7lJkETv9jCeNAqYyguEu5D8gG",
		"wx876e233fde456b7b",
		"4a91aa328569b10a9fb97adeb8b0af58",
		"/tmp/wechat_hitxy_token",
		"gh_f09231355c68"}

	CRMConfig = EspoCRMAPIConfig{
		"https://c.hitxy.org.au/",
		"wechat",
		"crmwechat.api"}
	GlobalPath = PathsConfig{"/tmp", "/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()
}
