user_black_test.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package dao
  2. import (
  3. "context"
  4. "github.com/smartystreets/goconvey/convey"
  5. "go-common/app/service/bbq/user/internal/model"
  6. xtime "go-common/library/time"
  7. "testing"
  8. "time"
  9. )
  10. func TestDaoTxAddUserBlack(t *testing.T) {
  11. convey.Convey("TxAddUserBlack", t, func(ctx convey.C) {
  12. var (
  13. c = context.Background()
  14. mid = int64(88895104)
  15. upMid = int64(88895105)
  16. )
  17. tx, _ := d.BeginTran(c)
  18. defer func() {
  19. tx.Rollback()
  20. }()
  21. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  22. num, err := d.TxAddUserBlack(c, tx, mid, upMid)
  23. ctx.Convey("Then err should be nil.num should not be nil.", func(ctx convey.C) {
  24. ctx.So(err, convey.ShouldBeNil)
  25. ctx.So(num, convey.ShouldNotBeNil)
  26. })
  27. })
  28. })
  29. }
  30. func TestDaoTxCancelUserBlack(t *testing.T) {
  31. convey.Convey("TxCancelUserBlack", t, func(ctx convey.C) {
  32. var (
  33. c = context.Background()
  34. mid = int64(88895104)
  35. upMid = int64(88895105)
  36. )
  37. tx, _ := d.BeginTran(c)
  38. defer func() {
  39. tx.Rollback()
  40. }()
  41. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  42. num, err := d.TxCancelUserBlack(c, tx, mid, upMid)
  43. ctx.Convey("Then err should be nil.num should not be nil.", func(ctx convey.C) {
  44. ctx.So(err, convey.ShouldBeNil)
  45. ctx.So(num, convey.ShouldNotBeNil)
  46. })
  47. })
  48. })
  49. }
  50. func TestDaoFetchBlackList(t *testing.T) {
  51. convey.Convey("FetchBlackList", t, func(ctx convey.C) {
  52. var (
  53. c = context.Background()
  54. mid = int64(88895104)
  55. )
  56. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  57. upMid, err := d.FetchBlackList(c, mid)
  58. ctx.Convey("Then err should be nil.upMid should not be nil.", func(ctx convey.C) {
  59. ctx.So(err, convey.ShouldBeNil)
  60. ctx.So(upMid, convey.ShouldNotBeNil)
  61. })
  62. })
  63. })
  64. }
  65. func TestDaoFetchPartBlackList(t *testing.T) {
  66. convey.Convey("FetchPartBlackList", t, func(ctx convey.C) {
  67. var (
  68. c = context.Background()
  69. mid = int64(88895104)
  70. cursor model.CursorValue
  71. size = int(10)
  72. )
  73. cursor.CursorID = model.MaxInt64
  74. cursor.CursorTime = xtime.Time(time.Now().Unix())
  75. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  76. MID2IDMap, blackMIDs, err := d.FetchPartBlackList(c, mid, cursor, size)
  77. ctx.Convey("Then err should be nil.MID2IDMap,blackMIDs should not be nil.", func(ctx convey.C) {
  78. ctx.So(err, convey.ShouldBeNil)
  79. ctx.So(blackMIDs, convey.ShouldNotBeNil)
  80. ctx.So(MID2IDMap, convey.ShouldNotBeNil)
  81. })
  82. })
  83. })
  84. }
  85. func TestDaoIsBlack(t *testing.T) {
  86. convey.Convey("IsBlack", t, func(ctx convey.C) {
  87. var (
  88. c = context.Background()
  89. mid = int64(88895104)
  90. candidateMIDs = []int64{88895105}
  91. )
  92. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  93. MIDMap := d.IsBlack(c, mid, candidateMIDs)
  94. ctx.Convey("Then MIDMap should not be nil.", func(ctx convey.C) {
  95. ctx.So(MIDMap, convey.ShouldNotBeNil)
  96. })
  97. })
  98. })
  99. }