direction_test.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/admin/main/aegis/model/net"
  5. "testing"
  6. "encoding/json"
  7. "github.com/smartystreets/goconvey/convey"
  8. "go-common/app/admin/main/aegis/model"
  9. )
  10. func TestServiceShowDirection(t *testing.T) {
  11. var (
  12. c = context.TODO()
  13. id = int64(1)
  14. )
  15. convey.Convey("ShowDirection", t, func(ctx convey.C) {
  16. r, err := s.ShowDirection(c, id)
  17. ctx.Convey("Then err should be nil.r should not be nil.", func(ctx convey.C) {
  18. ctx.So(err, convey.ShouldBeNil)
  19. ctx.So(r, convey.ShouldNotBeNil)
  20. })
  21. d := r.Direction
  22. t.Logf("%+v", d)
  23. oper := &model.NetConfOper{
  24. OID: d.ID,
  25. Action: model.LogNetActionUpdate,
  26. UID: d.UID,
  27. NetID: d.NetID,
  28. FlowID: d.FlowID,
  29. TranID: d.TransitionID,
  30. Diff: []string{
  31. model.LogFieldTemp(model.LogFieldDirection, net.DirDirectionDesc[d.Direction], "", false),
  32. model.LogFieldTemp(model.LogFieldOrder, net.DirOrderDesc[d.Order], "", false),
  33. model.LogFieldTemp(model.LogFieldGuard, d.Guard, "", false),
  34. model.LogFieldTemp(model.LogFieldOutput, d.Output, "", false),
  35. },
  36. }
  37. i, _ := json.Marshal(oper)
  38. t.Logf("%s", i)
  39. s.sendNetConfLog(c, model.LogTypeDirConf, oper)
  40. //{"diff":"[指向]为[从节点指向变化]","[顺序]为[]","[输出规则]为[]"}
  41. })
  42. }
  43. func TestServiceGetDirectionList(t *testing.T) {
  44. var (
  45. c = context.TODO()
  46. pm = &net.ListDirectionParam{NetID: 1}
  47. )
  48. convey.Convey("GetDirectionList", t, func(ctx convey.C) {
  49. result, err := s.GetDirectionList(c, pm)
  50. ctx.Convey("Then err should be nil.result should not be nil.", func(ctx convey.C) {
  51. ctx.So(err, convey.ShouldBeNil)
  52. ctx.So(result, convey.ShouldNotBeNil)
  53. })
  54. })
  55. }
  56. func TestServicecheckDirectionUnique(t *testing.T) {
  57. var (
  58. netID = int64(0)
  59. FlowID = int64(0)
  60. transitionID = int64(0)
  61. direction = int8(0)
  62. )
  63. convey.Convey("checkDirectionUnique", t, func(ctx convey.C) {
  64. err, msg := s.checkDirectionUnique(cntx, netID, FlowID, transitionID, direction)
  65. ctx.Convey("Then err should be nil.msg should not be nil.", func(ctx convey.C) {
  66. ctx.So(msg, convey.ShouldNotBeNil)
  67. ctx.So(err, convey.ShouldBeNil)
  68. })
  69. })
  70. }
  71. func TestServicecheckDirectionBindAvailable(t *testing.T) {
  72. var (
  73. flowID = int64(0)
  74. transitionID = int64(0)
  75. )
  76. convey.Convey("checkDirectionBindAvailable", t, func(ctx convey.C) {
  77. err := s.checkDirectionBindAvailable(cntx, flowID, transitionID)
  78. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  79. ctx.So(err, convey.ShouldBeNil)
  80. })
  81. })
  82. }
  83. func TestServiceisDirEnable(t *testing.T) {
  84. var (
  85. dir = &net.Direction{}
  86. )
  87. convey.Convey("isDirEnable", t, func(ctx convey.C) {
  88. enable := s.isDirEnable(dir)
  89. ctx.Convey("Then err should be nil.enable should not be nil.", func(ctx convey.C) {
  90. ctx.So(enable, convey.ShouldNotBeNil)
  91. })
  92. })
  93. }
  94. func TestServicegetInDirTransitionID(t *testing.T) {
  95. var (
  96. flowID = int64(1)
  97. )
  98. convey.Convey("fetchFlowNextEnableDirs", t, func(ctx convey.C) {
  99. dirs, err := s.fetchFlowNextEnableDirs(cntx, flowID)
  100. ctx.Convey("Then err should be nil.tids,dirList should not be nil.", func(ctx convey.C) {
  101. ctx.So(err, convey.ShouldBeNil)
  102. ctx.So(dirs, convey.ShouldNotBeNil)
  103. })
  104. })
  105. }