dao_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package datadao
  2. import (
  3. "flag"
  4. "net/http"
  5. "os"
  6. "testing"
  7. "go-common/app/interface/main/mcn/conf"
  8. "go-common/app/interface/main/mcn/dao/global"
  9. "gopkg.in/h2non/gock.v1"
  10. )
  11. var (
  12. d *Dao
  13. )
  14. func TestMain(m *testing.M) {
  15. if os.Getenv("DEPLOY_ENV") != "" {
  16. flag.Set("app_id", "main.archive.mcn-interface")
  17. flag.Set("conf_token", "49e4671bafbf93059aeb602685052ca0")
  18. flag.Set("tree_id", "58909")
  19. flag.Set("conf_version", "docker-1")
  20. flag.Set("deploy_env", "uat")
  21. flag.Set("conf_host", "config.bilibili.co")
  22. flag.Set("conf_path", "/tmp")
  23. flag.Set("region", "sh")
  24. flag.Set("zone", "sh001")
  25. } else {
  26. flag.Set("conf", "../../cmd/mcn-interface.toml")
  27. }
  28. if os.Getenv("UT_LOCAL_TEST") != "" {
  29. flag.Set("conf", "../../cmd/mcn-interface.toml")
  30. }
  31. flag.Parse()
  32. if err := conf.Init(); err != nil {
  33. panic(err)
  34. }
  35. global.Init(conf.Conf)
  36. d = New(conf.Conf)
  37. d.Client.SetTransport(gock.DefaultTransport)
  38. var result = `{
  39. "code": 200,
  40. "msg": "success",
  41. "result": [ ]
  42. }`
  43. gock.New("http://berserker.bilibili.co/avenger/api").Get("/").AddMatcher(
  44. func(request *http.Request, request2 *gock.Request) (bool, error) {
  45. return true, nil
  46. }).Persist().Reply(200).JSON(result)
  47. defer gock.OffAll()
  48. os.Exit(m.Run())
  49. }
  50. // func httpMock(method, url string) *gock.Request {
  51. // r := gock.New(url)
  52. // r.Method = strings.ToUpper(method)
  53. // return r
  54. // }