dao_test.go 1013 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package caldiff
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "path/filepath"
  7. "strings"
  8. "go-common/app/job/main/appstatic/conf"
  9. "gopkg.in/h2non/gock.v1"
  10. )
  11. var (
  12. d *Dao
  13. ctx = context.Background()
  14. )
  15. func init() {
  16. if os.Getenv("DEPLOY_ENV") != "" {
  17. flag.Set("app_id", "main.web-svr.appstatic-job")
  18. flag.Set("conf_token", "bb62e0021e8d0c7996ccf1fb8d267cee")
  19. flag.Set("tree_id", "40719")
  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. dir, _ := filepath.Abs("../cmd/appstatic-job-test.toml")
  28. flag.Set("conf", dir)
  29. }
  30. flag.Parse()
  31. if err := conf.Init(); err != nil {
  32. panic(err)
  33. }
  34. d = New(conf.Conf)
  35. d.client.SetTransport(gock.DefaultTransport)
  36. }
  37. func WithDao(f func(d *Dao)) func() {
  38. return func() {
  39. f(d)
  40. }
  41. }
  42. func httpMock(method, url string) *gock.Request {
  43. r := gock.New(url)
  44. r.Method = strings.ToUpper(method)
  45. return r
  46. }