task_dispatch_test.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaoUpGtimeByID(t *testing.T) {
  9. convey.Convey("UpGtimeByID", t, func(ctx convey.C) {
  10. var (
  11. c = context.Background()
  12. id = int64(0)
  13. gtime = ""
  14. )
  15. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  16. rows, err := d.UpGtimeByID(c, id, gtime)
  17. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  18. ctx.So(err, convey.ShouldBeNil)
  19. ctx.So(rows, convey.ShouldNotBeNil)
  20. })
  21. })
  22. })
  23. }
  24. func TestDaoUserUndoneSpecTask(t *testing.T) {
  25. convey.Convey("UserUndoneSpecTask", t, func(ctx convey.C) {
  26. var (
  27. c = context.Background()
  28. uid = int64(0)
  29. )
  30. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  31. _, err := d.UserUndoneSpecTask(c, uid)
  32. ctx.Convey("Then err should be nil.tasks should not be nil.", func(ctx convey.C) {
  33. ctx.So(err, convey.ShouldBeNil)
  34. })
  35. })
  36. })
  37. }
  38. func TestDaoListByCondition(t *testing.T) {
  39. convey.Convey("ListByCondition", t, func(ctx convey.C) {
  40. var (
  41. c = context.Background()
  42. uid = int64(0)
  43. pn = int(0)
  44. ps = int(0)
  45. ltype = int8(0)
  46. leader = int8(0)
  47. )
  48. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  49. tasks, err := d.ListByCondition(c, uid, pn, ps, ltype, leader)
  50. ctx.Convey("Then err should be nil.tasks should not be nil.", func(ctx convey.C) {
  51. ctx.So(err, convey.ShouldBeNil)
  52. ctx.So(tasks, convey.ShouldNotBeNil)
  53. })
  54. })
  55. })
  56. }
  57. func TestDaosqlHelper(t *testing.T) {
  58. convey.Convey("sqlHelper", t, func(ctx convey.C) {
  59. var (
  60. uid = int64(0)
  61. pn = int(0)
  62. ps = int(0)
  63. ltype = int8(0)
  64. leader = int8(0)
  65. )
  66. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  67. p1 := d.sqlHelper(uid, pn, ps, ltype, leader)
  68. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  69. ctx.So(p1, convey.ShouldNotBeNil)
  70. })
  71. })
  72. })
  73. }
  74. func TestDaoGetWeightDB(t *testing.T) {
  75. convey.Convey("GetWeightDB", t, func(ctx convey.C) {
  76. var (
  77. c = context.Background()
  78. )
  79. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  80. _, err := d.GetWeightDB(c, []int64{0, 1, 2})
  81. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  82. ctx.So(err, convey.ShouldBeNil)
  83. })
  84. })
  85. })
  86. }
  87. func TestDaoTaskByID(t *testing.T) {
  88. convey.Convey("TaskByID", t, func(ctx convey.C) {
  89. var (
  90. c = context.Background()
  91. )
  92. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  93. _, err := d.TaskByID(c, 0)
  94. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  95. ctx.So(err, convey.ShouldBeNil)
  96. })
  97. })
  98. })
  99. }
  100. func TestDaoTxUpTaskByID(t *testing.T) {
  101. convey.Convey("TxUpTaskByID", t, func(ctx convey.C) {
  102. var (
  103. c = context.Background()
  104. )
  105. tx, _ := d.BeginTran(c)
  106. defer tx.Commit()
  107. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  108. _, err := d.TxUpTaskByID(tx, 0, map[string]interface{}{"uid": 0})
  109. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  110. ctx.So(err, convey.ShouldBeNil)
  111. })
  112. })
  113. })
  114. }
  115. func TestDaoTxReleaseByID(t *testing.T) {
  116. convey.Convey("TxReleaseByID", t, func(ctx convey.C) {
  117. var (
  118. c = context.Background()
  119. )
  120. tx, _ := d.BeginTran(c)
  121. defer tx.Commit()
  122. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  123. _, err := d.TxReleaseByID(tx, 0)
  124. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  125. ctx.So(err, convey.ShouldBeNil)
  126. })
  127. })
  128. })
  129. }
  130. func TestDaoMulReleaseMtime(t *testing.T) {
  131. convey.Convey("MulReleaseMtime", t, func(ctx convey.C) {
  132. var (
  133. c = context.Background()
  134. )
  135. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  136. _, err := d.MulReleaseMtime(c, []int64{1}, time.Now())
  137. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  138. ctx.So(err, convey.ShouldBeNil)
  139. })
  140. })
  141. })
  142. }
  143. func TestDaoGetTimeOutTask(t *testing.T) {
  144. convey.Convey("GetTimeOutTask", t, func(ctx convey.C) {
  145. var (
  146. c = context.Background()
  147. )
  148. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  149. _, err := d.GetTimeOutTask(c)
  150. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  151. ctx.So(err, convey.ShouldBeNil)
  152. })
  153. })
  154. })
  155. }
  156. func TestDaoGetRelTask(t *testing.T) {
  157. convey.Convey("GetRelTask", t, func(ctx convey.C) {
  158. var (
  159. c = context.Background()
  160. )
  161. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  162. _, _, err := d.GetRelTask(c, 0)
  163. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  164. ctx.So(err, convey.ShouldBeNil)
  165. })
  166. })
  167. })
  168. }