dao_test.go 903 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package weeklyhonor
  2. import (
  3. "flag"
  4. "os"
  5. "testing"
  6. "go-common/app/interface/main/creative/conf"
  7. "github.com/golang/mock/gomock"
  8. )
  9. var (
  10. d *Dao
  11. )
  12. func TestMain(m *testing.M) {
  13. if os.Getenv("DEPLOY_ENV") != "" {
  14. flag.Set("app_id", "main.archive.creative")
  15. flag.Set("conf_token", "96b6a6c10bb311e894c14a552f48fef8")
  16. flag.Set("tree_id", "2305")
  17. flag.Set("conf_version", "docker-1")
  18. flag.Set("deploy_env", "uat")
  19. flag.Set("conf_host", "config.bilibili.co")
  20. flag.Set("conf_path", "/tmp")
  21. flag.Set("region", "sh")
  22. flag.Set("zone", "sh001")
  23. } else {
  24. flag.Set("conf", "../../cmd/creative.toml")
  25. }
  26. flag.Parse()
  27. if err := conf.Init(); err != nil {
  28. panic(err)
  29. }
  30. d = New(conf.Conf)
  31. m.Run()
  32. os.Exit(0)
  33. }
  34. func WithMock(t *testing.T, f func(mock *gomock.Controller)) func() {
  35. return func() {
  36. mockCtrl := gomock.NewController(t)
  37. defer mockCtrl.Finish()
  38. f(mockCtrl)
  39. }
  40. }