dao_test.go 956 B

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