dao_test.go 905 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package dao
  2. import (
  3. "flag"
  4. "os"
  5. "strings"
  6. "testing"
  7. "go-common/app/service/main/dynamic/conf"
  8. "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.web-svr.dynamic-service")
  16. flag.Set("conf_token", "f7c6b053ef986c6d3c87b4fd69e64ddb")
  17. flag.Set("tree_id", "2316")
  18. flag.Set("conf_version", "docker-1")
  19. flag.Set("deploy_env", "uat")
  20. flag.Set("conf_host", "config.bilibili.co")
  21. flag.Set("conf_path", "/tmp")
  22. flag.Set("region", "sh")
  23. flag.Set("zone", "sh001")
  24. } else {
  25. flag.Set("conf", "../cmd/dynamic-service-test.toml")
  26. }
  27. flag.Parse()
  28. if err := conf.Init(); err != nil {
  29. panic(err)
  30. }
  31. d = New(conf.Conf)
  32. d.httpR.SetTransport(gock.DefaultTransport)
  33. m.Run()
  34. os.Exit(0)
  35. }
  36. func httpMock(method, url string) *gock.Request {
  37. r := gock.New(url)
  38. r.Method = strings.ToUpper(method)
  39. return r
  40. }