rule_test.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func testRuleDaoImplGetByCond(t *testing.T) {
  8. var (
  9. c = context.TODO()
  10. cond = &Condition{}
  11. )
  12. convey.Convey("GetByCond", t, func(ctx convey.C) {
  13. rules, totalCounts, err := rdi.GetByCond(c, cond)
  14. ctx.Convey("Then err should be nil.rules,totalCounts should not be nil.", func(ctx convey.C) {
  15. ctx.So(err, convey.ShouldBeNil)
  16. ctx.So(totalCounts, convey.ShouldNotBeNil)
  17. ctx.So(rules, convey.ShouldNotBeNil)
  18. })
  19. })
  20. }
  21. func testRuleDaoImplUpdate(t *testing.T) {
  22. var (
  23. c = context.TODO()
  24. r = &Rule{}
  25. )
  26. convey.Convey("Update", t, func(ctx convey.C) {
  27. p1, err := rdi.Update(c, r)
  28. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  29. ctx.So(err, convey.ShouldBeNil)
  30. ctx.So(p1, convey.ShouldNotBeNil)
  31. })
  32. })
  33. }
  34. func testRuleDaoImplInsert(t *testing.T) {
  35. var (
  36. c = context.TODO()
  37. r = &Rule{}
  38. )
  39. convey.Convey("Insert", t, func(ctx convey.C) {
  40. p1, err := rdi.Insert(c, r)
  41. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  42. ctx.So(err, convey.ShouldBeNil)
  43. ctx.So(p1, convey.ShouldNotBeNil)
  44. })
  45. })
  46. }
  47. func testRuleDaoImplGetByID(t *testing.T) {
  48. var (
  49. c = context.TODO()
  50. id = int64(0)
  51. )
  52. convey.Convey("GetByID", t, func(ctx convey.C) {
  53. p1, err := rdi.GetByID(c, id)
  54. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  55. ctx.So(err, convey.ShouldBeNil)
  56. ctx.So(p1, convey.ShouldNotBeNil)
  57. })
  58. })
  59. }
  60. func testRuleDaoImplDaoGetByIDs(t *testing.T) {
  61. var (
  62. c = context.TODO()
  63. ids = []int64{}
  64. )
  65. convey.Convey("GetByIDs", t, func(ctx convey.C) {
  66. p1, err := rdi.GetByIDs(c, ids)
  67. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  68. ctx.So(err, convey.ShouldBeNil)
  69. ctx.So(p1, convey.ShouldNotBeNil)
  70. })
  71. })
  72. }
  73. func testRuleDaoImplGetByAreaAndLimitType(t *testing.T) {
  74. var (
  75. c = context.TODO()
  76. cond = &Condition{}
  77. )
  78. convey.Convey("GetByAreaAndLimitType", t, func(ctx convey.C) {
  79. p1, err := rdi.GetByAreaAndLimitType(c, cond)
  80. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  81. ctx.So(err, convey.ShouldBeNil)
  82. ctx.So(p1, convey.ShouldNotBeNil)
  83. })
  84. })
  85. }
  86. func testRuleDaoImplGetByAreaAndTypeAndScope(t *testing.T) {
  87. var (
  88. c = context.TODO()
  89. cond = &Condition{}
  90. )
  91. convey.Convey("GetByAreaAndTypeAndScope", t, func(ctx convey.C) {
  92. p1, err := rdi.GetByAreaAndTypeAndScope(c, cond)
  93. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  94. ctx.So(err, convey.ShouldBeNil)
  95. ctx.So(p1, convey.ShouldNotBeNil)
  96. })
  97. })
  98. }
  99. func testRuleDaoImplGetByArea(t *testing.T) {
  100. var (
  101. c = context.TODO()
  102. cond = &Condition{}
  103. )
  104. convey.Convey("GetByArea", t, func(ctx convey.C) {
  105. p1, err := rdi.GetByArea(c, cond)
  106. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  107. ctx.So(err, convey.ShouldBeNil)
  108. ctx.So(p1, convey.ShouldNotBeNil)
  109. })
  110. })
  111. }