redis_test.go 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. package spam
  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 *Cache
  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 = NewCache(conf.Conf.Redis.Config)
  32. os.Exit(m.Run())
  33. }
  34. func TestSpamkeyRcntCnt(t *testing.T) {
  35. convey.Convey("keyRcntCnt", t, func(ctx convey.C) {
  36. var (
  37. mid = int64(0)
  38. )
  39. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  40. p1 := d.keyRcntCnt(mid)
  41. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  42. ctx.So(p1, convey.ShouldNotBeNil)
  43. })
  44. })
  45. })
  46. }
  47. func TestSpamkeyUpRcntCnt(t *testing.T) {
  48. convey.Convey("keyUpRcntCnt", t, func(ctx convey.C) {
  49. var (
  50. mid = int64(0)
  51. )
  52. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  53. p1 := d.keyUpRcntCnt(mid)
  54. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  55. ctx.So(p1, convey.ShouldNotBeNil)
  56. })
  57. })
  58. })
  59. }
  60. func TestSpamkeyDailyCnt(t *testing.T) {
  61. convey.Convey("keyDailyCnt", t, func(ctx convey.C) {
  62. var (
  63. mid = int64(0)
  64. )
  65. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  66. p1 := d.keyDailyCnt(mid)
  67. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  68. ctx.So(p1, convey.ShouldNotBeNil)
  69. })
  70. })
  71. })
  72. }
  73. func TestSpamkeyActRec(t *testing.T) {
  74. convey.Convey("keyActRec", t, func(ctx convey.C) {
  75. var (
  76. mid = int64(0)
  77. )
  78. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  79. p1 := d.keyActRec(mid)
  80. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  81. ctx.So(p1, convey.ShouldNotBeNil)
  82. })
  83. })
  84. })
  85. }
  86. func TestSpamkeySpamRpRec(t *testing.T) {
  87. convey.Convey("keySpamRpRec", t, func(ctx convey.C) {
  88. var (
  89. mid = int64(0)
  90. )
  91. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  92. p1 := d.keySpamRpRec(mid)
  93. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  94. ctx.So(p1, convey.ShouldNotBeNil)
  95. })
  96. })
  97. })
  98. }
  99. func TestSpamkeySpamRpDaily(t *testing.T) {
  100. convey.Convey("keySpamRpDaily", t, func(ctx convey.C) {
  101. var (
  102. mid = int64(0)
  103. )
  104. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  105. p1 := d.keySpamRpDaily(mid)
  106. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  107. ctx.So(p1, convey.ShouldNotBeNil)
  108. })
  109. })
  110. })
  111. }
  112. func TestSpamkeySpamActRec(t *testing.T) {
  113. convey.Convey("keySpamActRec", t, func(ctx convey.C) {
  114. var (
  115. mid = int64(0)
  116. )
  117. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  118. p1 := d.keySpamActRec(mid)
  119. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  120. ctx.So(p1, convey.ShouldNotBeNil)
  121. })
  122. })
  123. })
  124. }
  125. func TestSpamIncrReply(t *testing.T) {
  126. convey.Convey("IncrReply", t, func(ctx convey.C) {
  127. var (
  128. mid = int64(0)
  129. isUp bool
  130. )
  131. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  132. count, err := d.IncrReply(context.Background(), mid, isUp)
  133. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  134. ctx.So(err, convey.ShouldBeNil)
  135. ctx.So(count, convey.ShouldNotBeNil)
  136. })
  137. })
  138. })
  139. }
  140. func TestSpamIncrAct(t *testing.T) {
  141. convey.Convey("IncrAct", t, func(ctx convey.C) {
  142. var (
  143. mid = int64(0)
  144. )
  145. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  146. count, err := d.IncrAct(context.Background(), mid)
  147. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  148. ctx.So(err, convey.ShouldBeNil)
  149. ctx.So(count, convey.ShouldNotBeNil)
  150. })
  151. })
  152. })
  153. }
  154. func TestSpamIncrDailyReply(t *testing.T) {
  155. convey.Convey("IncrDailyReply", t, func(ctx convey.C) {
  156. var (
  157. mid = int64(0)
  158. )
  159. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  160. count, err := d.IncrDailyReply(context.Background(), mid)
  161. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  162. ctx.So(err, convey.ShouldBeNil)
  163. ctx.So(count, convey.ShouldNotBeNil)
  164. })
  165. })
  166. })
  167. }
  168. func TestSpamTTLDailyReply(t *testing.T) {
  169. convey.Convey("TTLDailyReply", t, func(ctx convey.C) {
  170. var (
  171. mid = int64(0)
  172. )
  173. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  174. ttl, err := d.TTLDailyReply(context.Background(), mid)
  175. ctx.Convey("Then err should be nil.ttl should not be nil.", func(ctx convey.C) {
  176. ctx.So(err, convey.ShouldBeNil)
  177. ctx.So(ttl, convey.ShouldNotBeNil)
  178. })
  179. })
  180. })
  181. }
  182. func TestSpamExpireDailyReply(t *testing.T) {
  183. convey.Convey("ExpireDailyReply", t, func(ctx convey.C) {
  184. var (
  185. mid = int64(0)
  186. exp = int(1)
  187. )
  188. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  189. err := d.ExpireDailyReply(context.Background(), mid, exp)
  190. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  191. ctx.So(err, convey.ShouldBeNil)
  192. })
  193. })
  194. })
  195. }
  196. func TestSpamSetReplyRecSpam(t *testing.T) {
  197. convey.Convey("SetReplyRecSpam", t, func(ctx convey.C) {
  198. var (
  199. mid = int64(0)
  200. code = int(0)
  201. exp = int(1)
  202. )
  203. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  204. err := d.SetReplyRecSpam(context.Background(), mid, code, exp)
  205. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  206. ctx.So(err, convey.ShouldBeNil)
  207. })
  208. })
  209. })
  210. }
  211. func TestSpamSetReplyDailySpam(t *testing.T) {
  212. convey.Convey("SetReplyDailySpam", t, func(ctx convey.C) {
  213. var (
  214. mid = int64(0)
  215. code = int(0)
  216. exp = int(1)
  217. )
  218. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  219. err := d.SetReplyDailySpam(context.Background(), mid, code, exp)
  220. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  221. ctx.So(err, convey.ShouldBeNil)
  222. })
  223. })
  224. })
  225. }
  226. func TestSpamSetActionRecSpam(t *testing.T) {
  227. convey.Convey("SetActionRecSpam", t, func(ctx convey.C) {
  228. var (
  229. mid = int64(0)
  230. code = int(0)
  231. exp = int(1)
  232. )
  233. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  234. err := d.SetActionRecSpam(context.Background(), mid, code, exp)
  235. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  236. ctx.So(err, convey.ShouldBeNil)
  237. })
  238. })
  239. })
  240. }