engine_test.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package service
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. "go-common/app/admin/main/aegis/model"
  7. "go-common/app/admin/main/aegis/model/resource"
  8. )
  9. func TestServiceListBizFlow(t *testing.T) {
  10. var (
  11. c = context.TODO()
  12. )
  13. convey.Convey("ListBizFlow", t, func(ctx convey.C) {
  14. r, err := s.ListBizFlow(c, 1, []int64{1}, []int64{1, 2})
  15. for _, item := range r {
  16. t.Logf("bizflow(%+v)", item)
  17. }
  18. ctx.Convey("Then err should be nil.r should not be nil.", func(ctx convey.C) {
  19. ctx.So(err, convey.ShouldBeNil)
  20. })
  21. })
  22. }
  23. //conf = biz=1, mid="1,2",oid="oid1,oid3", oid="oid6"&extra2="3,4"
  24. var grayTest = []struct {
  25. AddOpt *model.AddOption
  26. Expect bool
  27. }{
  28. {AddOpt: &model.AddOption{Resource: resource.Resource{
  29. BusinessID: 100,
  30. MID: 1,
  31. OID: "oid1",
  32. }},
  33. Expect: true,
  34. },
  35. {AddOpt: &model.AddOption{Resource: resource.Resource{
  36. BusinessID: 100,
  37. MID: 2,
  38. OID: "oid2",
  39. }},
  40. Expect: true,
  41. },
  42. {AddOpt: &model.AddOption{Resource: resource.Resource{
  43. BusinessID: 100,
  44. MID: 3,
  45. OID: "oid3",
  46. }},
  47. Expect: true,
  48. },
  49. {AddOpt: &model.AddOption{Resource: resource.Resource{
  50. BusinessID: 100,
  51. MID: 4,
  52. OID: "oid4",
  53. }},
  54. Expect: false,
  55. },
  56. {AddOpt: &model.AddOption{Resource: resource.Resource{
  57. BusinessID: 200,
  58. MID: 5,
  59. OID: "oid5",
  60. }},
  61. Expect: true,
  62. },
  63. {AddOpt: &model.AddOption{Resource: resource.Resource{
  64. BusinessID: 100,
  65. MID: 6,
  66. OID: "oid6",
  67. }},
  68. Expect: false,
  69. },
  70. {AddOpt: &model.AddOption{Resource: resource.Resource{
  71. BusinessID: 100,
  72. MID: 7,
  73. OID: "oid6",
  74. Extra2: 5,
  75. }},
  76. Expect: false,
  77. },
  78. {AddOpt: &model.AddOption{Resource: resource.Resource{
  79. BusinessID: 100,
  80. MID: 7,
  81. OID: "oid6",
  82. Extra2: 3,
  83. }},
  84. Expect: true,
  85. },
  86. {AddOpt: &model.AddOption{Resource: resource.Resource{
  87. BusinessID: 200, //没配置灰度
  88. MID: 7,
  89. OID: "oid6",
  90. Extra2: 10,
  91. }},
  92. Expect: true,
  93. },
  94. }
  95. func TestServiceGray(t *testing.T) {
  96. convey.Convey("Gray", t, func(ctx convey.C) {
  97. optid := 0
  98. for biz, options := range s.gray {
  99. for _, fields := range options {
  100. optid++
  101. t.Logf("gray biz(%d) options.id(%d), options.fields.len=%d, field(%+v)\r\n", biz, optid, len(fields), fields)
  102. }
  103. }
  104. ctx.Convey("No return values", func(ctx convey.C) {
  105. for _, item := range grayTest {
  106. reality := s.Gray(item.AddOpt)
  107. t.Logf("gray opt(%+v) reality(%v) expect(%v)", item.AddOpt, reality, item.Expect)
  108. convey.So(reality, convey.ShouldEqual, item.Expect)
  109. }
  110. })
  111. })
  112. }
  113. func TestService_Auth(t *testing.T) {
  114. convey.Convey("Auth", t, func(ctx convey.C) {
  115. auth, err := s.Auth(cntx, 421)
  116. ctx.Convey("auth ok", func(ctx convey.C) {
  117. ctx.So(err, convey.ShouldBeNil)
  118. t.Logf("auth(%+v)", auth)
  119. })
  120. })
  121. }