dao_test.go 989 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package dao
  2. import (
  3. "flag"
  4. "go-common/app/admin/main/usersuit/conf"
  5. "os"
  6. "strings"
  7. "testing"
  8. gock "gopkg.in/h2non/gock.v1"
  9. )
  10. var (
  11. d *Dao
  12. )
  13. func TestMain(m *testing.M) {
  14. if os.Getenv("DEPLOY_ENV") != "" {
  15. flag.Set("app_id", "main.account.usersuit-admin")
  16. flag.Set("conf_appid", "main.account.usersuit-admin")
  17. flag.Set("conf_token", "DJOLMyoiZhqTIrk0r9zGrhewXiBMirIH")
  18. flag.Set("tree_id", "6814")
  19. flag.Set("conf_version", "docker-1")
  20. flag.Set("deploy_env", "uat")
  21. flag.Set("conf_env", "10")
  22. flag.Set("conf_host", "config.bilibili.co")
  23. flag.Set("conf_path", "/tmp")
  24. flag.Set("region", "sh")
  25. flag.Set("zone", "sh001")
  26. } else {
  27. flag.Set("conf", "../cmd/usersuit-admin-test.toml")
  28. }
  29. flag.Parse()
  30. if err := conf.Init(); err != nil {
  31. panic(err)
  32. }
  33. d = New(conf.Conf)
  34. d.client.SetTransport(gock.DefaultTransport)
  35. os.Exit(m.Run())
  36. }
  37. func httpMock(method, url string) *gock.Request {
  38. r := gock.New(url)
  39. r.Method = strings.ToUpper(method)
  40. return r
  41. }