trade_test.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "testing"
  6. "time"
  7. "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestDaoAddGoods(t *testing.T) {
  10. convey.Convey("AddGoods", t, func(ctx convey.C) {
  11. var (
  12. c = context.Background()
  13. fields = "ex_product_id, ex_resource_id, goods_type, is_display, discount"
  14. values = fmt.Sprintf("('%s', 1, 1, 1, 100)", time.Now().Format("2006-01-02 15:04:05"))
  15. )
  16. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  17. p1, err := d.AddGoods(c, fields, values)
  18. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  19. ctx.So(err, convey.ShouldBeNil)
  20. ctx.So(p1, convey.ShouldNotBeNil)
  21. })
  22. })
  23. })
  24. }
  25. func TestDaoUpdateGoods(t *testing.T) {
  26. convey.Convey("UpdateGoods", t, func(ctx convey.C) {
  27. var (
  28. c = context.Background()
  29. set = "is_display=1"
  30. where = "is_deleted=0"
  31. IDs = []int64{1}
  32. )
  33. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  34. p1, err := d.UpdateGoods(c, set, where, IDs)
  35. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  36. ctx.So(err, convey.ShouldBeNil)
  37. ctx.So(p1, convey.ShouldNotBeNil)
  38. })
  39. })
  40. })
  41. }
  42. func TestDaoGoodsList(t *testing.T) {
  43. convey.Convey("GoodsList", t, func(ctx convey.C) {
  44. var (
  45. c = context.Background()
  46. where = "is_deleted=0"
  47. from = int(0)
  48. limit = int(0)
  49. )
  50. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  51. res, err := d.GoodsList(c, where, from, limit)
  52. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  53. ctx.So(err, convey.ShouldBeNil)
  54. ctx.So(res, convey.ShouldNotBeNil)
  55. })
  56. })
  57. })
  58. }
  59. func TestDaoGoodsCount(t *testing.T) {
  60. convey.Convey("GoodsCount", t, func(ctx convey.C) {
  61. var (
  62. c = context.Background()
  63. where = "is_deleted=0"
  64. )
  65. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  66. total, err := d.GoodsCount(c, where)
  67. ctx.Convey("Then err should be nil.total should not be nil.", func(ctx convey.C) {
  68. ctx.So(err, convey.ShouldBeNil)
  69. ctx.So(total, convey.ShouldNotBeNil)
  70. })
  71. })
  72. })
  73. }
  74. func TestDaoOrderCount(t *testing.T) {
  75. convey.Convey("OrderCount", t, func(ctx convey.C) {
  76. var (
  77. c = context.Background()
  78. where = "is_deleted=0"
  79. )
  80. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  81. total, err := d.OrderCount(c, where)
  82. ctx.Convey("Then err should be nil.total should not be nil.", func(ctx convey.C) {
  83. ctx.So(err, convey.ShouldBeNil)
  84. ctx.So(total, convey.ShouldNotBeNil)
  85. })
  86. })
  87. })
  88. }
  89. func TestDaoOrderList(t *testing.T) {
  90. convey.Convey("OrderList", t, func(ctx convey.C) {
  91. var (
  92. c = context.Background()
  93. where = "is_deleted=0"
  94. from = int(0)
  95. limit = int(0)
  96. )
  97. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  98. res, err := d.OrderList(c, where, from, limit)
  99. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  100. ctx.So(err, convey.ShouldBeNil)
  101. ctx.So(res, convey.ShouldNotBeNil)
  102. })
  103. })
  104. })
  105. }