redis_test.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. "go-common/app/service/main/figure/model"
  7. )
  8. func TestDaofigureKey(t *testing.T) {
  9. convey.Convey("figureKey", t, func(ctx convey.C) {
  10. var (
  11. mid = int64(46333)
  12. )
  13. ctx.Convey("When everything right.", func(ctx convey.C) {
  14. key := figureKey(mid)
  15. ctx.Convey("Then key should equal f:key.", func(ctx convey.C) {
  16. ctx.So(key, convey.ShouldEqual, "f:46333")
  17. })
  18. })
  19. })
  20. }
  21. func TestDaoPingRedis(t *testing.T) {
  22. convey.Convey("PingRedis", t, func(ctx convey.C) {
  23. var (
  24. c = context.Background()
  25. )
  26. ctx.Convey("When everything right.", func(ctx convey.C) {
  27. err := d.PingRedis(c)
  28. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  29. ctx.So(err, convey.ShouldBeNil)
  30. })
  31. })
  32. })
  33. }
  34. func TestDaoAddFigureInfoCache(t *testing.T) {
  35. convey.Convey("AddFigureInfoCache", t, func(ctx convey.C) {
  36. var (
  37. c = context.Background()
  38. figure = &model.Figure{
  39. Mid: 46333,
  40. Score: 2333,
  41. LawfulScore: 123,
  42. WideScore: 321,
  43. FriendlyScore: 19999,
  44. BountyScore: 1,
  45. CreativityScore: 0,
  46. Ver: 2333,
  47. }
  48. )
  49. ctx.Convey("When add FigureInfoCache.", func(ctx convey.C) {
  50. err := d.AddFigureInfoCache(c, figure)
  51. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  52. ctx.So(err, convey.ShouldBeNil)
  53. ctx.Convey("When get FigureInfoCache.", func(ctx convey.C) {
  54. figure2, err := d.FigureInfoCache(c, figure.Mid)
  55. ctx.Convey("Then err should be nil.figure2 should resemble figure.", func(ctx convey.C) {
  56. ctx.So(err, convey.ShouldBeNil)
  57. ctx.So(figure2, convey.ShouldResemble, figure)
  58. })
  59. })
  60. ctx.Convey("When get FigureBatchInfoCache.", func(ctx convey.C) {
  61. figures, missIndex, err := d.FigureBatchInfoCache(c, []int64{figure.Mid})
  62. ctx.Convey("Then err should be nil.missIndex should be empty.figures should have length 1.figuers[0] should resemble figure", func(ctx convey.C) {
  63. ctx.So(err, convey.ShouldBeNil)
  64. ctx.So(missIndex, convey.ShouldBeEmpty)
  65. ctx.So(figures, convey.ShouldHaveLength, 1)
  66. ctx.So(figures[0], convey.ShouldResemble, figure)
  67. })
  68. })
  69. })
  70. })
  71. })
  72. }