123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490 |
- package dao
- import (
- "context"
- "testing"
- "go-common/app/service/main/favorite/model"
- "github.com/smartystreets/goconvey/convey"
- )
- func TestMultiExpireRelations(t *testing.T) {
- var (
- c = context.TODO()
- fids = []int64{1, 2}
- mid = int64(0)
- )
- convey.Convey("RemFidsRedis", t, func(ctx convey.C) {
- _, err := d.MultiExpireRelations(c, mid, fids)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestFavRemFidsRedis(t *testing.T) {
- var (
- c = context.TODO()
- typ = int8(0)
- mid = int64(0)
- fs = &model.Folder{}
- )
- convey.Convey("RemFidsRedis", t, func(ctx convey.C) {
- err := d.RemFidsRedis(c, typ, mid, fs)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestFavfavedBitKey(t *testing.T) {
- var (
- tp = int8(1)
- mid = int64(88888894)
- )
- convey.Convey("favedBitKey", t, func(ctx convey.C) {
- p1 := favedBitKey(tp, mid)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- }
- func TestFavAddRelationCache(t *testing.T) {
- var (
- c = context.TODO()
- m = &model.Favorite{
- Oid: 1,
- Fid: 1,
- Mid: 88888894,
- Type: 1,
- }
- )
- convey.Convey("AddRelationCache", t, func(ctx convey.C) {
- err := d.AddRelationCache(c, m)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestFavfolderKey(t *testing.T) {
- var (
- tp = int8(1)
- mid = int64(88888894)
- )
- convey.Convey("folderKey", t, func(ctx convey.C) {
- p1 := folderKey(tp, mid)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- }
- func TestFavrelationKey(t *testing.T) {
- var (
- mid = int64(88888894)
- fid = int64(1)
- )
- convey.Convey("relationKey", t, func(ctx convey.C) {
- p1 := relationKey(mid, fid)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- }
- func TestFavrelationOidsKey(t *testing.T) {
- var (
- tp = int8(1)
- mid = int64(88888894)
- )
- convey.Convey("relationOidsKey", t, func(ctx convey.C) {
- p1 := relationOidsKey(tp, mid)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- }
- func TestFavpingRedis(t *testing.T) {
- var (
- c = context.TODO()
- )
- convey.Convey("pingRedis", t, func(ctx convey.C) {
- err := d.pingRedis(c)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestFavExpireRelations(t *testing.T) {
- var (
- c = context.TODO()
- mid = int64(88888894)
- fid = int64(1)
- )
- convey.Convey("ExpireRelations", t, func(ctx convey.C) {
- ok, err := d.ExpireRelations(c, mid, fid)
- ctx.Convey("Then err should be nil.ok should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(ok, convey.ShouldNotBeNil)
- })
- })
- }
- func TestFavExpireFolder(t *testing.T) {
- var (
- c = context.TODO()
- tp = int8(1)
- mid = int64(88888894)
- )
- convey.Convey("ExpireFolder", t, func(ctx convey.C) {
- ok, err := d.ExpireFolder(c, tp, mid)
- ctx.Convey("Then err should be nil.ok should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(ok, convey.ShouldNotBeNil)
- })
- })
- }
- func TestFavAddFidsRedis(t *testing.T) {
- var (
- c = context.TODO()
- typ = int8(0)
- mid = int64(0)
- fs = &model.Folder{}
- )
- convey.Convey("AddFidsRedis", t, func(ctx convey.C) {
- err := d.AddFidsRedis(c, typ, mid, fs)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestFavFidsRedis(t *testing.T) {
- var (
- c = context.TODO()
- tp = int8(0)
- mid = int64(0)
- )
- convey.Convey("FidsRedis", t, func(ctx convey.C) {
- _, err := d.FidsRedis(c, tp, mid)
- ctx.Convey("Then err should be nil.fids should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestFavDelFidsRedis(t *testing.T) {
- var (
- c = context.TODO()
- typ = int8(1)
- mid = int64(88888894)
- )
- convey.Convey("DelFidsRedis", t, func(ctx convey.C) {
- err := d.DelFidsRedis(c, typ, mid)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestFavAddFoldersCache(t *testing.T) {
- var (
- c = context.TODO()
- tp = int8(1)
- mid = int64(88888894)
- folders = []*model.Folder{
- &model.Folder{
- ID: 1,
- },
- }
- )
- convey.Convey("AddFoldersCache", t, func(ctx convey.C) {
- err := d.AddFoldersCache(c, tp, mid, folders)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestFavFolderRelationsCache(t *testing.T) {
- var (
- c = context.TODO()
- typ = int8(1)
- mid = int64(88888894)
- fid = int64(1)
- start = int(1)
- end = int(2)
- )
- convey.Convey("FolderRelationsCache", t, func(ctx convey.C) {
- _, err := d.FolderRelationsCache(c, typ, mid, fid, start, end)
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestFavAllFolderRelationsCache(t *testing.T) {
- var (
- c = context.TODO()
- typ = int8(1)
- mid = int64(88888894)
- fid = int64(1)
- start = int(1)
- end = int(2)
- )
- convey.Convey("FolderAllRelationsCache", t, func(ctx convey.C) {
- _, err := d.FolderAllRelationsCache(c, typ, mid, fid, start, end)
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestFavCntRelationsCache(t *testing.T) {
- var (
- c = context.TODO()
- mid = int64(88888894)
- fid = int64(1)
- )
- convey.Convey("CntRelationsCache", t, func(ctx convey.C) {
- cnt, err := d.CntRelationsCache(c, mid, fid)
- ctx.Convey("Then err should be nil.cnt should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(cnt, convey.ShouldNotBeNil)
- })
- })
- }
- func TestFavCntAllRelationsCache(t *testing.T) {
- var (
- c = context.TODO()
- mid = int64(88888894)
- fid = int64(1)
- )
- convey.Convey("CntAllRelationsCache", t, func(ctx convey.C) {
- cnt, err := d.CntAllRelationsCache(c, mid, fid)
- ctx.Convey("Then err should be nil.cnt should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(cnt, convey.ShouldNotBeNil)
- })
- })
- }
- func TestFavExpireRelationOids(t *testing.T) {
- var (
- c = context.TODO()
- tp = int8(1)
- mid = int64(88888894)
- )
- convey.Convey("ExpireRelationOids", t, func(ctx convey.C) {
- ok, err := d.ExpireRelationOids(c, tp, mid)
- ctx.Convey("Then err should be nil.ok should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(ok, convey.ShouldNotBeNil)
- })
- })
- }
- func TestFavAddRelationOidCache(t *testing.T) {
- var (
- c = context.TODO()
- tp = int8(1)
- mid = int64(88888894)
- oid = int64(1)
- )
- convey.Convey("AddRelationOidCache", t, func(ctx convey.C) {
- err := d.AddRelationOidCache(c, tp, mid, oid)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestFavRemRelationOidCache(t *testing.T) {
- var (
- c = context.TODO()
- tp = int8(1)
- mid = int64(88888894)
- oid = int64(123)
- )
- convey.Convey("RemRelationOidCache", t, func(ctx convey.C) {
- err := d.RemRelationOidCache(c, tp, mid, oid)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestFavIsFavedCache(t *testing.T) {
- var (
- c = context.TODO()
- tp = int8(1)
- mid = int64(88888894)
- oid = int64(123)
- )
- convey.Convey("IsFavedCache", t, func(ctx convey.C) {
- isFaved, err := d.IsFavedCache(c, tp, mid, oid)
- ctx.Convey("Then err should be nil.isFaved should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(isFaved, convey.ShouldNotBeNil)
- })
- })
- }
- func TestFavIsFavedsCache(t *testing.T) {
- var (
- c = context.TODO()
- tp = int8(1)
- mid = int64(88888894)
- oids = []int64{1, 2, 3}
- )
- convey.Convey("IsFavedsCache", t, func(ctx convey.C) {
- favoreds, err := d.IsFavedsCache(c, tp, mid, oids)
- ctx.Convey("Then err should be nil.favoreds should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(favoreds, convey.ShouldNotBeNil)
- })
- })
- }
- func TestFavSetFavedBit(t *testing.T) {
- var (
- c = context.TODO()
- tp = int8(1)
- mid = int64(88888894)
- )
- convey.Convey("SetFavedBit", t, func(ctx convey.C) {
- err := d.SetFavedBit(c, tp, mid)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestFavSetUnFavedBit(t *testing.T) {
- var (
- c = context.TODO()
- tp = int8(1)
- mid = int64(88888894)
- )
- convey.Convey("SetUnFavedBit", t, func(ctx convey.C) {
- err := d.SetUnFavedBit(c, tp, mid)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestFavFavedBit(t *testing.T) {
- var (
- c = context.TODO()
- tp = int8(1)
- mid = int64(88888894)
- )
- convey.Convey("FavedBit", t, func(ctx convey.C) {
- unfaved, err := d.FavedBit(c, tp, mid)
- ctx.Convey("Then err should be nil.unfaved should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(unfaved, convey.ShouldNotBeNil)
- })
- })
- }
- func TestFavDelRelationsCache(t *testing.T) {
- var (
- c = context.TODO()
- mid = int64(88888894)
- fid = int64(1)
- )
- convey.Convey("DelRelationsCache", t, func(ctx convey.C) {
- err := d.DelRelationsCache(c, mid, fid)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestFavDelAllRelationsCache(t *testing.T) {
- var (
- c = context.TODO()
- mid = int64(88888894)
- fid = int64(1)
- )
- convey.Convey("DelRelationsCache", t, func(ctx convey.C) {
- err := d.DelAllRelationsCache(c, mid, fid)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestFavRecentOidsCache(t *testing.T) {
- var (
- c = context.TODO()
- typ = int8(1)
- mid = int64(88888894)
- fids = []int64{1}
- )
- convey.Convey("RecentOidsCache", t, func(ctx convey.C) {
- rctFidsMap, missFids, err := d.RecentOidsCache(c, typ, mid, fids)
- ctx.Convey("Then err should be nil.rctFidsMap,missFids should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(missFids, convey.ShouldNotBeNil)
- ctx.So(rctFidsMap, convey.ShouldNotBeNil)
- })
- })
- }
- func TestFavBatchOidsRedis(t *testing.T) {
- var (
- c = context.TODO()
- tp = int8(1)
- mid = int64(88888894)
- limit = int(10)
- )
- convey.Convey("BatchOidsRedis", t, func(ctx convey.C) {
- oids, err := d.BatchOidsRedis(c, tp, mid, limit)
- ctx.Convey("Then err should be nil.oids should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(oids, convey.ShouldNotBeNil)
- })
- })
- }
- func TestIsCleaned(t *testing.T) {
- var (
- c = context.TODO()
- typ = int8(2)
- mid = int64(88888894)
- fid = int64(59)
- )
- convey.Convey("IsCleaned", t, func(ctx convey.C) {
- _, err := d.IsCleaned(c, typ, mid, fid)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestSetCleanedCache(t *testing.T) {
- var (
- c = context.TODO()
- typ = int8(2)
- mid = int64(88888894)
- fid = int64(59)
- ftime = int64(88888894)
- expire = int64(86400)
- )
- convey.Convey("SetCleanedCache", t, func(ctx convey.C) {
- err := d.SetCleanedCache(c, typ, mid, fid, ftime, expire)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
|