mysql_task_test.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/admin/main/dm/model"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaoTaskList(t *testing.T) {
  9. convey.Convey("TaskList", t, func(ctx convey.C) {
  10. var (
  11. c = context.Background()
  12. taskSQL = []string{}
  13. pn = int64(1)
  14. ps = int64(50)
  15. )
  16. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  17. tasks, total, err := testDao.TaskList(c, taskSQL, pn, ps)
  18. ctx.Convey("Then err should be nil.tasks,total should not be nil.", func(ctx convey.C) {
  19. ctx.So(err, convey.ShouldBeNil)
  20. ctx.So(total, convey.ShouldNotBeNil)
  21. t.Logf("====%d", total)
  22. ctx.So(tasks, convey.ShouldNotBeNil)
  23. // t.Logf("====%+v", tasks[0])
  24. })
  25. })
  26. })
  27. }
  28. func TestDaoAddTask(t *testing.T) {
  29. convey.Convey("AddTask", t, func(ctx convey.C) {
  30. var (
  31. tx, _ = testDao.BeginBiliDMTrans(context.Background())
  32. v = &model.AddTaskArg{
  33. Title: "test",
  34. Start: "2016-10-30 16:12:21",
  35. End: "2018-10-30 16:12:21",
  36. }
  37. )
  38. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  39. taskID, err := testDao.AddTask(tx, v, 1)
  40. ctx.Convey("Then err should be nil.taskID should not be nil.", func(ctx convey.C) {
  41. ctx.So(err, convey.ShouldBeNil)
  42. ctx.So(taskID, convey.ShouldNotBeNil)
  43. t.Logf("====%d", taskID)
  44. tx.Commit()
  45. })
  46. })
  47. })
  48. }
  49. func TestDaoAddSubTask(t *testing.T) {
  50. convey.Convey("AddSubTask", t, func(ctx convey.C) {
  51. var (
  52. tx, _ = testDao.BeginBiliDMTrans(context.Background())
  53. taskID = int64(8)
  54. operation = int32(0)
  55. start = "2018-10-30 16:12:21"
  56. rate = int32(100)
  57. )
  58. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  59. id, err := testDao.AddSubTask(tx, taskID, operation, start, rate)
  60. ctx.Convey("Then err should be nil.id should not be nil.", func(ctx convey.C) {
  61. ctx.So(err, convey.ShouldBeNil)
  62. ctx.So(id, convey.ShouldNotBeNil)
  63. t.Logf("====%d", id)
  64. })
  65. tx.Commit()
  66. })
  67. })
  68. }
  69. func TestDaoEditTaskState(t *testing.T) {
  70. convey.Convey("EditTaskState", t, func(ctx convey.C) {
  71. var (
  72. c = context.Background()
  73. v = &model.EditTasksStateArg{
  74. IDs: "1,7",
  75. State: 1,
  76. }
  77. )
  78. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  79. affected, err := testDao.EditTaskState(c, v)
  80. ctx.Convey("Then err should be nil.affected should not be nil.", func(ctx convey.C) {
  81. ctx.So(err, convey.ShouldBeNil)
  82. ctx.So(affected, convey.ShouldNotBeNil)
  83. })
  84. })
  85. })
  86. }
  87. func TestDaoTaskView(t *testing.T) {
  88. convey.Convey("TaskView", t, func(ctx convey.C) {
  89. var (
  90. c = context.Background()
  91. id = int64(1)
  92. )
  93. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  94. task, err := testDao.TaskView(c, id)
  95. ctx.Convey("Then err should be nil.task should not be nil.", func(ctx convey.C) {
  96. ctx.So(err, convey.ShouldBeNil)
  97. ctx.So(task, convey.ShouldNotBeNil)
  98. t.Logf("====%+v", task)
  99. })
  100. })
  101. })
  102. }
  103. func TestDaoSubTask(t *testing.T) {
  104. convey.Convey("SubTask", t, func(ctx convey.C) {
  105. var (
  106. c = context.Background()
  107. id = int64(8)
  108. )
  109. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  110. subTask, err := testDao.SubTask(c, id)
  111. ctx.Convey("Then err should be nil.subTask should not be nil.", func(ctx convey.C) {
  112. ctx.So(err, convey.ShouldBeNil)
  113. ctx.So(subTask, convey.ShouldNotBeNil)
  114. t.Logf("====%+v", subTask)
  115. })
  116. })
  117. })
  118. }
  119. func TestDaoReviewTask(t *testing.T) {
  120. convey.Convey("ReviewTask", t, func(ctx convey.C) {
  121. var (
  122. c = context.Background()
  123. v = &model.ReviewTaskArg{}
  124. )
  125. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  126. affected, err := testDao.ReviewTask(c, v)
  127. ctx.Convey("Then err should be nil.affected should not be nil.", func(ctx convey.C) {
  128. ctx.So(err, convey.ShouldBeNil)
  129. ctx.So(affected, convey.ShouldNotBeNil)
  130. })
  131. })
  132. })
  133. }
  134. func TestDaoEditTaskPriority(t *testing.T) {
  135. convey.Convey("EditTaskPriority", t, func(ctx convey.C) {
  136. var (
  137. c = context.Background()
  138. ids = "12"
  139. priority = int64(0)
  140. )
  141. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  142. affected, err := testDao.EditTaskPriority(c, ids, priority)
  143. ctx.Convey("Then err should be nil.affected should not be nil.", func(ctx convey.C) {
  144. ctx.So(err, convey.ShouldBeNil)
  145. ctx.So(affected, convey.ShouldNotBeNil)
  146. })
  147. })
  148. })
  149. }