memcache_test.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/service/main/archive/api"
  6. feed "go-common/app/service/main/feed/model"
  7. xtime "go-common/library/time"
  8. . "github.com/smartystreets/goconvey/convey"
  9. )
  10. func Test_ArchivesCache(t *testing.T) {
  11. arc := api.Arc{Aid: 1, PubDate: xtime.Time(100), Title: "title"}
  12. c := context.TODO()
  13. Convey("add cache", t, func() {
  14. err := d.AddArchivesCacheMap(c, map[int64]*api.Arc{1: &arc})
  15. So(err, ShouldBeNil)
  16. Convey("get cache return cached data", func() {
  17. cached, missed, err := d.ArchivesCache(c, []int64{1})
  18. So(err, ShouldBeNil)
  19. So(missed, ShouldBeEmpty)
  20. So(cached, ShouldResemble, map[int64]*api.Arc{1: &arc})
  21. })
  22. Convey("del cache return null", func() {
  23. err := d.DelArchiveCache(c, 1)
  24. So(err, ShouldBeNil)
  25. cached, missed, err := d.ArchivesCache(c, []int64{1})
  26. So(err, ShouldBeNil)
  27. So(cached, ShouldBeEmpty)
  28. So(missed, ShouldResemble, []int64{1})
  29. })
  30. })
  31. }
  32. func Test_BangumiCache(t *testing.T) {
  33. bangumi := feed.Bangumi{SeasonID: 1, Title: "t"}
  34. c := context.TODO()
  35. Convey("add cache", t, func() {
  36. err := d.AddBangumisCacheMap(c, map[int64]*feed.Bangumi{1: &bangumi})
  37. So(err, ShouldBeNil)
  38. Convey("get cache return cached data", func() {
  39. cached, missed, err := d.BangumisCache(c, []int64{1})
  40. So(err, ShouldBeNil)
  41. So(missed, ShouldBeEmpty)
  42. So(cached, ShouldResemble, map[int64]*feed.Bangumi{1: &bangumi})
  43. })
  44. Convey("return missed", func() {
  45. miss := int64(2000)
  46. cached, missed, err := d.BangumisCache(c, []int64{miss})
  47. So(err, ShouldBeNil)
  48. So(cached, ShouldBeEmpty)
  49. So(missed, ShouldResemble, []int64{miss})
  50. })
  51. })
  52. }