redis_test.go 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/video/stream-mng/model"
  5. "testing"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaogetStreamNamekey(t *testing.T) {
  9. convey.Convey("getStreamNamekey", t, func(ctx convey.C) {
  10. var (
  11. streamName = "live_19148701_6447624"
  12. )
  13. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  14. p1 := d.getStreamNamekey(streamName)
  15. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  16. ctx.So(p1, convey.ShouldNotBeNil)
  17. })
  18. })
  19. })
  20. }
  21. func TestDaogetRoomIDKey(t *testing.T) {
  22. convey.Convey("getRoomIDKey", t, func(ctx convey.C) {
  23. var (
  24. rid = int64(11891462)
  25. )
  26. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  27. p1 := d.getRoomIDKey(rid)
  28. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  29. ctx.So(p1, convey.ShouldNotBeNil)
  30. })
  31. })
  32. })
  33. }
  34. func TestDaogetRoomFieldDefaultKey(t *testing.T) {
  35. convey.Convey("getRoomFieldDefaultKey", t, func(ctx convey.C) {
  36. var (
  37. streamName = "live_19148701_6447624"
  38. )
  39. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  40. p1 := d.getRoomFieldDefaultKey(streamName)
  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 TestDaogetRoomFieldOriginKey(t *testing.T) {
  48. convey.Convey("getRoomFieldOriginKey", t, func(ctx convey.C) {
  49. var (
  50. streamName = "live_19148701_6447624"
  51. )
  52. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  53. p1 := d.getRoomFieldOriginKey(streamName)
  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 TestDaogetRoomFieldForwardKey(t *testing.T) {
  61. convey.Convey("getRoomFieldForwardKey", t, func(ctx convey.C) {
  62. var (
  63. streamName = "live_19148701_6447624"
  64. )
  65. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  66. p1 := d.getRoomFieldForwardKey(streamName)
  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 TestDaogetRoomFieldSecretKey(t *testing.T) {
  74. convey.Convey("getRoomFieldSecretKey", t, func(ctx convey.C) {
  75. var (
  76. streamName = "live_19148701_6447624"
  77. )
  78. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  79. p1 := d.getRoomFieldSecretKey(streamName)
  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 TestDaogetLastCDNKey(t *testing.T) {
  87. convey.Convey("getLastCDNKey", t, func(ctx convey.C) {
  88. var (
  89. rid = int64(11891462)
  90. )
  91. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  92. p1 := d.getLastCDNKey(rid)
  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 TestDaogetChangeSrcKey(t *testing.T) {
  100. convey.Convey("getChangeSrcKey", t, func(ctx convey.C) {
  101. var (
  102. rid = int64(11891462)
  103. )
  104. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  105. p1 := d.getChangeSrcKey(rid)
  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 TestDaoCacheStreamFullInfo(t *testing.T) {
  113. convey.Convey("CacheStreamFullInfo", t, func(ctx convey.C) {
  114. var (
  115. c = context.Background()
  116. rid = int64(11891462)
  117. sname = ""
  118. )
  119. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  120. res, err := d.CacheStreamFullInfo(c, rid, sname)
  121. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  122. ctx.So(err, convey.ShouldBeNil)
  123. ctx.So(res, convey.ShouldNotBeNil)
  124. })
  125. })
  126. })
  127. }
  128. func TestDaoAddCacheStreamFullInfo(t *testing.T) {
  129. convey.Convey("AddCacheStreamFullInfo", t, func(ctx convey.C) {
  130. var (
  131. c = context.Background()
  132. id = int64(11891462)
  133. stream = &model.StreamFullInfo{}
  134. )
  135. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  136. err := d.AddCacheStreamFullInfo(c, id, stream)
  137. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  138. ctx.So(err, convey.ShouldBeNil)
  139. })
  140. })
  141. })
  142. }
  143. func TestDaoCacheStreamRIDByName(t *testing.T) {
  144. convey.Convey("CacheStreamRIDByName", t, func(ctx convey.C) {
  145. var (
  146. c = context.Background()
  147. sname = "live_19148701_6447624"
  148. )
  149. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  150. res, err := d.CacheStreamRIDByName(c, sname)
  151. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  152. ctx.So(err, convey.ShouldBeNil)
  153. ctx.So(res, convey.ShouldNotBeNil)
  154. })
  155. })
  156. })
  157. }
  158. func TestDaoAddCacheStreamRIDByName(t *testing.T) {
  159. convey.Convey("AddCacheStreamRIDByName", t, func(ctx convey.C) {
  160. var (
  161. c = context.Background()
  162. sname = "live_19148701_6447624"
  163. stream = &model.StreamFullInfo{}
  164. )
  165. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  166. err := d.AddCacheStreamRIDByName(c, sname, stream)
  167. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  168. ctx.So(err, convey.ShouldBeNil)
  169. })
  170. })
  171. })
  172. }
  173. func TestDaoAddCacheMultiStreamInfo(t *testing.T) {
  174. convey.Convey("AddCacheMultiStreamInfo", t, func(ctx convey.C) {
  175. var (
  176. c = context.Background()
  177. res map[int64]*model.StreamFullInfo
  178. )
  179. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  180. err := d.AddCacheMultiStreamInfo(c, res)
  181. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  182. ctx.So(err, convey.ShouldBeNil)
  183. })
  184. })
  185. })
  186. }
  187. func TestDaoCacheMultiStreamInfo(t *testing.T) {
  188. convey.Convey("CacheMultiStreamInfo", t, func(ctx convey.C) {
  189. var (
  190. c = context.Background()
  191. rids = []int64{11891462}
  192. )
  193. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  194. res, err := d.CacheMultiStreamInfo(c, rids)
  195. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  196. ctx.So(err, convey.ShouldBeNil)
  197. ctx.So(res, convey.ShouldNotBeNil)
  198. })
  199. })
  200. })
  201. }
  202. func TestDaoUpdateLastCDNCache(t *testing.T) {
  203. convey.Convey("UpdateLastCDNCache", t, func(ctx convey.C) {
  204. var (
  205. c = context.Background()
  206. rid = int64(11891462)
  207. origin = int64(0)
  208. )
  209. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  210. err := d.UpdateLastCDNCache(c, rid, origin)
  211. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  212. ctx.So(err, convey.ShouldBeNil)
  213. })
  214. })
  215. })
  216. }
  217. func TestDaoUpdateChangeSrcCache(t *testing.T) {
  218. convey.Convey("UpdateChangeSrcCache", t, func(ctx convey.C) {
  219. var (
  220. c = context.Background()
  221. rid = int64(11891462)
  222. origin = int64(0)
  223. )
  224. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  225. err := d.UpdateChangeSrcCache(c, rid, origin)
  226. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  227. ctx.So(err, convey.ShouldBeNil)
  228. })
  229. })
  230. })
  231. }
  232. func TestDaoGetLastCDNFromCache(t *testing.T) {
  233. convey.Convey("GetLastCDNFromCache", t, func(ctx convey.C) {
  234. var (
  235. c = context.Background()
  236. rid = int64(11891462)
  237. )
  238. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  239. p1, err := d.GetLastCDNFromCache(c, rid)
  240. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  241. ctx.So(err, convey.ShouldBeNil)
  242. ctx.So(p1, convey.ShouldNotBeNil)
  243. })
  244. })
  245. })
  246. }
  247. func TestDaoGetChangeSrcFromCache(t *testing.T) {
  248. convey.Convey("GetChangeSrcFromCache", t, func(ctx convey.C) {
  249. var (
  250. c = context.Background()
  251. rid = int64(11891462)
  252. )
  253. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  254. p1, err := d.GetChangeSrcFromCache(c, rid)
  255. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  256. ctx.So(err, convey.ShouldBeNil)
  257. ctx.So(p1, convey.ShouldNotBeNil)
  258. })
  259. })
  260. })
  261. }
  262. func TestDaoDeleteStreamByRIDFromCache(t *testing.T) {
  263. convey.Convey("DeleteStreamByRIDFromCache", t, func(ctx convey.C) {
  264. var (
  265. c = context.Background()
  266. rid = int64(11891462)
  267. )
  268. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  269. err := d.DeleteStreamByRIDFromCache(c, rid)
  270. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  271. ctx.So(err, convey.ShouldBeNil)
  272. })
  273. })
  274. })
  275. }
  276. func TestDaoDeleteLastCDNFromCache(t *testing.T) {
  277. convey.Convey("DeleteLastCDNFromCache", t, func(ctx convey.C) {
  278. var (
  279. c = context.Background()
  280. rid = int64(11891462)
  281. )
  282. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  283. err := d.DeleteLastCDNFromCache(c, rid)
  284. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  285. ctx.So(err, convey.ShouldBeNil)
  286. })
  287. })
  288. })
  289. }