keyword_test.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/app/service/main/antispam/util"
  6. "math/rand"
  7. "testing"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. func testKeywordDaoImplGetRubbish(t *testing.T) {
  11. var (
  12. c = context.TODO()
  13. cond = &Condition{Pagination: &util.Pagination{CurPage: 1, PerPage: 10}, Tags: []string{"reply"}, Area: "reply", Offset: "1", State: "0", HitCounts: "0", StartTime: "2018-8-1 16:36:48", EndTime: "2018-8-21 16:36:48"}
  14. )
  15. convey.Convey("GetRubbish", t, func(ctx convey.C) {
  16. _, err := kwi.GetRubbish(c, cond)
  17. ctx.Convey("Then err should be nil.keywords should not be nil.", func(ctx convey.C) {
  18. ctx.So(err, convey.ShouldBeNil)
  19. })
  20. })
  21. }
  22. func testKeywordDaoImplGetByOffsetLimit(t *testing.T) {
  23. var (
  24. c = context.TODO()
  25. cond = &Condition{Pagination: &util.Pagination{CurPage: 1, PerPage: 10}, Tags: []string{"reply"}, Area: "reply", Offset: "1", State: "0", HitCounts: "0", StartTime: "2018-8-1 16:36:48", EndTime: "2018-8-21 16:36:48"}
  26. )
  27. convey.Convey("GetByOffsetLimit", t, func(ctx convey.C) {
  28. keywords, err := kwi.GetByOffsetLimit(c, cond)
  29. ctx.Convey("Then err should be nil.keywords should not be nil.", func(ctx convey.C) {
  30. ctx.So(err, convey.ShouldBeNil)
  31. ctx.So(keywords, convey.ShouldNotBeNil)
  32. })
  33. })
  34. }
  35. func testKeywordDaoImplGetByCond(t *testing.T) {
  36. var (
  37. c = context.TODO()
  38. cond = &Condition{Pagination: &util.Pagination{CurPage: 1, PerPage: 10}, Tags: []string{"reply"}, Area: "reply", Offset: "1", State: "0", HitCounts: "0", StartTime: "2018-8-1 16:36:48", EndTime: "2018-8-21 16:36:48"}
  39. )
  40. convey.Convey("GetByCond", t, func(ctx convey.C) {
  41. keywords, totalCounts, err := kwi.GetByCond(c, cond)
  42. ctx.Convey("Then err should be nil.keywords,totalCounts should not be nil.", func(ctx convey.C) {
  43. ctx.So(err, convey.ShouldBeNil)
  44. ctx.So(totalCounts, convey.ShouldNotBeNil)
  45. ctx.So(keywords, convey.ShouldNotBeNil)
  46. })
  47. })
  48. }
  49. func testKeywordDaoImplGetByAreaAndContents(t *testing.T) {
  50. var (
  51. c = context.TODO()
  52. cond = &Condition{Pagination: &util.Pagination{CurPage: 1, PerPage: 10}, Tags: []string{"reply"}, Area: "reply", Offset: "1", State: "0", HitCounts: "0", StartTime: "2018-8-1 16:36:48", EndTime: "2018-8-21 16:36:48"}
  53. )
  54. convey.Convey("GetByAreaAndContents", t, func(ctx convey.C) {
  55. p1, err := kwi.GetByAreaAndContents(c, cond)
  56. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  57. ctx.So(err, convey.ShouldBeNil)
  58. ctx.So(p1, convey.ShouldNotBeNil)
  59. })
  60. })
  61. }
  62. func testKeywordDaoImplGetByAreaAndContent(t *testing.T) {
  63. var (
  64. c = context.TODO()
  65. cond = &Condition{Pagination: &util.Pagination{CurPage: 1, PerPage: 10}, Tags: []string{"reply"}, Area: "reply", Offset: "1", State: "0", HitCounts: "0", StartTime: "2018-8-1 16:36:48", EndTime: "2018-8-21 16:36:48"}
  66. )
  67. convey.Convey("GetByAreaAndContent", t, func(ctx convey.C) {
  68. p1, err := kwi.GetByAreaAndContent(c, cond)
  69. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  70. ctx.So(err, convey.ShouldBeNil)
  71. ctx.So(p1, convey.ShouldNotBeNil)
  72. })
  73. })
  74. }
  75. func TestKeywordDaoImplUpdate(t *testing.T) {
  76. var (
  77. c = context.TODO()
  78. k = &Keyword{ID: 1, Content: fmt.Sprint(rand.Int63())}
  79. )
  80. convey.Convey("Update", t, func(ctx convey.C) {
  81. p1, err := kwi.Update(c, k)
  82. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  83. ctx.So(err, convey.ShouldBeNil)
  84. ctx.So(p1, convey.ShouldNotBeNil)
  85. })
  86. })
  87. }
  88. func TestKeywordDaoImplInsert(t *testing.T) {
  89. var (
  90. c = context.TODO()
  91. k = &Keyword{Content: fmt.Sprint(rand.Int63())}
  92. )
  93. convey.Convey("Insert", t, func(ctx convey.C) {
  94. p1, err := kwi.Insert(c, k)
  95. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  96. ctx.So(err, convey.ShouldBeNil)
  97. ctx.So(p1, convey.ShouldNotBeNil)
  98. })
  99. })
  100. }
  101. func TestKeywordDaoImplDeleteByIDs(t *testing.T) {
  102. var (
  103. c = context.TODO()
  104. ids = []int64{1}
  105. )
  106. convey.Convey("DeleteByIDs", t, func(ctx convey.C) {
  107. p1, err := kwi.DeleteByIDs(c, ids)
  108. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  109. ctx.So(err, convey.ShouldBeNil)
  110. ctx.So(p1, convey.ShouldNotBeNil)
  111. })
  112. })
  113. }
  114. func TestKeywordDaoImplGetByID(t *testing.T) {
  115. var (
  116. c = context.TODO()
  117. id = int64(1)
  118. )
  119. convey.Convey("GetByID", t, func(ctx convey.C) {
  120. p1, err := kwi.GetByID(c, id)
  121. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  122. ctx.So(err, convey.ShouldBeNil)
  123. ctx.So(p1, convey.ShouldNotBeNil)
  124. })
  125. })
  126. }
  127. func TestKeywordDaoImplGetByIDs(t *testing.T) {
  128. var (
  129. c = context.TODO()
  130. ids = []int64{1, 2, 3}
  131. )
  132. convey.Convey("GetByIDs", t, func(ctx convey.C) {
  133. p1, err := kwi.GetByIDs(c, ids)
  134. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  135. ctx.So(err, convey.ShouldBeNil)
  136. ctx.So(p1, convey.ShouldNotBeNil)
  137. })
  138. })
  139. }