task_test.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "go-common/app/job/main/dm2/model"
  7. "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestDaoTaskInfos(t *testing.T) {
  10. convey.Convey("TaskInfos", t, func(ctx convey.C) {
  11. var (
  12. c = context.Background()
  13. state = int32(1)
  14. )
  15. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  16. tasks, err := testDao.TaskInfos(c, state)
  17. ctx.Convey("Then err should be nil.tasks should not be nil.", func(ctx convey.C) {
  18. ctx.So(err, convey.ShouldBeNil)
  19. ctx.So(tasks, convey.ShouldNotBeNil)
  20. for _, task := range tasks {
  21. t.Logf("%+v", task)
  22. }
  23. })
  24. })
  25. })
  26. }
  27. func TestDaoUpdateTask(t *testing.T) {
  28. convey.Convey("UpdateTask", t, func(ctx convey.C) {
  29. var (
  30. c = context.Background()
  31. task = &model.TaskInfo{}
  32. )
  33. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  34. affected, err := testDao.UpdateTask(c, task)
  35. ctx.Convey("Then err should be nil.affected should not be nil.", func(ctx convey.C) {
  36. ctx.So(err, convey.ShouldBeNil)
  37. ctx.So(affected, convey.ShouldNotBeNil)
  38. })
  39. })
  40. })
  41. }
  42. func TestDaoDelDMs(t *testing.T) {
  43. convey.Convey("DelDMs", t, func(ctx convey.C) {
  44. var (
  45. c = context.Background()
  46. oid = int64(221)
  47. dmids = []int64{719182141}
  48. state = int32(12)
  49. )
  50. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  51. affected, err := testDao.DelDMs(c, oid, dmids, state)
  52. ctx.Convey("Then err should be nil.affected should not be nil.", func(ctx convey.C) {
  53. ctx.So(err, convey.ShouldBeNil)
  54. ctx.So(affected, convey.ShouldNotBeNil)
  55. })
  56. })
  57. })
  58. }
  59. func TestDaoUptSubTask(t *testing.T) {
  60. convey.Convey("UptSubTask", t, func(ctx convey.C) {
  61. var (
  62. c = context.Background()
  63. taskID = int64(0)
  64. delCount = int64(0)
  65. end = time.Now()
  66. )
  67. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  68. affected, err := testDao.UptSubTask(c, taskID, delCount, end)
  69. ctx.Convey("Then err should be nil.affected should not be nil.", func(ctx convey.C) {
  70. ctx.So(err, convey.ShouldBeNil)
  71. ctx.So(affected, convey.ShouldNotBeNil)
  72. })
  73. })
  74. })
  75. }
  76. func TestDaoTaskSearchRes(t *testing.T) {
  77. convey.Convey("TaskSearchRes", t, func(ctx convey.C) {
  78. var (
  79. c = context.Background()
  80. task = &model.TaskInfo{
  81. Topic: "http://berserker.bilibili.co/m-avenger/api/hive/status/query/148/672bc22888af701529e8b3052fd2c4a7/1541066053/1389520",
  82. }
  83. )
  84. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  85. _, result, state, err := testDao.TaskSearchRes(c, task)
  86. ctx.Convey("Then err should be nil.result,state should not be nil.", func(ctx convey.C) {
  87. ctx.So(err, convey.ShouldBeNil)
  88. ctx.So(state, convey.ShouldNotBeNil)
  89. ctx.So(result, convey.ShouldNotBeNil)
  90. t.Log(result, state)
  91. })
  92. })
  93. })
  94. }
  95. func TestDaoUptSubjectCount(t *testing.T) {
  96. convey.Convey("UptSubjectCount", t, func(ctx convey.C) {
  97. var (
  98. c = context.Background()
  99. tp = int32(1)
  100. oid = int64(0)
  101. count = int64(0)
  102. )
  103. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  104. affected, err := testDao.UptSubjectCount(c, tp, oid, count)
  105. ctx.Convey("Then err should be nil.affected should not be nil.", func(ctx convey.C) {
  106. ctx.So(err, convey.ShouldBeNil)
  107. ctx.So(affected, convey.ShouldNotBeNil)
  108. })
  109. })
  110. })
  111. }
  112. func TestDaoSendWechatWorkMsg(t *testing.T) {
  113. convey.Convey("SendWechatWorkMsg", t, func(ctx convey.C) {
  114. var (
  115. c = context.Background()
  116. content = "test"
  117. title = "test"
  118. users = []string{"fengduzhen"}
  119. )
  120. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  121. err := testDao.SendWechatWorkMsg(c, content, title, users)
  122. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  123. ctx.So(err, convey.ShouldBeNil)
  124. })
  125. })
  126. })
  127. }
  128. func TestDaoSubTask(t *testing.T) {
  129. convey.Convey("SubTask", t, func(ctx convey.C) {
  130. var (
  131. c = context.Background()
  132. id = int64(32)
  133. )
  134. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  135. _, err := testDao.SubTask(c, id)
  136. ctx.Convey("Then err should be nil.subTask should not be nil.", func(ctx convey.C) {
  137. ctx.So(err, convey.ShouldBeNil)
  138. })
  139. })
  140. })
  141. }