dao_test.go 1001 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package goblin
  2. import (
  3. "flag"
  4. "os"
  5. "strings"
  6. "go-common/app/interface/main/tv/conf"
  7. . "github.com/smartystreets/goconvey/convey"
  8. "gopkg.in/h2non/gock.v1"
  9. )
  10. var d *Dao
  11. func init() {
  12. //dir, _ := filepath.Abs("../../cmd/tv-interface.toml")
  13. //flag.Set("conf", dir)
  14. if os.Getenv("DEPLOY_ENV") != "" {
  15. flag.Set("app_id", "main.web-svr.tv-interface")
  16. flag.Set("conf_token", "07c1826c1f39df02a1411cdd6f455879")
  17. flag.Set("tree_id", "15326")
  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. }
  25. flag.Parse()
  26. if err := conf.Init(); err != nil {
  27. panic(err)
  28. }
  29. d = New(conf.Conf)
  30. }
  31. func WithDao(f func(d *Dao)) func() {
  32. return func() {
  33. Reset(func() {})
  34. f(d)
  35. }
  36. }
  37. func httpMock(method, url string) *gock.Request {
  38. r := gock.New(url)
  39. r.Method = strings.ToUpper(method)
  40. d.client.SetTransport(gock.DefaultTransport)
  41. return r
  42. }