redis_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package ads
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestAdsBuvidCache(t *testing.T) {
  8. var (
  9. buvidCache = map[string]map[int64]int64{
  10. "123456": {
  11. 10097289: 1,
  12. 10097290: 5,
  13. },
  14. "234567": {
  15. 10097288: 3,
  16. 10098523: 1,
  17. },
  18. }
  19. res int64
  20. err error
  21. )
  22. convey.Convey("AddBuvidCount - add cache", t, WithDao(func(d *Dao) {
  23. err = d.AddBuvidCount(context.Background(), buvidCache)
  24. convey.Convey("Error should be nil", func() {
  25. convey.So(err, convey.ShouldBeNil)
  26. })
  27. convey.Convey("BuvidCount - get cache", func() {
  28. convey.Convey("Case 1: faid = 10097290, buvid = 123456", func() {
  29. res, err = d.BuvidCount(context.Background(), 10097290, "123456")
  30. convey.Convey("Error should be nil, res should be 5", func() {
  31. convey.So(err, convey.ShouldBeNil)
  32. convey.So(res, convey.ShouldEqual, 5)
  33. })
  34. })
  35. convey.Convey("Case 2: faid = 10097288, buvid = 234567", func() {
  36. res, err := d.BuvidCount(context.Background(), 10097288, "234567")
  37. convey.Convey("Error should be nil, res should be 3", func() {
  38. convey.So(err, convey.ShouldBeNil)
  39. convey.So(res, convey.ShouldEqual, 3)
  40. })
  41. })
  42. })
  43. convey.Convey("keyBuvid", func() {
  44. key := d.keyBuvid("234567")
  45. convey.Convey("key should not be nil", func() {
  46. convey.So(key, convey.ShouldNotBeNil)
  47. })
  48. convey.Convey("ExistsAuth - expire cache", func() {
  49. res, err := d.ExistsAuth(context.Background(), key)
  50. convey.Convey("Error should be nil, res should be true", func() {
  51. convey.So(err, convey.ShouldBeNil)
  52. convey.So(res, convey.ShouldEqual, true)
  53. })
  54. })
  55. })
  56. }))
  57. }