token_test.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package service
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/admin/main/aegis/model/net"
  6. "github.com/smartystreets/goconvey/convey"
  7. "time"
  8. )
  9. func TestServiceGetTokenList(t *testing.T) {
  10. var (
  11. c = context.TODO()
  12. pm = &net.ListTokenParam{
  13. NetID: 1,
  14. }
  15. )
  16. convey.Convey("GetTokenList", t, func(ctx convey.C) {
  17. result, err := s.GetTokenList(c, pm)
  18. ctx.Convey("Then err should be nil.result should not be nil.", func(ctx convey.C) {
  19. ctx.So(err, convey.ShouldBeNil)
  20. ctx.So(result, convey.ShouldNotBeNil)
  21. })
  22. })
  23. }
  24. func TestServiceShowToken(t *testing.T) {
  25. var (
  26. c = context.TODO()
  27. id = int64(20)
  28. )
  29. convey.Convey("ShowToken", t, func(ctx convey.C) {
  30. n, err := s.ShowToken(c, id)
  31. ctx.Convey("Then err should be nil.n should not be nil.", func(ctx convey.C) {
  32. ctx.So(err, convey.ShouldBeNil)
  33. ctx.So(n, convey.ShouldNotBeNil)
  34. })
  35. })
  36. }
  37. func TestServicecheckTokenUnique(t *testing.T) {
  38. var (
  39. netID = int64(0)
  40. name = ""
  41. compare = int8(0)
  42. value = ""
  43. )
  44. convey.Convey("checkTokenUnique", t, func(ctx convey.C) {
  45. err, msg := s.checkTokenUnique(cntx, netID, name, compare, value)
  46. ctx.Convey("Then err should be nil.msg should not be nil.", func(ctx convey.C) {
  47. ctx.So(msg, convey.ShouldNotBeNil)
  48. ctx.So(err, convey.ShouldBeNil)
  49. })
  50. })
  51. }
  52. func TestServiceAddToken(t *testing.T) {
  53. var (
  54. c = context.TODO()
  55. no = &net.Token{
  56. NetID: 1,
  57. ChName: "创建时间",
  58. Name: "time",
  59. Compare: net.TokenCompareAssign,
  60. Value: time.Now().String(),
  61. Type: net.TokenTypeInt16,
  62. }
  63. )
  64. convey.Convey("AddToken", t, func(ctx convey.C) {
  65. id, err, msg := s.AddToken(c, no)
  66. ctx.Convey("Then err should be nil.id,msg should not be nil.", func(ctx convey.C) {
  67. ctx.So(msg, convey.ShouldNotBeNil)
  68. ctx.So(err, convey.ShouldBeNil)
  69. ctx.So(id, convey.ShouldNotBeNil)
  70. })
  71. })
  72. }
  73. func TestServicefetchOldBindAndLog(t *testing.T) {
  74. convey.Convey("fetchOldBindAndLog", t, func(ctx convey.C) {
  75. all, logs, err := s.fetchOldBindAndLog(cntx, 3, net.BindTranType)
  76. for _, item := range all {
  77. t.Logf("s.fetchOldBindAndLog all item(%+v)", item)
  78. }
  79. t.Logf("logs(%v)", logs)
  80. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  81. ctx.So(err, convey.ShouldBeNil)
  82. })
  83. })
  84. }
  85. func TestServicecompareTransitionBind(t *testing.T) {
  86. var (
  87. elementID = int64(1)
  88. binds = []*net.TokenBindParam{
  89. {ID: 26, TokenID: "20", ChName: "批量通过"},
  90. {ID: 24, TokenID: "21,20", ChName: "可以通过"},
  91. }
  92. )
  93. convey.Convey("compareTransitionBind", t, func(ctx convey.C) {
  94. tx, _ := s.gorm.BeginTx(context.Background())
  95. diff, _, err, msg := s.compareTranBind(cntx, tx, elementID, binds, true)
  96. t.Logf("s.compareTranBind diff(%v) msg(%s)", diff, msg)
  97. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  98. ctx.So(err, convey.ShouldBeNil)
  99. })
  100. })
  101. }