123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- package dao
- import (
- "testing"
- "time"
- "go-common/app/service/main/ugcpay-rank/internal/conf"
- "go-common/app/service/main/ugcpay-rank/internal/model"
- xtime "go-common/library/time"
- "github.com/smartystreets/goconvey/convey"
- )
- func TestDaoLCLoadElecAVRankFromNil(t *testing.T) {
- convey.Convey("loadElecAVRank", t, func(ctx convey.C) {
- var (
- avID = int64(233)
- ver = int64(0)
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- rank, err := d.LCLoadElecAVRank(avID, ver)
- ctx.Convey("Then err should be nil.rank should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(rank, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoLCStoreElecAVRank(t *testing.T) {
- convey.Convey("storeElecAVRank", t, func(ctx convey.C) {
- var (
- avID = int64(233)
- ver = int64(0)
- rank = &model.RankElecAVProto{
- AVID: 233,
- }
- )
- conf.Conf.LocalCache.ElecAVRankTTL = xtime.Duration(time.Second)
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- err := d.LCStoreElecAVRank(avID, ver, rank)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoLCLoadElecAVRank(t *testing.T) {
- convey.Convey("loadElecAVRank", t, func(ctx convey.C) {
- var (
- avID = int64(233)
- ver = int64(0)
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- rank, err := d.LCLoadElecAVRank(avID, ver)
- ctx.Convey("Then err should be nil.rank should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(rank, convey.ShouldNotBeNil)
- ctx.So(rank.AVID, convey.ShouldEqual, avID)
- })
- })
- })
- }
- func TestDaoLCLoadElecAVRankAfterTTL(t *testing.T) {
- convey.Convey("loadElecAVRankAfterTTL", t, func(ctx convey.C) {
- var (
- avID = int64(233)
- ver = int64(0)
- )
- <-time.After(time.Duration(conf.Conf.LocalCache.ElecAVRankTTL))
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- rank, err := d.LCLoadElecAVRank(avID, ver)
- ctx.Convey("Then err should be nil.rank should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(rank, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoLCLoadElecUPRankFromNil(t *testing.T) {
- convey.Convey("loadElecUPRank", t, func(ctx convey.C) {
- var (
- upMID = int64(4633)
- ver = int64(0)
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- rank, err := d.LCLoadElecUPRank(upMID, ver)
- ctx.Convey("Then err should be nil.rank should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(rank, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoLCStoreElecUPRank(t *testing.T) {
- convey.Convey("storeElecUPRank", t, func(ctx convey.C) {
- var (
- upMID = int64(4633)
- ver = int64(0)
- rank = &model.RankElecUPProto{
- Count: 100,
- }
- )
- conf.Conf.LocalCache.ElecUPRankTTL = xtime.Duration(time.Second)
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- err := d.LCStoreElecUPRank(upMID, ver, rank)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoLCLoadElecUPRank(t *testing.T) {
- convey.Convey("loadElecUPRank", t, func(ctx convey.C) {
- var (
- upMID = int64(4633)
- ver = int64(0)
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- rank, err := d.LCLoadElecUPRank(upMID, ver)
- ctx.Convey("Then err should be nil.rank should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(rank, convey.ShouldNotBeNil)
- ctx.So(rank.Count, convey.ShouldEqual, 100)
- })
- })
- })
- }
- func TestDaoLCLoadElecUPRankAfterTTL(t *testing.T) {
- convey.Convey("loadElecUPRankAfterTTL", t, func(ctx convey.C) {
- var (
- upMID = int64(4633)
- ver = int64(0)
- )
- <-time.After(time.Duration(conf.Conf.LocalCache.ElecUPRankTTL))
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- rank, err := d.LCLoadElecUPRank(upMID, ver)
- ctx.Convey("Then err should be nil.rank should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(rank, convey.ShouldBeNil)
- })
- })
- })
- }
|