dao_test.go 974 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package manager
  2. import (
  3. "context"
  4. "flag"
  5. . "github.com/smartystreets/goconvey/convey"
  6. "go-common/app/admin/main/videoup/conf"
  7. "os"
  8. "testing"
  9. )
  10. var (
  11. d *Dao
  12. )
  13. func WithDao(f func(d *Dao)) func() {
  14. return func() {
  15. Reset(func() {})
  16. f(d)
  17. }
  18. }
  19. func TestPing(t *testing.T) {
  20. Convey("Ping", t, WithDao(func(d *Dao) {
  21. err := d.Ping(context.TODO())
  22. So(err, ShouldBeNil)
  23. }))
  24. }
  25. func TestMain(m *testing.M) {
  26. if os.Getenv("DEPLOY_ENV") != "" {
  27. flag.Set("app_id", "main.archive.videoup-admin")
  28. flag.Set("conf_token", "gRSfeavV7kJdY9875Gf29pbd2wrdKZ1a")
  29. flag.Set("tree_id", "2307")
  30. flag.Set("conf_version", "docker-1")
  31. flag.Set("deploy_env", "uat")
  32. flag.Set("conf_host", "config.bilibili.co")
  33. flag.Set("conf_path", "/tmp")
  34. flag.Set("region", "sh")
  35. flag.Set("zone", "sh001")
  36. } else {
  37. flag.Set("conf", "../../cmd/videoup-admin.toml")
  38. }
  39. flag.Parse()
  40. if err := conf.Init(); err != nil {
  41. panic(err)
  42. }
  43. d = New(conf.Conf)
  44. os.Exit(m.Run())
  45. }