search_test.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package search
  2. import (
  3. "context"
  4. "flag"
  5. "go-common/app/job/main/reply/conf"
  6. "os"
  7. "testing"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. var (
  11. d *Dao
  12. )
  13. func TestMain(m *testing.M) {
  14. if os.Getenv("DEPLOY_ENV") != "" {
  15. flag.Set("app_id", "main.community.reply-job")
  16. flag.Set("conf_token", "5deea0665f8a7670b22a719337a39c7d")
  17. flag.Set("tree_id", "2123")
  18. flag.Set("conf_version", "docker-1")
  19. flag.Set("deploy_env", "uat")
  20. flag.Set("conf_host", "config.bilibili.co")
  21. flag.Set("conf_path", "/tmp")
  22. flag.Set("region", "sh")
  23. flag.Set("zone", "sh001")
  24. } else {
  25. flag.Set("conf", "../../cmd/reply-job-test.toml")
  26. }
  27. flag.Parse()
  28. if err := conf.Init(); err != nil {
  29. panic(err)
  30. }
  31. d = New(conf.Conf)
  32. os.Exit(m.Run())
  33. }
  34. func TestSearchDelReply(t *testing.T) {
  35. convey.Convey("DelReply", t, func(ctx convey.C) {
  36. var (
  37. c = context.Background()
  38. rpid = int64(0)
  39. oid = int64(0)
  40. mid = int64(0)
  41. state = int8(0)
  42. )
  43. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  44. err := d.DelReply(c, rpid, oid, mid, state)
  45. if err != nil {
  46. ctx.So(err, convey.ShouldNotBeNil)
  47. } else {
  48. ctx.So(err, convey.ShouldBeNil)
  49. }
  50. })
  51. })
  52. }
  53. func TestSearchupdate(t *testing.T) {
  54. convey.Convey("update", t, func(ctx convey.C) {
  55. var (
  56. c = context.Background()
  57. rpid = int64(0)
  58. oid = int64(0)
  59. mid = int64(0)
  60. state = int8(0)
  61. )
  62. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  63. err := d.update(c, rpid, oid, mid, state)
  64. if err != nil {
  65. ctx.So(err, convey.ShouldNotBeNil)
  66. } else {
  67. ctx.So(err, convey.ShouldBeNil)
  68. }
  69. })
  70. })
  71. }