db_test.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/job/main/reply-feed/model"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestGenSQL(t *testing.T) {
  9. convey.Convey("genSQL", t, func(ctx convey.C) {
  10. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  11. p1 := genSQL()
  12. t.Log(p1)
  13. })
  14. })
  15. }
  16. func TestDaoreportHit(t *testing.T) {
  17. convey.Convey("reportHit", t, func(ctx convey.C) {
  18. var (
  19. oid = int64(0)
  20. )
  21. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  22. p1 := reportHit(oid)
  23. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  24. ctx.So(p1, convey.ShouldNotBeNil)
  25. })
  26. })
  27. })
  28. }
  29. func TestDaoreplyHit(t *testing.T) {
  30. convey.Convey("replyHit", t, func(ctx convey.C) {
  31. var (
  32. oid = int64(0)
  33. )
  34. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  35. p1 := replyHit(oid)
  36. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  37. ctx.So(p1, convey.ShouldNotBeNil)
  38. })
  39. })
  40. })
  41. }
  42. func TestDaosubjectHit(t *testing.T) {
  43. convey.Convey("subjectHit", t, func(ctx convey.C) {
  44. var (
  45. oid = int64(0)
  46. )
  47. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  48. p1 := subjectHit(oid)
  49. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  50. ctx.So(p1, convey.ShouldNotBeNil)
  51. })
  52. })
  53. })
  54. }
  55. func TestDaosplit(t *testing.T) {
  56. convey.Convey("split", t, func(ctx convey.C) {
  57. var (
  58. s = []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
  59. )
  60. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  61. p1 := split(s, 5)
  62. p2 := split(s, 10)
  63. p3 := split(s, 20)
  64. p4 := split(s, 3)
  65. p5 := split(s, 1)
  66. p6 := split(s, 2)
  67. p7 := split(s, 4)
  68. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  69. ctx.So(len(p1), convey.ShouldEqual, 2)
  70. ctx.So(len(p2), convey.ShouldEqual, 1)
  71. ctx.So(len(p3), convey.ShouldEqual, 1)
  72. ctx.So(len(p4), convey.ShouldEqual, 4)
  73. ctx.So(len(p5), convey.ShouldEqual, 10)
  74. ctx.So(len(p6), convey.ShouldEqual, 5)
  75. ctx.So(len(p7), convey.ShouldEqual, 3)
  76. })
  77. })
  78. })
  79. }
  80. func TestDaoSlotStats(t *testing.T) {
  81. convey.Convey("SlotStats", t, func(ctx convey.C) {
  82. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  83. ss, err := d.SlotStats(context.Background())
  84. ctx.Convey("Then err should be nil.ss should not be nil.", func(ctx convey.C) {
  85. ctx.So(err, convey.ShouldBeNil)
  86. ctx.So(ss, convey.ShouldNotBeNil)
  87. })
  88. })
  89. })
  90. }
  91. func TestDaoRpIDs(t *testing.T) {
  92. convey.Convey("RpIDs", t, func(ctx convey.C) {
  93. var (
  94. oid = int64(0)
  95. tp = int(0)
  96. )
  97. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  98. rpIDs, err := d.RpIDs(context.Background(), oid, tp)
  99. ctx.Convey("Then err should be nil.rpIDs should not be nil.", func(ctx convey.C) {
  100. ctx.So(err, convey.ShouldBeNil)
  101. ctx.So(rpIDs, convey.ShouldBeNil)
  102. })
  103. })
  104. })
  105. }
  106. func TestDaoReportStatsByID(t *testing.T) {
  107. convey.Convey("ReportStatsByID", t, func(ctx convey.C) {
  108. var (
  109. oid = int64(0)
  110. rpIDs = []int64{-1}
  111. )
  112. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  113. reportMap, err := d.ReportStatsByID(context.Background(), oid, rpIDs)
  114. ctx.Convey("Then err should be nil.reportMap should not be nil.", func(ctx convey.C) {
  115. ctx.So(err, convey.ShouldBeNil)
  116. ctx.So(reportMap, convey.ShouldNotBeNil)
  117. })
  118. })
  119. })
  120. }
  121. func TestDaoReplyLHRCStatsByID(t *testing.T) {
  122. convey.Convey("ReplyLHRCStatsByID", t, func(ctx convey.C) {
  123. var (
  124. oid = int64(0)
  125. rpIDs = []int64{-1}
  126. )
  127. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  128. replyMap, err := d.ReplyLHRCStatsByID(context.Background(), oid, rpIDs)
  129. ctx.Convey("Then err should be nil.replyMap should not be nil.", func(ctx convey.C) {
  130. ctx.So(err, convey.ShouldBeNil)
  131. ctx.So(replyMap, convey.ShouldNotBeNil)
  132. })
  133. })
  134. })
  135. }
  136. func TestDaoSubjectStats(t *testing.T) {
  137. convey.Convey("SubjectStats", t, func(ctx convey.C) {
  138. var (
  139. oid = int64(0)
  140. tp = int(0)
  141. )
  142. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  143. ctime, err := d.SubjectStats(context.Background(), oid, tp)
  144. ctx.Convey("Then err should be nil.ctime should not be nil.", func(ctx convey.C) {
  145. ctx.So(err, convey.ShouldBeNil)
  146. ctx.So(ctime, convey.ShouldNotBeNil)
  147. })
  148. })
  149. })
  150. }
  151. func TestDaoReplyLHRCStats(t *testing.T) {
  152. convey.Convey("ReplyLHRCStats", t, func(ctx convey.C) {
  153. var (
  154. oid = int64(0)
  155. tp = int(0)
  156. )
  157. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  158. replyMap, err := d.ReplyLHRCStats(context.Background(), oid, tp)
  159. ctx.Convey("Then err should be nil.replyMap should not be nil.", func(ctx convey.C) {
  160. ctx.So(err, convey.ShouldBeNil)
  161. ctx.So(replyMap, convey.ShouldNotBeNil)
  162. })
  163. })
  164. })
  165. }
  166. func TestDaoSlotsMapping(t *testing.T) {
  167. convey.Convey("SlotsMapping", t, func(ctx convey.C) {
  168. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  169. slotsMap, err := d.SlotsMapping(context.Background())
  170. ctx.Convey("Then err should be nil.slotsMap should not be nil.", func(ctx convey.C) {
  171. ctx.So(err, convey.ShouldBeNil)
  172. ctx.So(slotsMap, convey.ShouldNotBeNil)
  173. })
  174. })
  175. })
  176. }
  177. func TestDaoUpsertStatistics(t *testing.T) {
  178. convey.Convey("UpsertStatistics", t, func(ctx convey.C) {
  179. var (
  180. name = ""
  181. date = int(0)
  182. hour = int(0)
  183. s = &model.StatisticsStat{}
  184. )
  185. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  186. err := d.UpsertStatistics(context.Background(), name, date, hour, s)
  187. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  188. ctx.So(err, convey.ShouldBeNil)
  189. })
  190. })
  191. })
  192. }