123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519 |
- package dao
- import (
- "context"
- "testing"
- "go-common/app/service/main/coupon/model"
- "github.com/smartystreets/goconvey/convey"
- )
- func TestDaoreceiveLogKey(t *testing.T) {
- var (
- appkey = "123"
- orderNo = "456"
- ct = int8(0)
- )
- convey.Convey("TestDaoreceiveLogKey ", t, func(ctx convey.C) {
- p1 := receiveLogKey(appkey, orderNo, ct)
- ctx.Convey("Then p1 should equal.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldEqual, "rl:1234560")
- })
- })
- }
- func TestDaoprizeCardKey(t *testing.T) {
- var (
- mid int64 = 22
- actID int64 = 1
- ct = int8(0)
- )
- convey.Convey("TestDaoprizeCardKey ", t, func(ctx convey.C) {
- p1 := prizeCardKey(mid, actID, ct)
- ctx.Convey("Then p1 should equal.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldEqual, "nypc:22:1:0")
- })
- })
- }
- func TestDaoprizeCardsKey(t *testing.T) {
- var (
- mid int64 = 22
- actID int64 = 1
- )
- convey.Convey("TestDaoprizeCardsKey ", t, func(ctx convey.C) {
- p1 := prizeCardsKey(mid, actID)
- ctx.Convey("Then p1 should equal.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldEqual, "nypcs:22:1")
- })
- })
- }
- func TestDaocouponuniqueNoKey(t *testing.T) {
- var (
- uniqueno string = "uniqueno"
- )
- convey.Convey("TestDaocouponuniqueNoKey ", t, func(ctx convey.C) {
- p1 := couponuniqueNoKey(uniqueno)
- ctx.Convey("Then p1 should equal.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldEqual, "uq:uniqueno")
- })
- })
- }
- func TestDaocouponsKey(t *testing.T) {
- var (
- mid = int64(0)
- ct = int8(0)
- )
- convey.Convey("couponsKey ", t, func(ctx convey.C) {
- p1 := couponsKey(mid, ct)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaouseUniqueKey(t *testing.T) {
- var (
- orderNO = "1"
- ct = int8(0)
- )
- convey.Convey("useUniqueKey", t, func(ctx convey.C) {
- p1 := useUniqueKey(orderNO, ct)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaocouponBalancesKey(t *testing.T) {
- var (
- mid = int64(0)
- ct = int8(0)
- )
- convey.Convey("couponBalancesKey", t, func(ctx convey.C) {
- p1 := couponBalancesKey(mid, ct)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaouserGrantKey(t *testing.T) {
- var (
- token = "1"
- mid = int64(0)
- )
- convey.Convey("userGrantKey", t, func(ctx convey.C) {
- p1 := userGrantKey(token, mid)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaobranchCurrentCount(t *testing.T) {
- var (
- token = "1"
- )
- convey.Convey("branchCurrentCount", t, func(ctx convey.C) {
- p1 := branchCurrentCount(token)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaocouponAllowancesKey(t *testing.T) {
- var (
- mid = int64(0)
- )
- convey.Convey("couponAllowancesKey", t, func(ctx convey.C) {
- p1 := couponAllowancesKey(mid, 0)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoDelUniqueKey(t *testing.T) {
- var (
- c = context.TODO()
- orderNO = "1"
- ct = int8(0)
- )
- convey.Convey("DelUniqueKey", t, func(ctx convey.C) {
- err := d.DelUniqueKey(c, orderNO, ct)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoDelCouponsCache(t *testing.T) {
- var (
- c = context.TODO()
- mid = int64(0)
- ct = int8(0)
- )
- convey.Convey("DelCouponsCache", t, func(ctx convey.C) {
- err := d.DelCouponsCache(c, mid, ct)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoDelCouponBalancesCache(t *testing.T) {
- var (
- c = context.TODO()
- mid = int64(0)
- ct = int8(0)
- )
- convey.Convey("DelCouponBalancesCache", t, func(ctx convey.C) {
- err := d.DelCouponBalancesCache(c, mid, ct)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoDelGrantKey(t *testing.T) {
- var (
- c = context.TODO()
- token = "1"
- mid = int64(0)
- )
- convey.Convey("DelGrantKey", t, func(ctx convey.C) {
- err := d.DelGrantKey(c, token, mid)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoDelBranchCurrentCountKey(t *testing.T) {
- var (
- c = context.TODO()
- token = "1"
- )
- convey.Convey("DelBranchCurrentCountKey", t, func(ctx convey.C) {
- err := d.DelBranchCurrentCountKey(c, token)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoDelCouponAllowancesKey(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(0)
- )
- convey.Convey("DelCouponAllowancesKey", t, func(ctx convey.C) {
- err := d.DelCouponAllowancesKey(c, mid, 0)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoDelPrizeCardKey(t *testing.T) {
- var (
- c = context.Background()
- mid int64 = 22
- actID int64 = 1
- ct = int8(0)
- )
- convey.Convey("DelPrizeCardKey", t, func(ctx convey.C) {
- err := d.DelPrizeCardKey(c, mid, actID, ct)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoDelPrizeCardsKey(t *testing.T) {
- var (
- c = context.Background()
- mid int64 = 22
- actID int64 = 1
- )
- convey.Convey("DelCouponAllowancesKey", t, func(ctx convey.C) {
- err := d.DelPrizeCardsKey(c, mid, actID)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoCouponsCache(t *testing.T) {
- var (
- c = context.TODO()
- mid = int64(0)
- ct = int8(0)
- coupons = []*model.CouponInfo{}
- err error
- )
- convey.Convey("CouponsCache", t, func(ctx convey.C) {
- coupons, err = d.CouponsCache(c, mid, ct)
- ctx.Convey("Then err should be nil.coupons should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(coupons, convey.ShouldBeNil)
- })
- err = d.SetCouponsCache(c, mid, ct, coupons)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- coupons, err = d.CouponsCache(c, mid, ct)
- ctx.Convey("Then err should be nil.coupons should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(coupons, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoAddUseUniqueLock(t *testing.T) {
- var (
- c = context.TODO()
- orderNO = "1"
- ct = int8(0)
- )
- convey.Convey("AddUseUniqueLock", t, func(ctx convey.C) {
- succeed := d.AddUseUniqueLock(c, orderNO, ct)
- ctx.Convey("Then succeed should not be nil.", func(ctx convey.C) {
- ctx.So(succeed, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoAddReceiveUniqueLock(t *testing.T) {
- var (
- c = context.TODO()
- appkey = "1"
- orderNO = "2"
- ct = int8(0)
- )
- convey.Convey("AddReceiveUniqueLock", t, func(ctx convey.C) {
- succeed := d.AddReceiveUniqueLock(c, appkey, orderNO, ct)
- ctx.Convey("Then succeed should not be nil.", func(ctx convey.C) {
- ctx.So(succeed, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoDelReceiveUniqueLock(t *testing.T) {
- var (
- c = context.TODO()
- appkey = "1"
- orderNO = "1"
- ct = int8(0)
- )
- convey.Convey("DelReceiveUniqueLock ", t, func(ctx convey.C) {
- err := d.DelReceiveUniqueLock(c, appkey, orderNO, ct)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaodelCache(t *testing.T) {
- var (
- c = context.TODO()
- key = "1"
- )
- convey.Convey("delCache", t, func(ctx convey.C) {
- err := d.delCache(c, key)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoCouponBlanceCache(t *testing.T) {
- var (
- c = context.TODO()
- mid = int64(0)
- ct = int8(0)
- coupons = []*model.CouponBalanceInfo{}
- )
- convey.Convey("CouponBlanceCache", t, func(ctx convey.C) {
- err := d.SetCouponBlanceCache(c, mid, ct, coupons)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- coupons, err := d.CouponBlanceCache(c, mid, ct)
- ctx.Convey("Then err should be nil.coupons should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(coupons, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoAddUniqueNoLock(t *testing.T) {
- var (
- c = context.TODO()
- uniqueno = "1"
- )
- convey.Convey("AddUniqueNoLock", t, func(ctx convey.C) {
- succeed := d.AddUniqueNoLock(c, uniqueno)
- ctx.Convey("Then succeed should not be nil.", func(ctx convey.C) {
- ctx.So(succeed, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoAddGrantUniqueLock(t *testing.T) {
- var (
- c = context.TODO()
- token = "1"
- mid = int64(0)
- )
- convey.Convey("AddGrantUniqueLock", t, func(ctx convey.C) {
- succeed := d.AddGrantUniqueLock(c, token, mid)
- ctx.Convey("Then succeed should not be nil.", func(ctx convey.C) {
- ctx.So(succeed, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoBranchCurrentCountCache(t *testing.T) {
- var (
- c = context.TODO()
- token = "1"
- )
- convey.Convey("BranchCurrentCountCache", t, func(ctx convey.C) {
- count, err := d.BranchCurrentCountCache(c, token)
- ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(count, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoSetBranchCurrentCountCache(t *testing.T) {
- var (
- c = context.TODO()
- token = "1"
- count = int(0)
- )
- convey.Convey("SetBranchCurrentCountCache", t, func(ctx convey.C) {
- err := d.SetBranchCurrentCountCache(c, token, count)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoIncreaseBranchCurrentCountCache(t *testing.T) {
- var (
- c = context.TODO()
- token = "1"
- count = uint64(0)
- )
- convey.Convey("IncreaseBranchCurrentCountCache", t, func(ctx convey.C) {
- err := d.IncreaseBranchCurrentCountCache(c, token, count)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoCouponAllowanceCache(t *testing.T) {
- var (
- c = context.TODO()
- mid = int64(0)
- coupons = []*model.CouponAllowanceInfo{}
- )
- convey.Convey("CouponAllowanceCache", t, func(ctx convey.C) {
- err := d.SetCouponAllowanceCache(c, mid, 0, coupons)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- coupons, err := d.CouponAllowanceCache(c, mid, 0)
- ctx.Convey("Then err should be nil.coupons should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(coupons, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoSetPrizeCardCache(t *testing.T) {
- var (
- c = context.TODO()
- mid int64 = 1
- actID int64 = 1
- prizeCard = &model.PrizeCardRep{}
- )
- convey.Convey("SetPrizeCardCache ", t, func(ctx convey.C) {
- err := d.SetPrizeCardCache(c, mid, actID, prizeCard)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoSetPrizeCardsCache(t *testing.T) {
- var (
- c = context.TODO()
- mid = int64(1)
- actID = int64(1)
- prizeCards = make([]*model.PrizeCardRep, 0)
- prizeCard = &model.PrizeCardRep{}
- )
- prizeCards = append(prizeCards, prizeCard)
- convey.Convey("SetPrizeCardsCache ", t, func(ctx convey.C) {
- err := d.SetPrizeCardsCache(c, mid, actID, prizeCards)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoPrizeCardCache(t *testing.T) {
- var (
- c = context.TODO()
- mid = int64(1)
- actID = int64(1)
- ct = int8(0)
- prizeCard = &model.PrizeCardRep{}
- )
- convey.Convey("PrizeCardCache", t, func(ctx convey.C) {
- d.SetPrizeCardCache(c, mid, actID, prizeCard)
- res, err := d.PrizeCardCache(c, mid, actID, ct)
- ctx.Convey("Then err should be nil.res should be not nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldNotBeNil)
- })
- d.DelPrizeCardKey(c, mid, actID, ct)
- res, err = d.PrizeCardCache(c, mid, actID, ct)
- ctx.Convey("Then err should be nil.res should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoPrizeCardsCache(t *testing.T) {
- var (
- c = context.TODO()
- mid = int64(1)
- actID = int64(1)
- prizeCards = make([]*model.PrizeCardRep, 0)
- prizeCard = &model.PrizeCardRep{}
- )
- prizeCards = append(prizeCards, prizeCard)
- convey.Convey("PrizeCardCache", t, func(ctx convey.C) {
- d.SetPrizeCardsCache(c, mid, actID, prizeCards)
- res, err := d.PrizeCardsCache(c, mid, actID)
- ctx.Convey("Then err should be nil.res should be not nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldNotBeNil)
- })
- d.DelPrizeCardsKey(c, mid, actID)
- res, err = d.PrizeCardsCache(c, mid, actID)
- ctx.Convey("Then err should be nil.res should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldBeNil)
- })
- })
- }
|