task_orm_test.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "go-common/app/job/main/aegis/model"
  7. "go-common/library/sync/errgroup"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestDaoTaskActiveConfigs(t *testing.T) {
  11. convey.Convey("TaskActiveConfigs", t, func(ctx convey.C) {
  12. var (
  13. c = context.Background()
  14. )
  15. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  16. configs, err := d.TaskActiveConfigs(c)
  17. ctx.Convey("Then err should be nil.configs should not be nil.", func(ctx convey.C) {
  18. ctx.So(err, convey.ShouldBeNil)
  19. ctx.So(configs, convey.ShouldNotBeNil)
  20. })
  21. })
  22. })
  23. }
  24. func TestDaoTaskActiveConsumer(t *testing.T) {
  25. convey.Convey("TaskActiveConsumer", t, func(ctx convey.C) {
  26. var (
  27. c = context.Background()
  28. )
  29. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  30. consumerCache, err := d.TaskActiveConsumer(c)
  31. ctx.Convey("Then err should be nil.consumerCache should not be nil.", func(ctx convey.C) {
  32. ctx.So(err, convey.ShouldBeNil)
  33. ctx.So(consumerCache, convey.ShouldNotBeNil)
  34. })
  35. })
  36. })
  37. }
  38. func TestDaoResource(t *testing.T) {
  39. convey.Convey("Resource", t, func(ctx convey.C) {
  40. var (
  41. c = context.Background()
  42. rid = int64(1)
  43. )
  44. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  45. _, err := d.Resource(c, rid)
  46. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  47. ctx.So(err, convey.ShouldBeNil)
  48. })
  49. })
  50. })
  51. }
  52. func TestDaoTaskRelease(t *testing.T) {
  53. convey.Convey("TaskRelease", t, func(ctx convey.C) {
  54. var (
  55. c = context.Background()
  56. mtime = time.Now().Add(-10 * time.Second)
  57. )
  58. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  59. err := d.TaskRelease(c, mtime)
  60. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  61. ctx.So(err, convey.ShouldBeNil)
  62. })
  63. })
  64. })
  65. }
  66. func TestDaoReport(t *testing.T) {
  67. convey.Convey("Report", t, func(ctx convey.C) {
  68. var (
  69. c = context.Background()
  70. )
  71. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  72. rt := &model.Report{
  73. BusinessID: 1,
  74. FlowID: 1,
  75. UID: 1,
  76. Content: []byte("sguyiuo"),
  77. }
  78. err := d.Report(c, rt)
  79. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  80. ctx.So(err, convey.ShouldBeNil)
  81. })
  82. })
  83. })
  84. }
  85. func TestDaoTaskClear(t *testing.T) {
  86. convey.Convey("TaskClear", t, func(ctx convey.C) {
  87. var (
  88. c = context.Background()
  89. )
  90. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  91. _, err := d.TaskClear(c, time.Now().Add(-3*24*time.Hour), 1000)
  92. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  93. ctx.So(err, convey.ShouldBeNil)
  94. })
  95. })
  96. })
  97. }
  98. func TestDaoCheckFlow(t *testing.T) {
  99. convey.Convey("CheckFlow", t, func(ctx convey.C) {
  100. var (
  101. c = context.Background()
  102. )
  103. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  104. _, err := d.CheckFlow(c, 1, 1)
  105. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  106. ctx.So(err, convey.ShouldBeNil)
  107. })
  108. })
  109. })
  110. }
  111. func TestDaoCreateTask(t *testing.T) {
  112. f := func() error {
  113. for i := 1; i < 100; i++ {
  114. task := &model.Task{
  115. BusinessID: int64(i),
  116. RID: int64(i),
  117. FlowID: int64(i),
  118. }
  119. if err := d.CreateTask(context.Background(), task); err != nil {
  120. return err
  121. }
  122. }
  123. return nil
  124. }
  125. wg := errgroup.Group{}
  126. wg.Go(f)
  127. wg.Go(f)
  128. wg.Go(f)
  129. if err := wg.Wait(); err != nil {
  130. t.Fail()
  131. }
  132. }