dao_test.go 915 B

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