dao_test.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package search
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "testing"
  7. "go-common/app/admin/main/credit/conf"
  8. "go-common/app/admin/main/credit/model/blocked"
  9. . "github.com/smartystreets/goconvey/convey"
  10. )
  11. var d *Dao
  12. func TestMain(m *testing.M) {
  13. if os.Getenv("DEPLOY_ENV") != "" {
  14. flag.Set("app_id", "main.account-law.credit-admin")
  15. flag.Set("conf_appid", "main.account-law.credit-admin")
  16. flag.Set("conf_token", "eKmbn2M4jvSyyjMEOywLFOQlX5ggRG9x")
  17. flag.Set("tree_id", "5885")
  18. flag.Set("conf_version", "docker-1")
  19. flag.Set("deploy_env", "uat")
  20. flag.Set("conf_env", "10")
  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/convey-test.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. func TestDao_Blocked(t *testing.T) {
  36. arg := &blocked.ArgBlockedSearch{Order: "id"}
  37. Convey("return someting", t, func() {
  38. ids, pagers, err := d.Blocked(context.TODO(), arg)
  39. So(err, ShouldBeNil)
  40. So(len(ids), ShouldBeGreaterThanOrEqualTo, 0)
  41. So(pagers, ShouldNotBeNil)
  42. })
  43. }
  44. func TestDao_Publish(t *testing.T) {
  45. arg := &blocked.ArgPublishSearch{Order: "id"}
  46. Convey("return someting", t, func() {
  47. ids, pagers, err := d.Publish(context.TODO(), arg)
  48. So(err, ShouldBeNil)
  49. So(len(ids), ShouldBeGreaterThanOrEqualTo, 0)
  50. So(pagers, ShouldNotBeNil)
  51. })
  52. }
  53. func Test_Case(t *testing.T) {
  54. arg := &blocked.ArgCaseSearch{Order: "id"}
  55. Convey("return someting", t, func() {
  56. ids, pagers, err := d.Case(context.TODO(), arg)
  57. So(err, ShouldBeNil)
  58. So(len(ids), ShouldBeGreaterThanOrEqualTo, 0)
  59. So(pagers, ShouldNotBeNil)
  60. })
  61. }
  62. func Test_Jury(t *testing.T) {
  63. arg := &blocked.ArgJurySearch{Order: "id"}
  64. Convey("return someting", t, func() {
  65. ids, pagers, err := d.Jury(context.TODO(), arg)
  66. So(err, ShouldBeNil)
  67. So(len(ids), ShouldBeGreaterThanOrEqualTo, 0)
  68. So(pagers, ShouldNotBeNil)
  69. })
  70. }
  71. func Test_Opinion(t *testing.T) {
  72. arg := &blocked.ArgOpinionSearch{Order: "id"}
  73. Convey("return someting", t, func() {
  74. ids, pagers, err := d.Opinion(context.TODO(), arg)
  75. So(err, ShouldBeNil)
  76. So(len(ids), ShouldBeGreaterThanOrEqualTo, 0)
  77. So(pagers, ShouldNotBeNil)
  78. })
  79. }
  80. func Test_KPIPoint(t *testing.T) {
  81. arg := &blocked.ArgKpiPointSearch{Order: "id", Start: "2006-01-02 15:04:05", End: "2019-01-02 15:04:05"}
  82. Convey("return someting", t, func() {
  83. ids, pagers, err := d.KPIPoint(context.TODO(), arg)
  84. So(err, ShouldBeNil)
  85. So(len(ids), ShouldBeGreaterThanOrEqualTo, 0)
  86. So(pagers, ShouldNotBeNil)
  87. })
  88. }
  89. func Test_BlockedUpdate(t *testing.T) {
  90. single := map[string]interface{}{
  91. "id": 1,
  92. "oper_id": 1,
  93. "status": 1,
  94. "black": 1,
  95. }
  96. var multiple []interface{}
  97. multiple = append(multiple, single)
  98. Convey("return someting", t, func() {
  99. err := d.SearchUpdate(context.TODO(), "block_info", "blocked_info", multiple)
  100. So(err, ShouldBeNil)
  101. })
  102. }