dao_test.go 978 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package dao
  2. import (
  3. "flag"
  4. "os"
  5. "strings"
  6. "testing"
  7. "go-common/app/admin/main/coupon/conf"
  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.coupon-admin")
  16. flag.Set("conf_appid", "main.account.coupon-admin")
  17. flag.Set("conf_token", "9b7cd88bef452958c66efec00a334d4d")
  18. flag.Set("tree_id", "38771")
  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/coupon-admin.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. }