task_test.go 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. package mysql
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "go-common/app/admin/main/aegis/model/common"
  7. modtask "go-common/app/admin/main/aegis/model/task"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestMysqlTaskFromDB(t *testing.T) {
  11. convey.Convey("TaskFromDB", t, func(ctx convey.C) {
  12. var (
  13. id = int64(0)
  14. )
  15. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  16. task, err := d.TaskFromDB(cntx, id)
  17. ctx.Convey("Then err should be nil.task should be nil.", func(ctx convey.C) {
  18. ctx.So(err, convey.ShouldBeNil)
  19. ctx.So(task, convey.ShouldBeNil)
  20. })
  21. })
  22. })
  23. }
  24. func TestMysqlDispatchByID(t *testing.T) {
  25. convey.Convey("DispatchByID", t, func(ctx convey.C) {
  26. var (
  27. mtasks map[int64]*modtask.Task
  28. ids = []int64{0}
  29. args = interface{}(int64(0))
  30. )
  31. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  32. missids, err := d.DispatchByID(cntx, mtasks, ids, args)
  33. ctx.Convey("Then err should be nil.missids should not be nil.", func(ctx convey.C) {
  34. ctx.So(err, convey.ShouldBeNil)
  35. ctx.So(missids, convey.ShouldNotBeNil)
  36. })
  37. })
  38. })
  39. }
  40. func TestMysqlDBDispatch(t *testing.T) {
  41. convey.Convey("DBDispatch", t, func(ctx convey.C) {
  42. var (
  43. opt = &modtask.NextOptions{}
  44. )
  45. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  46. _, count, err := d.DBDispatch(cntx, opt)
  47. ctx.Convey("Then err should be nil.tasks,count should not be nil.", func(ctx convey.C) {
  48. ctx.So(err, convey.ShouldBeNil)
  49. ctx.So(count, convey.ShouldNotBeNil)
  50. })
  51. })
  52. })
  53. }
  54. func TestMysqlRelease(t *testing.T) {
  55. convey.Convey("Release", t, func(ctx convey.C) {
  56. var (
  57. opt = &common.BaseOptions{}
  58. )
  59. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  60. rows, err := d.Release(cntx, opt, true)
  61. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  62. ctx.So(err, convey.ShouldBeNil)
  63. ctx.So(rows, convey.ShouldNotBeNil)
  64. })
  65. })
  66. })
  67. }
  68. func TestMysqlSeize(t *testing.T) {
  69. convey.Convey("Seize", t, func(ctx convey.C) {
  70. var (
  71. c = context.Background()
  72. mapids = map[int64]int64{1: 1}
  73. )
  74. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  75. count, err := d.Seize(c, mapids)
  76. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  77. ctx.So(err, convey.ShouldBeNil)
  78. ctx.So(count, convey.ShouldNotBeNil)
  79. })
  80. })
  81. })
  82. }
  83. func TestMysqlDelay(t *testing.T) {
  84. convey.Convey("Delay", t, func(ctx convey.C) {
  85. var (
  86. opt = &modtask.DelayOptions{}
  87. )
  88. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  89. rows, err := d.Delay(cntx, opt)
  90. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  91. ctx.So(err, convey.ShouldBeNil)
  92. ctx.So(rows, convey.ShouldNotBeNil)
  93. })
  94. })
  95. })
  96. }
  97. func TestMysqlListCheckUnSeized(t *testing.T) {
  98. convey.Convey("ListCheckUnSeized", t, func(ctx convey.C) {
  99. var (
  100. mtasks = map[int64]*modtask.Task{}
  101. )
  102. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  103. _, err := d.ListCheckUnSeized(cntx, mtasks, []int64{})
  104. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  105. ctx.So(err, convey.ShouldBeNil)
  106. })
  107. })
  108. })
  109. }
  110. func TestMysqlListCheckSeized(t *testing.T) {
  111. convey.Convey("ListCheckSeized", t, func(ctx convey.C) {
  112. var (
  113. mtasks = map[int64]*modtask.Task{}
  114. )
  115. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  116. _, err := d.ListCheckSeized(cntx, mtasks, []int64{}, int64(1))
  117. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  118. ctx.So(err, convey.ShouldBeNil)
  119. })
  120. })
  121. })
  122. }
  123. func TestMysqlListCheckDelay(t *testing.T) {
  124. convey.Convey("ListCheckDelay", t, func(ctx convey.C) {
  125. var (
  126. mtasks = map[int64]*modtask.Task{}
  127. )
  128. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  129. _, err := d.ListCheckDelay(cntx, mtasks, []int64{}, int64(1))
  130. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  131. ctx.So(err, convey.ShouldBeNil)
  132. })
  133. })
  134. })
  135. }
  136. func TestMysqlListTasks(t *testing.T) {
  137. convey.Convey("ListTasks", t, func(ctx convey.C) {
  138. opt := &modtask.ListOptions{
  139. State: 4,
  140. }
  141. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  142. _, _, err := d.ListTasks(context.TODO(), opt)
  143. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  144. ctx.So(err, convey.ShouldBeNil)
  145. })
  146. })
  147. })
  148. }
  149. func TestMysqllistCheck(t *testing.T) {
  150. convey.Convey("listCheck", t, func(ctx convey.C) {
  151. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  152. _, err := d.listCheck(context.TODO(), "state=1", []int64{1})
  153. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  154. ctx.So(err, convey.ShouldBeNil)
  155. })
  156. })
  157. })
  158. }
  159. func TestMysqlConsumerOn(t *testing.T) {
  160. convey.Convey("ConsumerOn", t, func(ctx convey.C) {
  161. var (
  162. c = context.Background()
  163. opt = &common.BaseOptions{}
  164. )
  165. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  166. err := d.ConsumerOn(c, opt)
  167. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  168. ctx.So(err, convey.ShouldBeNil)
  169. })
  170. })
  171. })
  172. }
  173. func TestMysqlConsumerOff(t *testing.T) {
  174. convey.Convey("ConsumerOff", t, func(ctx convey.C) {
  175. var (
  176. c = context.Background()
  177. opt = &common.BaseOptions{}
  178. )
  179. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  180. err := d.ConsumerOff(c, opt)
  181. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  182. ctx.So(err, convey.ShouldBeNil)
  183. })
  184. })
  185. })
  186. }
  187. func TestMysqlIsConsumerOn(t *testing.T) {
  188. convey.Convey("IsConsumerOn", t, func(ctx convey.C) {
  189. var (
  190. c = context.Background()
  191. opt = &common.BaseOptions{}
  192. )
  193. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  194. on, err := d.IsConsumerOn(c, opt)
  195. ctx.Convey("Then err should be nil.on should not be nil.", func(ctx convey.C) {
  196. ctx.So(err, convey.ShouldBeNil)
  197. ctx.So(on, convey.ShouldNotBeNil)
  198. })
  199. })
  200. })
  201. }
  202. func TestMysqlconsumer(t *testing.T) {
  203. convey.Convey("consumer", t, func(ctx convey.C) {
  204. var (
  205. c = context.Background()
  206. opt = &common.BaseOptions{}
  207. action = int8(0)
  208. )
  209. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  210. err := d.consumer(c, opt, action)
  211. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  212. ctx.So(err, convey.ShouldBeNil)
  213. })
  214. })
  215. })
  216. }
  217. func TestMysqlConsumerStat(t *testing.T) {
  218. convey.Convey("ConsumerStat", t, func(ctx convey.C) {
  219. var (
  220. c = context.Background()
  221. bizid = int64(0)
  222. flowid = int64(0)
  223. )
  224. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  225. items, err := d.ConsumerStat(c, bizid, flowid)
  226. ctx.Convey("Then err should be nil.items should not be nil.", func(ctx convey.C) {
  227. ctx.So(err, convey.ShouldBeNil)
  228. ctx.So(items, convey.ShouldNotBeNil)
  229. })
  230. })
  231. })
  232. }
  233. func TestMysqlOnlines(t *testing.T) {
  234. convey.Convey("Onlines", t, func(ctx convey.C) {
  235. var (
  236. c = context.Background()
  237. opt = &common.BaseOptions{}
  238. )
  239. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  240. uids, err := d.Onlines(c, opt)
  241. ctx.Convey("Then err should be nil.uids should not be nil.", func(ctx convey.C) {
  242. ctx.So(err, convey.ShouldBeNil)
  243. ctx.So(uids, convey.ShouldNotBeNil)
  244. })
  245. })
  246. })
  247. }
  248. func TestMysqlQueryTask(t *testing.T) {
  249. convey.Convey("QueryTask", t, func(ctx convey.C) {
  250. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  251. _, _, err := d.QueryTask(context.TODO(), 0, time.Now(), 0, 0)
  252. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  253. ctx.So(err, convey.ShouldBeNil)
  254. })
  255. })
  256. })
  257. }
  258. func TestMysqlCountPersonal(t *testing.T) {
  259. convey.Convey("CountPersonal", t, func(ctx convey.C) {
  260. var (
  261. c = context.Background()
  262. opt = &common.BaseOptions{}
  263. )
  264. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  265. count, err := d.CountPersonal(c, opt)
  266. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  267. ctx.So(err, convey.ShouldBeNil)
  268. ctx.So(count, convey.ShouldNotBeNil)
  269. })
  270. })
  271. })
  272. }
  273. func TestMysqlQueryForSeize(t *testing.T) {
  274. convey.Convey("QueryForSeize", t, func(ctx convey.C) {
  275. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  276. _, err := d.QueryForSeize(context.TODO(), 0, 0, 0, 0)
  277. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  278. ctx.So(err, convey.ShouldBeNil)
  279. })
  280. })
  281. })
  282. }