redis_test.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/service/main/thumbup/model"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaohashStatsKey(t *testing.T) {
  9. var (
  10. businessID = int64(1)
  11. originID = int64(1)
  12. )
  13. convey.Convey("hashStatsKey", t, func(ctx convey.C) {
  14. p1 := hashStatsKey(businessID, originID)
  15. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  16. ctx.So(p1, convey.ShouldNotBeNil)
  17. })
  18. })
  19. }
  20. func TestDaoExpireHashStatsCache(t *testing.T) {
  21. var (
  22. c = context.TODO()
  23. businessID = int64(1)
  24. originID = int64(1)
  25. )
  26. convey.Convey("ExpireHashStatsCache", t, func(ctx convey.C) {
  27. ok, err := d.ExpireHashStatsCache(c, businessID, originID)
  28. ctx.Convey("Then err should be nil.ok should not be nil.", func(ctx convey.C) {
  29. ctx.So(err, convey.ShouldBeNil)
  30. ctx.So(ok, convey.ShouldNotBeNil)
  31. })
  32. })
  33. }
  34. func TestDaoDelHashStatsCache(t *testing.T) {
  35. var (
  36. c = context.TODO()
  37. businessID = int64(1)
  38. originID = int64(1)
  39. )
  40. convey.Convey("DelHashStatsCache", t, func(ctx convey.C) {
  41. err := d.DelHashStatsCache(c, businessID, originID)
  42. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  43. ctx.So(err, convey.ShouldBeNil)
  44. })
  45. })
  46. }
  47. func TestDaoHashStatsCache(t *testing.T) {
  48. var (
  49. c = context.TODO()
  50. businessID = int64(1)
  51. originID = int64(1)
  52. messageIDs = []int64{1}
  53. )
  54. convey.Convey("HashStatsCache", t, func(ctx convey.C) {
  55. res, err := d.HashStatsCache(c, businessID, originID, messageIDs)
  56. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  57. ctx.So(err, convey.ShouldBeNil)
  58. ctx.So(res, convey.ShouldNotBeNil)
  59. })
  60. })
  61. }
  62. func TestDaoAddHashStatsCache(t *testing.T) {
  63. var (
  64. c = context.TODO()
  65. businessID = int64(1)
  66. originID = int64(1)
  67. stats = &model.Stats{}
  68. )
  69. convey.Convey("AddHashStatsCache", t, func(ctx convey.C) {
  70. err := d.AddHashStatsCache(c, businessID, originID, stats)
  71. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  72. ctx.So(err, convey.ShouldBeNil)
  73. })
  74. })
  75. }
  76. func TestDaoAddHashStatsCacheMap(t *testing.T) {
  77. var (
  78. c = context.TODO()
  79. businessID = int64(1)
  80. originID = int64(1)
  81. stats map[int64]*model.Stats
  82. )
  83. convey.Convey("AddHashStatsCacheMap", t, func(ctx convey.C) {
  84. err := d.AddHashStatsCacheMap(c, businessID, originID, stats)
  85. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  86. ctx.So(err, convey.ShouldBeNil)
  87. })
  88. })
  89. }