memcache_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/main/identify-game/model"
  5. "testing"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaoSetAccessCache(t *testing.T) {
  9. var (
  10. c = context.Background()
  11. key = "123456"
  12. res = &model.AccessInfo{Mid: 1, AppID: 1, Token: "ashiba", CreateAt: 123, UserID: "12", Name: "mdzz", Expires: 1577811661, Permission: "all"}
  13. )
  14. convey.Convey("SetAccessCache", t, func(ctx convey.C) {
  15. err := d.SetAccessCache(c, key, res)
  16. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  17. ctx.So(err, convey.ShouldBeNil)
  18. })
  19. })
  20. res.Expires = -1
  21. convey.Convey("SetAccessCacheExpires", t, func(ctx convey.C) {
  22. err := d.SetAccessCache(c, key, res)
  23. ctx.Convey("Then err should be error.", func(ctx convey.C) {
  24. ctx.So(err, convey.ShouldBeNil)
  25. })
  26. })
  27. }
  28. func TestDaoAccessCache(t *testing.T) {
  29. var (
  30. c = context.Background()
  31. key = "123456"
  32. )
  33. convey.Convey("AccessCache", t, func(ctx convey.C) {
  34. res, err := d.AccessCache(c, key)
  35. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  36. ctx.So(err, convey.ShouldBeNil)
  37. ctx.So(res, convey.ShouldNotBeNil)
  38. })
  39. })
  40. }
  41. func TestDaoDelAccessCache(t *testing.T) {
  42. var (
  43. c = context.Background()
  44. key = "123456"
  45. )
  46. convey.Convey("DelAccessCache", t, func(ctx convey.C) {
  47. err := d.DelAccessCache(c, key)
  48. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  49. ctx.So(err, convey.ShouldBeNil)
  50. })
  51. })
  52. }