code_test.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "testing"
  6. "time"
  7. "go-common/app/admin/main/coupon/model"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestDaoCountCode(t *testing.T) {
  11. convey.Convey("CountCode", t, func(convCtx convey.C) {
  12. var (
  13. c = context.Background()
  14. a = &model.ArgCouponCode{}
  15. )
  16. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  17. count, err := d.CountCode(c, a)
  18. convCtx.Convey("Then err should be nil.count should not be nil.", func(convCtx convey.C) {
  19. convCtx.So(err, convey.ShouldBeNil)
  20. convCtx.So(count, convey.ShouldNotBeNil)
  21. })
  22. })
  23. })
  24. }
  25. func TestDaoCodeList(t *testing.T) {
  26. convey.Convey("CodeList", t, func(convCtx convey.C) {
  27. var (
  28. c = context.Background()
  29. a = &model.ArgCouponCode{}
  30. )
  31. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  32. res, err := d.CodeList(c, a)
  33. convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
  34. convCtx.So(err, convey.ShouldBeNil)
  35. convCtx.So(res, convey.ShouldNotBeNil)
  36. })
  37. })
  38. })
  39. }
  40. func TestDaoUpdateCodeBlock(t *testing.T) {
  41. convey.Convey("UpdateCodeBlock", t, func(convCtx convey.C) {
  42. var (
  43. c = context.Background()
  44. a = &model.CouponCode{}
  45. )
  46. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  47. err := d.UpdateCodeBlock(c, a)
  48. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  49. convCtx.So(err, convey.ShouldBeNil)
  50. })
  51. })
  52. })
  53. }
  54. func TestDaoCodeByID(t *testing.T) {
  55. convey.Convey("CodeByID", t, func(convCtx convey.C) {
  56. var (
  57. c = context.Background()
  58. id = int64(0)
  59. )
  60. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  61. _, err := d.CodeByID(c, id)
  62. convCtx.Convey("Then err should be nil.r should not be nil.", func(convCtx convey.C) {
  63. convCtx.So(err, convey.ShouldBeNil)
  64. })
  65. })
  66. })
  67. }
  68. func TestDaoBatchAddCode(t *testing.T) {
  69. convey.Convey("BatchAddCode", t, func(convCtx convey.C) {
  70. var (
  71. c = context.Background()
  72. cs = []*model.CouponCode{
  73. {
  74. BatchToken: fmt.Sprintf("%d", time.Now().Unix()),
  75. Code: fmt.Sprintf("%d", time.Now().Unix()),
  76. CouponType: 3,
  77. State: model.CodeStateNotUse,
  78. },
  79. }
  80. )
  81. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  82. err := d.BatchAddCode(c, cs)
  83. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  84. convCtx.So(err, convey.ShouldBeNil)
  85. })
  86. })
  87. })
  88. }
  89. func TestDaowhereSQL(t *testing.T) {
  90. convey.Convey("whereSQL", t, func(convCtx convey.C) {
  91. var (
  92. a = &model.ArgCouponCode{}
  93. )
  94. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  95. sql := whereSQL(a)
  96. convCtx.Convey("Then sql should not be nil.", func(convCtx convey.C) {
  97. convCtx.So(sql, convey.ShouldNotBeNil)
  98. })
  99. })
  100. })
  101. }
  102. func TestDaopageSQL(t *testing.T) {
  103. convey.Convey("pageSQL", t, func(convCtx convey.C) {
  104. var (
  105. pn = int(0)
  106. ps = int(0)
  107. )
  108. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  109. sql := pageSQL(pn, ps)
  110. convCtx.Convey("Then sql should not be nil.", func(convCtx convey.C) {
  111. convCtx.So(sql, convey.ShouldNotBeNil)
  112. })
  113. })
  114. })
  115. }