userext_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package dao
  2. import (
  3. "context"
  4. . "github.com/smartystreets/goconvey/convey"
  5. "go-common/app/interface/live/app-room/model"
  6. "math/rand"
  7. "testing"
  8. "time"
  9. )
  10. func getTestRandUid() int64 {
  11. var r = rand.New(rand.NewSource(time.Now().UnixNano()))
  12. return r.Int63n(10000000)
  13. }
  14. func TestDao_UserConf(t *testing.T) {
  15. Convey("normal", t, func() {
  16. Convey("conf", func() {
  17. So(7, ShouldEqual, testDao.c.Gift.RechargeTip.SilverTipDays[0])
  18. So(1, ShouldEqual, len(testDao.c.Gift.RechargeTip.SilverTipDays))
  19. t.Logf("%v", testDao.c.Gift.RechargeTip.SilverTipDays)
  20. })
  21. Convey("set and get", func() {
  22. uid := getTestRandUid()
  23. err := testDao.SetUserConf(context.Background(), uid, model.GoldTarget, 1)
  24. So(err, ShouldBeNil)
  25. m, err := testDao.GetUserConf(context.Background(), uid, model.GoldTarget, []int64{1})
  26. So(err, ShouldBeNil)
  27. v, ok := m[1]
  28. t.Logf("v: %v", v)
  29. So(ok, ShouldBeTrue)
  30. So(v, ShouldEqual, "1")
  31. So(m.IsSet(1), ShouldBeTrue)
  32. testDao.DelUserConf(context.Background(), uid, model.GoldTarget, 1)
  33. m, err = testDao.GetUserConf(context.Background(), uid, model.GoldTarget, []int64{1})
  34. So(err, ShouldBeNil)
  35. v, ok = m[1]
  36. t.Logf("v: %v", v)
  37. So(ok, ShouldBeTrue)
  38. So(v, ShouldEqual, "")
  39. So(m.IsSet(1), ShouldBeFalse)
  40. })
  41. })
  42. }