mysql_test.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package dao
  2. import (
  3. "testing"
  4. "time"
  5. "go-common/app/service/main/usersuit/model"
  6. "github.com/satori/go.uuid"
  7. "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestDaoBegin(t *testing.T) {
  10. convey.Convey("Begin", t, func(ctx convey.C) {
  11. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  12. tx, err := d.Begin(c)
  13. ctx.Convey("Then err should be nil.tx should not be nil.", func(ctx convey.C) {
  14. ctx.So(err, convey.ShouldBeNil)
  15. ctx.So(tx, convey.ShouldNotBeNil)
  16. })
  17. })
  18. })
  19. }
  20. func TestDaoTxAddInvite(t *testing.T) {
  21. convey.Convey("TxAddInvite", t, func(ctx convey.C) {
  22. var (
  23. tx, _ = d.Begin(c)
  24. inv = &model.Invite{
  25. Mid: 1,
  26. IPng: []byte{1, 1, 1, 1},
  27. Code: uuid.NewV4().String(),
  28. }
  29. )
  30. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  31. affected, err := d.TxAddInvite(c, tx, inv)
  32. ctx.Convey("Then err should be nil.affected should not be nil.", func(ctx convey.C) {
  33. ctx.So(err, convey.ShouldBeNil)
  34. ctx.So(affected, convey.ShouldNotBeNil)
  35. })
  36. })
  37. })
  38. }
  39. func TestDaoUpdateInvite(t *testing.T) {
  40. convey.Convey("UpdateInvite", t, func(ctx convey.C) {
  41. var (
  42. imid = int64(0)
  43. usedAt = int64(0)
  44. code = "2bbf90926c984a53"
  45. )
  46. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  47. affected, err := d.UpdateInvite(c, imid, usedAt, code)
  48. ctx.Convey("Then err should be nil.affected should not be nil.", func(ctx convey.C) {
  49. ctx.So(err, convey.ShouldBeNil)
  50. ctx.So(affected, convey.ShouldNotBeNil)
  51. })
  52. })
  53. })
  54. }
  55. func TestDaoInvite(t *testing.T) {
  56. convey.Convey("Invite", t, func(ctx convey.C) {
  57. var (
  58. code = "2bbf90926c984a53"
  59. )
  60. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  61. res, err := d.Invite(c, code)
  62. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  63. ctx.So(err, convey.ShouldBeNil)
  64. ctx.So(res, convey.ShouldNotBeNil)
  65. })
  66. })
  67. })
  68. }
  69. func TestDaoInvites(t *testing.T) {
  70. convey.Convey("Invites", t, func(ctx convey.C) {
  71. var (
  72. mid = int64(88888970)
  73. )
  74. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  75. res, err := d.Invites(c, mid)
  76. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  77. ctx.So(err, convey.ShouldBeNil)
  78. ctx.So(res, convey.ShouldNotBeNil)
  79. })
  80. })
  81. })
  82. }
  83. func TestDaoCurrentCount(t *testing.T) {
  84. convey.Convey("CurrentCount", t, func(ctx convey.C) {
  85. var (
  86. mid = int64(0)
  87. start = time.Now()
  88. end = time.Now()
  89. )
  90. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  91. res, err := d.CurrentCount(c, mid, start, end)
  92. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  93. ctx.So(err, convey.ShouldBeNil)
  94. ctx.So(res, convey.ShouldNotBeNil)
  95. })
  96. })
  97. })
  98. }