user_gift_test.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestDaoGetBag(t *testing.T) {
  8. convey.Convey("GetBag", t, func(c convey.C) {
  9. var (
  10. ctx = context.Background()
  11. uid = int64(0)
  12. giftID = int64(0)
  13. expireAt = int64(0)
  14. )
  15. c.Convey("When everything gose positive", func(c convey.C) {
  16. res, err := d.GetBag(ctx, uid, giftID, expireAt)
  17. c.Convey("Then err should be nil.res should not be nil.", func(c convey.C) {
  18. c.So(err, convey.ShouldBeNil)
  19. c.So(res, convey.ShouldNotBeNil)
  20. })
  21. })
  22. })
  23. }
  24. func TestDaoUpdateBagNum(t *testing.T) {
  25. convey.Convey("UpdateBagNum", t, func(c convey.C) {
  26. var (
  27. ctx = context.Background()
  28. uid = int64(0)
  29. id = int64(0)
  30. num = int64(0)
  31. )
  32. c.Convey("When everything gose positive", func(c convey.C) {
  33. affected, err := d.UpdateBagNum(ctx, uid, id, num)
  34. c.Convey("Then err should be nil.affected should not be nil.", func(c convey.C) {
  35. c.So(err, convey.ShouldBeNil)
  36. c.So(affected, convey.ShouldNotBeNil)
  37. })
  38. })
  39. })
  40. }
  41. func TestDaoAddBag(t *testing.T) {
  42. convey.Convey("AddBag", t, func(c convey.C) {
  43. var (
  44. ctx = context.Background()
  45. uid = int64(0)
  46. giftID = int64(0)
  47. giftNum = int64(0)
  48. expireAt = int64(0)
  49. )
  50. c.Convey("When everything gose positive", func(c convey.C) {
  51. affected, err := d.AddBag(ctx, uid, giftID, giftNum, expireAt)
  52. c.Convey("Then err should be nil.affected should not be nil.", func(c convey.C) {
  53. c.So(err, convey.ShouldBeNil)
  54. c.So(affected, convey.ShouldNotBeNil)
  55. })
  56. })
  57. })
  58. }
  59. func TestDaoGetBagByID(t *testing.T) {
  60. convey.Convey("GetBagByID", t, func(c convey.C) {
  61. var (
  62. ctx = context.Background()
  63. uid = int64(0)
  64. id = int64(0)
  65. )
  66. c.Convey("When everything gose positive", func(c convey.C) {
  67. res, err := d.GetBagByID(ctx, uid, id)
  68. c.Convey("Then err should be nil.res should not be nil.", func(c convey.C) {
  69. c.So(err, convey.ShouldBeNil)
  70. c.So(res, convey.ShouldNotBeNil)
  71. })
  72. })
  73. })
  74. }
  75. func TestDaogetPostFix(t *testing.T) {
  76. convey.Convey("getPostFix", t, func(c convey.C) {
  77. var (
  78. uid = int64(1)
  79. )
  80. c.Convey("When everything gose positive", func(c convey.C) {
  81. p1 := getPostFix(uid)
  82. c.Convey("Then p1 should not be nil.", func(c convey.C) {
  83. c.So(p1, convey.ShouldNotBeNil)
  84. c.So(p1, convey.ShouldEqual, "c")
  85. })
  86. })
  87. })
  88. }
  89. func TestDaoGetBagList(t *testing.T) {
  90. convey.Convey("GetBagList", t, func(c convey.C) {
  91. var (
  92. ctx = context.Background()
  93. uid = int64(0)
  94. )
  95. c.Convey("When everything gose positive", func(c convey.C) {
  96. list, err := d.GetBagList(ctx, uid)
  97. c.Convey("Then err should be nil.list should be nil.", func(c convey.C) {
  98. c.So(err, convey.ShouldBeNil)
  99. c.So(list, convey.ShouldBeNil)
  100. })
  101. })
  102. })
  103. }