common_test.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package dao
  2. import (
  3. "context"
  4. "github.com/smartystreets/goconvey/convey"
  5. "testing"
  6. )
  7. func TestDaoparseCursor(t *testing.T) {
  8. convey.Convey("parseCursor", t, func(convCtx convey.C) {
  9. var (
  10. ctx = context.Background()
  11. )
  12. convCtx.Convey("common case", func(convCtx convey.C) {
  13. cursorPrev := ""
  14. cursorNext := ""
  15. cursor, directionNext, err := parseCursor(ctx, cursorPrev, cursorNext)
  16. convCtx.So(err, convey.ShouldBeNil)
  17. convCtx.So(directionNext, convey.ShouldBeTrue)
  18. convCtx.So(cursor.Offset, convey.ShouldEqual, 0)
  19. convCtx.So(cursor.StickRank, convey.ShouldEqual, 0)
  20. })
  21. convCtx.Convey("error case", func(convCtx convey.C) {
  22. cursorPrev := ""
  23. cursorNext := "{\"stick_rank\":1,\"offset\":1}"
  24. _, _, err := parseCursor(ctx, cursorPrev, cursorNext)
  25. convCtx.So(err, convey.ShouldNotBeNil)
  26. cursorPrev = "{\"stick_rank\":0,\"offset\":0}"
  27. cursorNext = ""
  28. _, _, err = parseCursor(ctx, cursorPrev, cursorNext)
  29. convCtx.So(err, convey.ShouldNotBeNil)
  30. cursorPrev = "{stick_rank\":0,\"offset\":0}"
  31. cursorNext = ""
  32. _, _, err = parseCursor(ctx, cursorPrev, cursorNext)
  33. convCtx.So(err, convey.ShouldNotBeNil)
  34. })
  35. })
  36. }
  37. func TestDaogetRedisList(t *testing.T) {
  38. convey.Convey("getRedisList", t, func(convCtx convey.C) {
  39. var (
  40. ctx = context.Background()
  41. key = "stick:ttttt"
  42. )
  43. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  44. list, err := d.getRedisList(ctx, key)
  45. convCtx.Convey("Then err should be nil.list should not be nil.", func(convCtx convey.C) {
  46. convCtx.So(err, convey.ShouldBeNil)
  47. convCtx.So(list, convey.ShouldBeNil)
  48. })
  49. })
  50. })
  51. }
  52. func TestDaosetRedisList(t *testing.T) {
  53. convey.Convey("setRedisList", t, func(convCtx convey.C) {
  54. var (
  55. ctx = context.Background()
  56. key = "stick:topic"
  57. list = []int64{}
  58. )
  59. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  60. err := d.setRedisList(ctx, key, list)
  61. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  62. convCtx.So(err, convey.ShouldBeNil)
  63. })
  64. })
  65. })
  66. }