net_control_test.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. package service
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestServicestartNet(t *testing.T) {
  8. var (
  9. rid = int64(1)
  10. biz = int64(1)
  11. nid = int64(1)
  12. tx, _ = s.gorm.BeginTx(context.TODO())
  13. )
  14. convey.Convey("startNet", t, func(ctx convey.C) {
  15. result, err := s.startNet(context.TODO(), biz, nid)
  16. if err == nil {
  17. t.Logf("result(%+v) result.resulttoken(%+v)", result, result.ResultToken)
  18. } else {
  19. return
  20. }
  21. result.RID = rid
  22. err = s.reachNewFlowDB(context.TODO(), tx, result)
  23. if err == nil {
  24. tx.Commit()
  25. }
  26. s.afterReachNewFlow(context.TODO(), result, biz)
  27. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  28. ctx.So(err, convey.ShouldBeNil)
  29. })
  30. })
  31. }
  32. func TestServicecancelNet(t *testing.T) {
  33. var (
  34. rid = []int64{1, 3, 4}
  35. tx, _ = s.gorm.BeginTx(context.TODO())
  36. )
  37. convey.Convey("cancelNet", t, func(ctx convey.C) {
  38. _, err := s.cancelNet(context.TODO(), tx, rid)
  39. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  40. ctx.So(err, convey.ShouldBeNil)
  41. })
  42. })
  43. }
  44. /**
  45. 批量
  46. */
  47. func TestServicefetchBatchOperations(t *testing.T) {
  48. convey.Convey("fetchBatchOperations", t, func(ctx convey.C) {
  49. result, err := s.fetchBatchOperations(cntx, 1, 0)
  50. for _, item := range result {
  51. t.Logf("operations(%+v)", item)
  52. }
  53. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  54. ctx.So(err, convey.ShouldBeNil)
  55. })
  56. })
  57. }
  58. func TestServicecomputeBatchTriggerResult(t *testing.T) {
  59. var (
  60. rid = int64(1) //running at flow(1), flow(1)->t1->flow(3)
  61. binds = []int64{1} //bind by transition 3 & 1
  62. )
  63. convey.Convey("computeBatchTriggerResult", t, func(ctx convey.C) {
  64. result, err := s.computeBatchTriggerResult(cntx, 1, rid, binds)
  65. if err != nil {
  66. return
  67. }
  68. tx, _ := s.gorm.BeginTx(cntx)
  69. s.reachNewFlowDB(cntx, tx, result)
  70. err = tx.Commit().Error
  71. t.Logf("result(%+v) submittoken(%+v) resulttoken(%+v)", result, result.SubmitToken, result.ResultToken)
  72. ctx.Convey("Then err should be nil.result should not be nil.", func(ctx convey.C) {
  73. ctx.So(err, convey.ShouldBeNil)
  74. ctx.So(result, convey.ShouldNotBeNil)
  75. })
  76. })
  77. }
  78. /**
  79. *资源单个处理
  80. */
  81. func TestServicefetchResourceTranInfo(t *testing.T) {
  82. convey.Convey("fetchResourceTranInfo", t, func(ctx convey.C) {
  83. result, err := s.fetchResourceTranInfo(cntx, 1, 1, 0)
  84. t.Logf("result(%+v)", result)
  85. for _, item := range result.Operations {
  86. t.Logf("operations(%+v)", item)
  87. }
  88. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  89. ctx.So(err, convey.ShouldBeNil)
  90. })
  91. })
  92. }
  93. func TestServicecomputeTriggerResult(t *testing.T) {
  94. var (
  95. rid = int64(1)
  96. flowID = int64(1)
  97. binds = []int64{23}
  98. )
  99. convey.Convey("computeTriggerResult", t, func(ctx convey.C) {
  100. result, err := s.computeTriggerResult(cntx, rid, flowID, binds)
  101. if err == nil {
  102. t.Logf("result(%+v) submittoken(%+v) resulttoken(%+v)", result, result.SubmitToken, result.ResultToken)
  103. s.sendNetTriggerLog(context.TODO(), result)
  104. }
  105. ctx.Convey("Then err should be nil.result should not be nil.", func(ctx convey.C) {
  106. ctx.So(err, convey.ShouldBeNil)
  107. ctx.So(result, convey.ShouldNotBeNil)
  108. })
  109. })
  110. }
  111. /**
  112. * 任务单个处理
  113. */
  114. func TestServicefetchTaskTransitionInfo(t *testing.T) {
  115. convey.Convey("fetchTaskTranInfo", t, func(ctx convey.C) {
  116. result, err := s.fetchTaskTranInfo(cntx, 1, 1, 1)
  117. t.Logf("result(%+v)", result)
  118. for _, item := range result.Operations {
  119. t.Logf("operations(%+v)", item)
  120. }
  121. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  122. ctx.So(err, convey.ShouldBeNil)
  123. })
  124. })
  125. }
  126. /**
  127. * 跳流程
  128. */
  129. func TestServicejumpFlow(t *testing.T) {
  130. var (
  131. tx, _ = s.gorm.BeginTx(context.TODO())
  132. )
  133. convey.Convey("jumpFlow", t, func(ctx convey.C) {
  134. result, err := s.jumpFlow(cntx, tx, 1, 1, 2, []int64{10})
  135. if err != nil {
  136. return
  137. }
  138. t.Logf("result(%+v) resulttoken(%+v) submittoken(%+v)", result, result.ResultToken, result.SubmitToken)
  139. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  140. ctx.So(err, convey.ShouldBeNil)
  141. })
  142. })
  143. }
  144. func TestServicefetchJumpFlowInfo(t *testing.T) {
  145. convey.Convey("FetchJumpFlowInfo", t, func(ctx convey.C) {
  146. res, err := s.FetchJumpFlowInfo(cntx, 1)
  147. for _, item := range res.Operations {
  148. t.Logf("operations(%+v)", item)
  149. }
  150. for _, item := range res.Flows {
  151. t.Logf("flowArr(%+v)", item)
  152. }
  153. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  154. ctx.So(err, convey.ShouldBeNil)
  155. })
  156. })
  157. }