redis_test.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. var (
  8. day = "20180808"
  9. mid = int64(91221505)
  10. app = int64(1)
  11. )
  12. func incrLimitDayCache() (int, error) {
  13. return d.IncrLimitDayCache(context.Background(), day, app, mid)
  14. }
  15. func TestDaoLimitDayCache(t *testing.T) {
  16. incrLimitDayCache()
  17. convey.Convey("LimitDayCache", t, func(ctx convey.C) {
  18. count, err := d.LimitDayCache(context.Background(), day, app, mid)
  19. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  20. ctx.So(err, convey.ShouldBeNil)
  21. ctx.So(count, convey.ShouldBeGreaterThan, 0)
  22. })
  23. })
  24. }
  25. func TestDaoIncrLimitDayCache(t *testing.T) {
  26. convey.Convey("IncrLimitDayCache", t, func(ctx convey.C) {
  27. count, err := incrLimitDayCache()
  28. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  29. ctx.So(err, convey.ShouldBeNil)
  30. ctx.So(count, convey.ShouldBeGreaterThan, 0)
  31. })
  32. })
  33. }
  34. func incrLimitNotLiveCache() (int, error) {
  35. return d.IncrLimitNotLiveCache(context.Background(), day, mid)
  36. }
  37. func TestDaoIncrLimitBizCache(t *testing.T) {
  38. incrLimitNotLiveCache()
  39. convey.Convey("IncrLimitBizCache", t, func(ctx convey.C) {
  40. count, err := d.IncrLimitBizCache(context.Background(), day, app, mid, biz)
  41. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  42. ctx.So(err, convey.ShouldBeNil)
  43. ctx.So(count, convey.ShouldBeGreaterThan, 0)
  44. })
  45. })
  46. }
  47. func TestDaoIncrLimitNotLiveCache(t *testing.T) {
  48. convey.Convey("IncrLimitNotLiveCache", t, func(ctx convey.C) {
  49. count, err := incrLimitNotLiveCache()
  50. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  51. ctx.So(err, convey.ShouldBeNil)
  52. ctx.So(count, convey.ShouldBeGreaterThan, 0)
  53. })
  54. })
  55. }