memcached_test.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/main/thumbup/model"
  5. "testing"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaostatsKey(t *testing.T) {
  9. var (
  10. businessID = int64(1)
  11. messageID = int64(1)
  12. )
  13. convey.Convey("statsKey", t, func(ctx convey.C) {
  14. p1 := statsKey(businessID, messageID)
  15. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  16. ctx.So(p1, convey.ShouldNotBeNil)
  17. })
  18. })
  19. }
  20. func TestDaorecoverStatsValue(t *testing.T) {
  21. var (
  22. c = context.TODO()
  23. s = ""
  24. )
  25. convey.Convey("recoverStatsValue", t, func(ctx convey.C) {
  26. res := recoverStatsValue(c, s)
  27. ctx.Convey("Then res should not be nil.", func(ctx convey.C) {
  28. ctx.So(res, convey.ShouldNotBeNil)
  29. })
  30. })
  31. }
  32. func TestDaoAddStatsCache(t *testing.T) {
  33. var (
  34. c = context.TODO()
  35. businessID = int64(1)
  36. vs = &model.Stats{}
  37. )
  38. convey.Convey("AddStatsCache", t, func(ctx convey.C) {
  39. err := d.AddStatsCache(c, businessID, vs)
  40. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  41. ctx.So(err, convey.ShouldBeNil)
  42. })
  43. })
  44. }
  45. func TestDaoDelStatsCache(t *testing.T) {
  46. var (
  47. c = context.TODO()
  48. businessID = int64(1)
  49. messageID = int64(1)
  50. )
  51. convey.Convey("DelStatsCache", t, func(ctx convey.C) {
  52. err := d.DelStatsCache(c, businessID, messageID)
  53. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  54. ctx.So(err, convey.ShouldBeNil)
  55. })
  56. })
  57. }
  58. func TestDaoAddStatsCacheMap(t *testing.T) {
  59. var (
  60. c = context.TODO()
  61. businessID = int64(1)
  62. stats map[int64]*model.Stats
  63. )
  64. convey.Convey("AddStatsCacheMap", t, func(ctx convey.C) {
  65. err := d.AddStatsCacheMap(c, businessID, stats)
  66. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  67. ctx.So(err, convey.ShouldBeNil)
  68. })
  69. })
  70. }
  71. func TestDaoStatsCache(t *testing.T) {
  72. var (
  73. c = context.TODO()
  74. businessID = int64(1)
  75. messageIDs = []int64{1}
  76. )
  77. convey.Convey("StatsCache", t, func(ctx convey.C) {
  78. cached, missed, err := d.StatsCache(c, businessID, messageIDs)
  79. ctx.Convey("Then err should be nil.cached,missed should not be nil.", func(ctx convey.C) {
  80. ctx.So(err, convey.ShouldBeNil)
  81. ctx.So(missed, convey.ShouldNotBeNil)
  82. ctx.So(cached, convey.ShouldBeEmpty)
  83. })
  84. })
  85. }