dao_test.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package dao
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "testing"
  7. "time"
  8. "go-common/app/service/main/riot-search/conf"
  9. "github.com/smartystreets/goconvey/convey"
  10. )
  11. var (
  12. d *Dao
  13. )
  14. func TestMain(m *testing.M) {
  15. if os.Getenv("DEPLOY_ENV") != "" {
  16. flag.Set("app_id", "main.search.riot-search")
  17. flag.Set("conf_token", "7cac78a7fdfe78c053879bf4dff0171b")
  18. flag.Set("tree_id", "55087")
  19. flag.Set("conf_version", "ut")
  20. flag.Set("deploy_env", "uat")
  21. flag.Set("conf_host", "config.bilibili.co")
  22. flag.Set("conf_path", "/tmp")
  23. flag.Set("region", "sh")
  24. flag.Set("zone", "sh001")
  25. } else {
  26. flag.Set("conf", "../cmd/ut.toml")
  27. }
  28. flag.Parse()
  29. if err := conf.Init(); err != nil {
  30. panic(err)
  31. }
  32. d = New(conf.Conf)
  33. os.Exit(m.Run())
  34. }
  35. // IncrementBackup ...
  36. func TestIncrementBackup(t *testing.T) {
  37. convey.Convey("IncrementBackup", t, func(ctx convey.C) {
  38. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  39. p1, err := d.IncrementBackup(context.Background(), time.Now(), time.Now())
  40. ctx.Convey("Error should be nil", func(ctx convey.C) {
  41. ctx.So(err, convey.ShouldBeNil)
  42. ctx.So(p1, convey.ShouldBeNil)
  43. })
  44. })
  45. })
  46. convey.Convey("Ping", t, func(ctx convey.C) {
  47. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  48. err := d.Ping(context.Background())
  49. ctx.Convey("Error should be nil", func(ctx convey.C) {
  50. ctx.So(err, convey.ShouldBeNil)
  51. })
  52. })
  53. })
  54. convey.Convey("Close", t, func(ctx convey.C) {
  55. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  56. d.Close()
  57. ctx.Convey("No return values", func(ctx convey.C) {
  58. })
  59. })
  60. })
  61. }