123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475 |
- package dao
- import (
- "context"
- v1pb "go-common/app/service/live/gift/api/grpc/v1"
- "go-common/app/service/live/gift/model"
- "testing"
- "github.com/smartystreets/goconvey/convey"
- )
- func TestDaodailyBagKey(t *testing.T) {
- convey.Convey("dailyBagKey", t, func(c convey.C) {
- var (
- uid = int64(0)
- )
- c.Convey("When everything gose positive", func(c convey.C) {
- p1 := dailyBagKey(uid)
- c.Convey("Then p1 should not be nil.", func(c convey.C) {
- c.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoGetDailyBagCache(t *testing.T) {
- convey.Convey("GetDailyBagCache", t, func(c convey.C) {
- var (
- ctx = context.Background()
- uid = int64(0)
- )
- c.Convey("When everything gose positive", func(c convey.C) {
- res, err := d.GetDailyBagCache(ctx, uid)
- c.Convey("Then err should be nil.res should be nil.", func(c convey.C) {
- c.So(err, convey.ShouldBeNil)
- c.So(res, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoSetDailyBagCache(t *testing.T) {
- convey.Convey("SetDailyBagCache", t, func(c convey.C) {
- var (
- ctx = context.Background()
- uid = int64(9527)
- data = []*v1pb.DailyBagResp_BagList{}
- expire = int64(1)
- )
- c.Convey("When everything gose positive", func(c convey.C) {
- err := d.SetDailyBagCache(ctx, uid, data, expire)
- c.Convey("Then err should be nil.", func(c convey.C) {
- c.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaodailyMedalBagKey(t *testing.T) {
- convey.Convey("dailyMedalBagKey", t, func(c convey.C) {
- var (
- uid = int64(0)
- )
- c.Convey("When everything gose positive", func(c convey.C) {
- p1 := dailyMedalBagKey(uid)
- c.Convey("Then p1 should not be nil.", func(c convey.C) {
- c.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoGetMedalDailyBagCache(t *testing.T) {
- convey.Convey("GetMedalDailyBagCache", t, func(c convey.C) {
- var (
- ctx = context.Background()
- uid = int64(-1)
- )
- c.Convey("When everything gose positive", func(c convey.C) {
- res, err := d.GetMedalDailyBagCache(ctx, uid)
- c.Convey("Then err should be nil.res should be nil.", func(c convey.C) {
- c.So(err, convey.ShouldBeNil)
- c.So(res, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoSetMedalDailyBagCache(t *testing.T) {
- convey.Convey("SetMedalDailyBagCache", t, func(c convey.C) {
- var (
- ctx = context.Background()
- uid = int64(9527)
- data = &model.BagGiftStatus{}
- expire = int64(1)
- )
- c.Convey("When everything gose positive", func(c convey.C) {
- err := d.SetMedalDailyBagCache(ctx, uid, data, expire)
- c.Convey("Then err should be nil.", func(c convey.C) {
- c.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoweekLevelBagKey(t *testing.T) {
- convey.Convey("weekLevelBagKey", t, func(c convey.C) {
- var (
- uid = int64(0)
- level = int64(0)
- )
- c.Convey("When everything gose positive", func(c convey.C) {
- p1 := weekLevelBagKey(uid, level)
- c.Convey("Then p1 should not be nil.", func(c convey.C) {
- c.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoGetWeekLevelBagCache(t *testing.T) {
- convey.Convey("GetWeekLevelBagCache", t, func(c convey.C) {
- var (
- ctx = context.Background()
- uid = int64(-1)
- level = int64(1)
- )
- c.Convey("When everything gose positive", func(c convey.C) {
- res, err := d.GetWeekLevelBagCache(ctx, uid, level)
- c.Convey("Then err should be nil.res should not be nil.", func(c convey.C) {
- c.So(err, convey.ShouldBeNil)
- c.So(res, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoSetWeekLevelBagCache(t *testing.T) {
- convey.Convey("SetWeekLevelBagCache", t, func(c convey.C) {
- var (
- ctx = context.Background()
- uid = int64(9527)
- level = int64(0)
- data = &model.BagGiftStatus{}
- expire = int64(1)
- )
- c.Convey("When everything gose positive", func(c convey.C) {
- err := d.SetWeekLevelBagCache(ctx, uid, level, data, expire)
- c.Convey("Then err should be nil.", func(c convey.C) {
- c.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoLock(t *testing.T) {
- convey.Convey("Lock", t, func(c convey.C) {
- var (
- ctx = context.Background()
- key = "test lock"
- ttl = int(1)
- retry = int(0)
- retryDelay = int(0)
- )
- c.Convey("When everything gose positive", func(c convey.C) {
- gotLock, lockValue, err := d.Lock(ctx, key, ttl, retry, retryDelay)
- c.Convey("Then err should be nil.gotLock,lockValue should not be nil.", func(c convey.C) {
- c.So(lockValue, convey.ShouldNotBeNil)
- c.So(err, convey.ShouldBeNil)
- c.So(gotLock, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoUnLock(t *testing.T) {
- convey.Convey("UnLock", t, func(c convey.C) {
- var (
- ctx = context.Background()
- key = "test unlock"
- lockValue = "1"
- )
- c.Convey("When everything gose positive", func(c convey.C) {
- err := d.UnLock(ctx, key, lockValue)
- c.Convey("Then err should be nil.", func(c convey.C) {
- c.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoForceUnLock(t *testing.T) {
- convey.Convey("ForceUnLock", t, func(c convey.C) {
- var (
- ctx = context.Background()
- key = ""
- )
- c.Convey("When everything gose positive", func(c convey.C) {
- err := d.ForceUnLock(ctx, key)
- c.Convey("Then err should be nil.", func(c convey.C) {
- c.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaolockKey(t *testing.T) {
- convey.Convey("lockKey", t, func(c convey.C) {
- var (
- key = ""
- )
- c.Convey("When everything gose positive", func(c convey.C) {
- p1 := lockKey(key)
- c.Convey("Then p1 should not be nil.", func(c convey.C) {
- c.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaorandomString(t *testing.T) {
- convey.Convey("randomString", t, func(c convey.C) {
- var (
- l = int(0)
- )
- c.Convey("When everything gose positive", func(c convey.C) {
- p1 := randomString(l)
- c.Convey("Then p1 should not be nil.", func(c convey.C) {
- c.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaobagIDCache(t *testing.T) {
- convey.Convey("bagIDCache", t, func(c convey.C) {
- var (
- uid = int64(0)
- giftID = int64(0)
- expireAt = int64(0)
- )
- c.Convey("When everything gose positive", func(c convey.C) {
- p1 := bagIDCache(uid, giftID, expireAt)
- c.Convey("Then p1 should not be nil.", func(c convey.C) {
- c.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoGetBagIDCache(t *testing.T) {
- convey.Convey("GetBagIDCache", t, func(c convey.C) {
- var (
- ctx = context.Background()
- uid = int64(0)
- giftID = int64(0)
- expireAt = int64(0)
- )
- c.Convey("When everything gose positive", func(c convey.C) {
- bagID, err := d.GetBagIDCache(ctx, uid, giftID, expireAt)
- c.Convey("Then err should be nil.bagID should not be nil.", func(c convey.C) {
- c.So(err, convey.ShouldBeNil)
- c.So(bagID, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoSetBagIDCache(t *testing.T) {
- convey.Convey("SetBagIDCache", t, func(c convey.C) {
- var (
- ctx = context.Background()
- uid = int64(9527)
- giftID = int64(1)
- expireAt = int64(1)
- bagID = int64(1)
- expire = int64(1)
- )
- c.Convey("When everything gose positive", func(c convey.C) {
- err := d.SetBagIDCache(ctx, uid, giftID, expireAt, bagID, expire)
- c.Convey("Then err should be nil.", func(c convey.C) {
- c.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaobagListKey(t *testing.T) {
- convey.Convey("bagListKey", t, func(c convey.C) {
- var (
- uid = int64(0)
- )
- c.Convey("When everything gose positive", func(c convey.C) {
- p1 := bagListKey(uid)
- c.Convey("Then p1 should not be nil.", func(c convey.C) {
- c.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoGetBagListCache(t *testing.T) {
- convey.Convey("GetBagListCache", t, func(c convey.C) {
- var (
- ctx = context.Background()
- uid = int64(0)
- )
- c.Convey("When everything gose positive", func(c convey.C) {
- res, err := d.GetBagListCache(ctx, uid)
- c.Convey("Then err should be nil.res should be nil.", func(c convey.C) {
- c.So(err, convey.ShouldBeNil)
- c.So(res, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoSetBagListCache(t *testing.T) {
- convey.Convey("SetBagListCache", t, func(c convey.C) {
- var (
- ctx = context.Background()
- uid = int64(0)
- data = []*model.BagGiftList{}
- expire = int64(1)
- )
- c.Convey("When everything gose positive", func(c convey.C) {
- err := d.SetBagListCache(ctx, uid, data, expire)
- c.Convey("Then err should be nil.", func(c convey.C) {
- c.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoClearBagListCache(t *testing.T) {
- convey.Convey("ClearBagListCache", t, func(c convey.C) {
- var (
- ctx = context.Background()
- uid = int64(0)
- )
- c.Convey("When everything gose positive", func(c convey.C) {
- err := d.ClearBagListCache(ctx, uid)
- c.Convey("Then err should be nil.", func(c convey.C) {
- c.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaobagNumKey(t *testing.T) {
- convey.Convey("bagNumKey", t, func(c convey.C) {
- var (
- uid = int64(0)
- giftID = int64(0)
- expireAt = int64(0)
- )
- c.Convey("When everything gose positive", func(c convey.C) {
- p1 := bagNumKey(uid, giftID, expireAt)
- c.Convey("Then p1 should not be nil.", func(c convey.C) {
- c.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoSetBagNumCache(t *testing.T) {
- convey.Convey("SetBagNumCache", t, func(c convey.C) {
- var (
- ctx = context.Background()
- uid = int64(9527)
- giftID = int64(1)
- expireAt = int64(1)
- giftNum = int64(1)
- expire = int64(1)
- )
- c.Convey("When everything gose positive", func(c convey.C) {
- err := d.SetBagNumCache(ctx, uid, giftID, expireAt, giftNum, expire)
- c.Convey("Then err should be nil.", func(c convey.C) {
- c.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaovipMonthBag(t *testing.T) {
- convey.Convey("vipMonthBag", t, func(c convey.C) {
- var (
- uid = int64(0)
- )
- c.Convey("When everything gose positive", func(c convey.C) {
- p1 := vipMonthBag(uid)
- c.Convey("Then p1 should not be nil.", func(c convey.C) {
- c.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoGetVipStatusCache(t *testing.T) {
- convey.Convey("GetVipStatusCache", t, func(c convey.C) {
- var (
- ctx = context.Background()
- uid = int64(0)
- )
- c.Convey("When everything gose positive", func(c convey.C) {
- status, err := d.GetVipStatusCache(ctx, uid)
- c.Convey("Then err should be nil.status should not be nil.", func(c convey.C) {
- c.So(err, convey.ShouldBeNil)
- c.So(status, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoClearVipStatusCache(t *testing.T) {
- convey.Convey("ClearVipStatusCache", t, func(c convey.C) {
- var (
- ctx = context.Background()
- uid = int64(0)
- )
- c.Convey("When everything gose positive", func(c convey.C) {
- err := d.ClearVipStatusCache(ctx, uid)
- c.Convey("Then err should be nil.", func(c convey.C) {
- c.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaogiftBagStatus(t *testing.T) {
- convey.Convey("giftBagStatus", t, func(c convey.C) {
- var (
- uid = int64(0)
- )
- c.Convey("When everything gose positive", func(c convey.C) {
- p1 := giftBagStatus(uid)
- c.Convey("Then p1 should not be nil.", func(c convey.C) {
- c.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoGetBagStatusCache(t *testing.T) {
- convey.Convey("GetBagStatusCache", t, func(c convey.C) {
- var (
- ctx = context.Background()
- uid = int64(0)
- )
- c.Convey("When everything gose positive", func(c convey.C) {
- status, err := d.GetBagStatusCache(ctx, uid)
- c.Convey("Then err should be nil.status should not be nil.", func(c convey.C) {
- c.So(err, convey.ShouldBeNil)
- c.So(status, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoSetBagStatusCache(t *testing.T) {
- convey.Convey("SetBagStatusCache", t, func(c convey.C) {
- var (
- ctx = context.Background()
- uid = int64(9527)
- status = int64(1)
- expire = int64(1)
- )
- c.Convey("When everything gose positive", func(c convey.C) {
- err := d.SetBagStatusCache(ctx, uid, status, expire)
- c.Convey("Then err should be nil.", func(c convey.C) {
- c.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
|