dao_test.go 887 B

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