redis_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestDaokeyZlimit(t *testing.T) {
  8. var (
  9. aid = int64(123456)
  10. )
  11. convey.Convey("keyZlimit", t, func(ctx convey.C) {
  12. key := keyZlimit(aid)
  13. ctx.Convey("key should not be equal to 123456", func(ctx convey.C) {
  14. ctx.So(key, convey.ShouldEqual, "zl_123456")
  15. })
  16. })
  17. }
  18. func TestDaoExistsAuth(t *testing.T) {
  19. var (
  20. c = context.TODO()
  21. aid = int64(123456)
  22. zoneids = map[int64]map[int64]int64{int64(123456): {int64(234567): int64(345678)}}
  23. )
  24. convey.Convey("ExistsAuth", t, WithDao(func(d *Dao) {
  25. d.AddAuth(c, zoneids)
  26. ok, err := d.ExistsAuth(c, aid)
  27. convey.Convey("Error should be nil, ok should be true", func(ctx convey.C) {
  28. ctx.So(err, convey.ShouldBeNil)
  29. ctx.So(ok, convey.ShouldBeTrue)
  30. })
  31. }))
  32. }
  33. func TestDaoAuth(t *testing.T) {
  34. var (
  35. c = context.TODO()
  36. aid = int64(0)
  37. zoneid = []int64{int64(0)}
  38. zoneids = map[int64]map[int64]int64{int64(123456): {int64(234567): int64(345678)}}
  39. )
  40. convey.Convey("Auth", t, WithDao(func(d *Dao) {
  41. d.AddAuth(c, zoneids)
  42. res, err := d.Auth(c, aid, zoneid)
  43. convey.Convey("Error should be nil, res should not be empty", func(ctx convey.C) {
  44. ctx.So(err, convey.ShouldBeNil)
  45. ctx.So(res, convey.ShouldNotBeEmpty)
  46. })
  47. }))
  48. }
  49. func TestDaoAddAuth(t *testing.T) {
  50. var (
  51. c = context.TODO()
  52. zoneids = map[int64]map[int64]int64{int64(123456): {int64(234567): int64(345678)}}
  53. )
  54. convey.Convey("AddAuth", t, WithDao(func(d *Dao) {
  55. err := d.AddAuth(c, zoneids)
  56. convey.Convey("Error should be nil", func(ctx convey.C) {
  57. ctx.So(err, convey.ShouldBeNil)
  58. })
  59. }))
  60. }