memcache_test.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/admin/main/reply/model"
  6. . "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestSubjectCache(t *testing.T) {
  9. var (
  10. sub = &model.Subject{
  11. Oid: 1,
  12. Type: 1,
  13. }
  14. c = context.Background()
  15. )
  16. Convey("test subject cache", t, WithDao(func(d *Dao) {
  17. // add
  18. err := d.AddSubjectCache(c, sub)
  19. So(err, ShouldBeNil)
  20. // get
  21. cache, err := d.SubjectCache(c, sub.Oid, sub.Type)
  22. So(err, ShouldBeNil)
  23. So(cache.Oid, ShouldEqual, sub.Oid)
  24. // del
  25. err = d.DelSubjectCache(c, sub.Oid, sub.Type)
  26. So(err, ShouldBeNil)
  27. // get
  28. cache, err = d.SubjectCache(c, sub.Oid, sub.Type)
  29. So(err, ShouldBeNil)
  30. So(cache, ShouldBeNil)
  31. }))
  32. }
  33. func TestReplyCache(t *testing.T) {
  34. var (
  35. rp = &model.Reply{
  36. ID: 1,
  37. Oid: 1,
  38. Type: 1,
  39. }
  40. c = context.Background()
  41. )
  42. Convey("test reply cache", t, WithDao(func(d *Dao) {
  43. // add
  44. err := d.AddReplyCache(c, rp)
  45. So(err, ShouldBeNil)
  46. // get
  47. cache, err := d.ReplyCache(c, rp.ID)
  48. So(err, ShouldBeNil)
  49. So(cache.ID, ShouldEqual, rp.ID)
  50. // get
  51. caches, miss, err := d.RepliesCache(c, []int64{rp.ID})
  52. So(err, ShouldBeNil)
  53. So(len(caches), ShouldEqual, 1)
  54. So(len(miss), ShouldEqual, 0)
  55. // del
  56. err = d.DelReplyCache(c, rp.ID)
  57. So(err, ShouldBeNil)
  58. // get
  59. cache, err = d.ReplyCache(c, rp.ID)
  60. So(err, ShouldBeNil)
  61. So(cache, ShouldBeNil)
  62. }))
  63. Convey("test top reply cache", t, WithDao(func(d *Dao) {
  64. rp.AttrSet(model.AttrYes, model.AttrTopAdmin)
  65. // add
  66. err := d.AddTopCache(c, rp)
  67. So(err, ShouldBeNil)
  68. // get
  69. cache, err := d.TopCache(c, rp.Oid, model.SubAttrTopAdmin)
  70. So(err, ShouldBeNil)
  71. So(cache.ID, ShouldEqual, rp.ID)
  72. // del
  73. err = d.DelTopCache(c, rp.Oid, model.SubAttrTopAdmin)
  74. // get
  75. cache, err = d.TopCache(c, rp.Oid, model.SubAttrTopAdmin)
  76. So(err, ShouldBeNil)
  77. So(cache, ShouldBeNil)
  78. }))
  79. }