redis_test.go 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/main/antispam/model"
  5. "testing"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaosendersKey(t *testing.T) {
  9. var (
  10. keywordID = int64(0)
  11. )
  12. convey.Convey("sendersKey", t, func(ctx convey.C) {
  13. p1 := sendersKey(keywordID)
  14. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  15. ctx.So(p1, convey.ShouldNotBeNil)
  16. })
  17. })
  18. }
  19. func TestDaoareaSendersKey(t *testing.T) {
  20. var (
  21. area = ""
  22. senderID = int64(0)
  23. )
  24. convey.Convey("areaSendersKey", t, func(ctx convey.C) {
  25. p1 := areaSendersKey(area, senderID)
  26. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  27. ctx.So(p1, convey.ShouldNotBeNil)
  28. })
  29. })
  30. }
  31. func TestDaototalCountsKey(t *testing.T) {
  32. var (
  33. keywordID = int64(0)
  34. )
  35. convey.Convey("totalCountsKey", t, func(ctx convey.C) {
  36. p1 := totalCountsKey(keywordID)
  37. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  38. ctx.So(p1, convey.ShouldNotBeNil)
  39. })
  40. })
  41. }
  42. func TestDaolocalCountsKey(t *testing.T) {
  43. var (
  44. keywordID = int64(0)
  45. oid = int64(0)
  46. )
  47. convey.Convey("localCountsKey", t, func(ctx convey.C) {
  48. p1 := localCountsKey(keywordID, oid)
  49. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  50. ctx.So(p1, convey.ShouldNotBeNil)
  51. })
  52. })
  53. }
  54. func TestDaoglobalCountsKey(t *testing.T) {
  55. var (
  56. keywordID = int64(0)
  57. )
  58. convey.Convey("globalCountsKey", t, func(ctx convey.C) {
  59. p1 := globalCountsKey(keywordID)
  60. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  61. ctx.So(p1, convey.ShouldNotBeNil)
  62. })
  63. })
  64. }
  65. func TestDaorulesKey(t *testing.T) {
  66. var (
  67. area = ""
  68. limitType = ""
  69. )
  70. convey.Convey("rulesKey", t, func(ctx convey.C) {
  71. p1 := rulesKey(area, limitType)
  72. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  73. ctx.So(p1, convey.ShouldNotBeNil)
  74. })
  75. })
  76. }
  77. func TestDaopingRedis(t *testing.T) {
  78. var (
  79. c = context.TODO()
  80. )
  81. convey.Convey("pingRedis", t, func(ctx convey.C) {
  82. err := d.pingRedis(c)
  83. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  84. ctx.So(err, convey.ShouldBeNil)
  85. })
  86. })
  87. }
  88. func TestDaoCntSendersCache(t *testing.T) {
  89. var (
  90. c = context.TODO()
  91. keywordID = int64(0)
  92. )
  93. convey.Convey("CntSendersCache", t, func(ctx convey.C) {
  94. cnt, err := d.CntSendersCache(c, keywordID)
  95. ctx.Convey("Then err should be nil.cnt should not be nil.", func(ctx convey.C) {
  96. ctx.So(err, convey.ShouldBeNil)
  97. ctx.So(cnt, convey.ShouldNotBeNil)
  98. })
  99. })
  100. }
  101. func TestDaoGlobalLocalLimitCache(t *testing.T) {
  102. var (
  103. c = context.TODO()
  104. keywordID = int64(0)
  105. oid = int64(0)
  106. )
  107. convey.Convey("GlobalLocalLimitCache", t, func(ctx convey.C) {
  108. p1, err := d.GlobalLocalLimitCache(c, keywordID, oid)
  109. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  110. ctx.So(err, convey.ShouldBeNil)
  111. ctx.So(p1, convey.ShouldNotBeNil)
  112. })
  113. })
  114. }
  115. func TestDaoIncrGlobalLimitCache(t *testing.T) {
  116. var (
  117. c = context.TODO()
  118. keywordID = int64(0)
  119. )
  120. convey.Convey("IncrGlobalLimitCache", t, func(ctx convey.C) {
  121. p1, err := d.IncrGlobalLimitCache(c, keywordID)
  122. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  123. ctx.So(err, convey.ShouldBeNil)
  124. ctx.So(p1, convey.ShouldNotBeNil)
  125. })
  126. })
  127. }
  128. func TestDaoIncrLocalLimitCache(t *testing.T) {
  129. var (
  130. c = context.TODO()
  131. keywordID = int64(0)
  132. oid = int64(0)
  133. )
  134. convey.Convey("IncrLocalLimitCache", t, func(ctx convey.C) {
  135. p1, err := d.IncrLocalLimitCache(c, keywordID, oid)
  136. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  137. ctx.So(err, convey.ShouldBeNil)
  138. ctx.So(p1, convey.ShouldNotBeNil)
  139. })
  140. })
  141. }
  142. func TestDaoLocalLimitExpire(t *testing.T) {
  143. var (
  144. c = context.TODO()
  145. keywordID = int64(0)
  146. oid = int64(0)
  147. dur = int64(0)
  148. )
  149. convey.Convey("LocalLimitExpire", t, func(ctx convey.C) {
  150. err := d.LocalLimitExpire(c, keywordID, oid, dur)
  151. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  152. ctx.So(err, convey.ShouldBeNil)
  153. })
  154. })
  155. }
  156. func TestDaoGlobalLimitExpire(t *testing.T) {
  157. var (
  158. c = context.TODO()
  159. keywordID = int64(0)
  160. dur = int64(0)
  161. )
  162. convey.Convey("GlobalLimitExpire", t, func(ctx convey.C) {
  163. err := d.GlobalLimitExpire(c, keywordID, dur)
  164. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  165. ctx.So(err, convey.ShouldBeNil)
  166. })
  167. })
  168. }
  169. func TestDaoDelRegexpCache(t *testing.T) {
  170. var (
  171. c = context.TODO()
  172. )
  173. convey.Convey("DelRegexpCache", t, func(ctx convey.C) {
  174. err := d.DelRegexpCache(c)
  175. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  176. ctx.So(err, convey.ShouldBeNil)
  177. })
  178. })
  179. }
  180. func TestDaoDelRulesCache(t *testing.T) {
  181. var (
  182. c = context.TODO()
  183. area = ""
  184. limitType = ""
  185. )
  186. convey.Convey("DelRulesCache", t, func(ctx convey.C) {
  187. err := d.DelRulesCache(c, area, limitType)
  188. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  189. ctx.So(err, convey.ShouldBeNil)
  190. })
  191. })
  192. }
  193. func TestDaoAreaSendersExpire(t *testing.T) {
  194. var (
  195. c = context.TODO()
  196. area = ""
  197. senderID = int64(0)
  198. dur = int64(0)
  199. )
  200. convey.Convey("AreaSendersExpire", t, func(ctx convey.C) {
  201. err := d.AreaSendersExpire(c, area, senderID, dur)
  202. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  203. ctx.So(err, convey.ShouldBeNil)
  204. })
  205. })
  206. }
  207. func TestDaoIncrAreaSendersCache(t *testing.T) {
  208. var (
  209. c = context.TODO()
  210. area = ""
  211. senderID = int64(0)
  212. )
  213. convey.Convey("IncrAreaSendersCache", t, func(ctx convey.C) {
  214. p1, err := d.IncrAreaSendersCache(c, area, senderID)
  215. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  216. ctx.So(err, convey.ShouldBeNil)
  217. ctx.So(p1, convey.ShouldNotBeNil)
  218. })
  219. })
  220. }
  221. func TestDaoAllSendersCache(t *testing.T) {
  222. var (
  223. c = context.TODO()
  224. keywordID = int64(0)
  225. )
  226. convey.Convey("AllSendersCache", t, func(ctx convey.C) {
  227. p1, err := d.AllSendersCache(c, keywordID)
  228. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  229. ctx.So(err, convey.ShouldBeNil)
  230. ctx.So(p1, convey.ShouldNotBeNil)
  231. })
  232. })
  233. }
  234. func TestDaoSendersCache(t *testing.T) {
  235. var (
  236. c = context.TODO()
  237. keywordID = int64(0)
  238. limit = int64(0)
  239. offset = int64(0)
  240. )
  241. convey.Convey("SendersCache", t, func(ctx convey.C) {
  242. p1, err := d.SendersCache(c, keywordID, limit, offset)
  243. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  244. ctx.So(err, convey.ShouldBeNil)
  245. ctx.So(p1, convey.ShouldNotBeNil)
  246. })
  247. })
  248. }
  249. func TestDaoTotalLimitExpire(t *testing.T) {
  250. var (
  251. c = context.TODO()
  252. keywordID = int64(0)
  253. dur = int64(0)
  254. )
  255. convey.Convey("TotalLimitExpire", t, func(ctx convey.C) {
  256. err := d.TotalLimitExpire(c, keywordID, dur)
  257. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  258. ctx.So(err, convey.ShouldBeNil)
  259. })
  260. })
  261. }
  262. func TestDaoIncrTotalLimitCache(t *testing.T) {
  263. var (
  264. c = context.TODO()
  265. keywordID = int64(0)
  266. )
  267. convey.Convey("IncrTotalLimitCache", t, func(ctx convey.C) {
  268. p1, err := d.IncrTotalLimitCache(c, keywordID)
  269. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  270. ctx.So(err, convey.ShouldBeNil)
  271. ctx.So(p1, convey.ShouldNotBeNil)
  272. })
  273. })
  274. }
  275. func TestDaoZaddSendersCache(t *testing.T) {
  276. var (
  277. c = context.TODO()
  278. keywordID = int64(0)
  279. score = int64(0)
  280. senderID = int64(0)
  281. )
  282. convey.Convey("ZaddSendersCache", t, func(ctx convey.C) {
  283. p1, err := d.ZaddSendersCache(c, keywordID, score, senderID)
  284. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  285. ctx.So(err, convey.ShouldBeNil)
  286. ctx.So(p1, convey.ShouldNotBeNil)
  287. })
  288. })
  289. }
  290. func TestDaoZremSendersCache(t *testing.T) {
  291. var (
  292. c = context.TODO()
  293. keywordID = int64(1)
  294. senderIDStr = ""
  295. )
  296. convey.Convey("ZremSendersCache", t, func(ctx convey.C) {
  297. p1, err := d.ZremSendersCache(c, keywordID, senderIDStr)
  298. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  299. ctx.So(err, convey.ShouldBeNil)
  300. ctx.So(p1, convey.ShouldNotBeNil)
  301. })
  302. })
  303. }
  304. func TestDaoDelKeywordRelatedCache(t *testing.T) {
  305. var (
  306. c = context.TODO()
  307. ks = []*model.Keyword{}
  308. )
  309. convey.Convey("DelKeywordRelatedCache", t, func(ctx convey.C) {
  310. err := d.DelKeywordRelatedCache(c, ks)
  311. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  312. ctx.So(err, convey.ShouldBeNil)
  313. })
  314. })
  315. }
  316. func TestDaoDelCountRelatedCache(t *testing.T) {
  317. var (
  318. c = context.TODO()
  319. k = &model.Keyword{}
  320. )
  321. convey.Convey("DelCountRelatedCache", t, func(ctx convey.C) {
  322. err := d.DelCountRelatedCache(c, k)
  323. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  324. ctx.So(err, convey.ShouldBeNil)
  325. })
  326. })
  327. }