dao_test.go 943 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package pendant
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "strings"
  7. "testing"
  8. "go-common/app/service/main/usersuit/conf"
  9. "gopkg.in/h2non/gock.v1"
  10. )
  11. var (
  12. d *Dao
  13. c = context.Background()
  14. )
  15. func TestMain(m *testing.M) {
  16. if os.Getenv("DEPLOY_ENV") != "" {
  17. flag.Set("app_id", "main.account.usersuit-service")
  18. flag.Set("conf_token", "BVWgBtBvS2pkTBbmxAl0frX6KRA14d5P")
  19. flag.Set("tree_id", "6813")
  20. flag.Set("conf_version", "docker-1")
  21. flag.Set("deploy_env", "uat")
  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/convey-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. m.Run()
  36. os.Exit(0)
  37. }
  38. func httpMock(method, url string) *gock.Request {
  39. r := gock.New(url)
  40. r.Method = strings.ToUpper(method)
  41. return r
  42. }