123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375 |
- package dao
- import (
- "context"
- "go-common/app/service/main/relation/model"
- "testing"
- "github.com/smartystreets/goconvey/convey"
- )
- func TestDaostatKey(t *testing.T) {
- var (
- mid = int64(1)
- )
- convey.Convey("statKey", t, func(cv convey.C) {
- p1 := statKey(mid)
- cv.Convey("Then p1 should not be nil.", func(cv convey.C) {
- cv.So(p1, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaotagsKey(t *testing.T) {
- var (
- mid = int64(1)
- )
- convey.Convey("tagsKey", t, func(cv convey.C) {
- p1 := tagsKey(mid)
- cv.Convey("Then p1 should not be nil.", func(cv convey.C) {
- cv.So(p1, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaofollowingKey(t *testing.T) {
- var (
- mid = int64(1)
- )
- convey.Convey("followingKey", t, func(cv convey.C) {
- p1 := followingKey(mid)
- cv.Convey("Then p1 should not be nil.", func(cv convey.C) {
- cv.So(p1, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaofollowerKey(t *testing.T) {
- var (
- mid = int64(1)
- )
- convey.Convey("followerKey", t, func(cv convey.C) {
- p1 := followerKey(mid)
- cv.Convey("Then p1 should not be nil.", func(cv convey.C) {
- cv.So(p1, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaotagCountKey(t *testing.T) {
- var (
- mid = int64(1)
- )
- convey.Convey("tagCountKey", t, func(cv convey.C) {
- p1 := tagCountKey(mid)
- cv.Convey("Then p1 should not be nil.", func(cv convey.C) {
- cv.So(p1, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoglobalHotKey(t *testing.T) {
- convey.Convey("globalHotKey", t, func(cv convey.C) {
- p1 := globalHotKey()
- cv.Convey("Then p1 should not be nil.", func(cv convey.C) {
- cv.So(p1, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaofollowerNotifySetting(t *testing.T) {
- var (
- mid = int64(1)
- )
- convey.Convey("followerNotifySetting", t, func(cv convey.C) {
- p1 := followerNotifySetting(mid)
- cv.Convey("Then p1 should not be nil.", func(cv convey.C) {
- cv.So(p1, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaopingMC(t *testing.T) {
- var (
- c = context.Background()
- )
- convey.Convey("pingMC", t, func(cv convey.C) {
- err := d.pingMC(c)
- cv.Convey("Then err should be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoSetFollowingCache(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(1)
- followings = []*model.Following{}
- )
- convey.Convey("SetFollowingCache", t, func(cv convey.C) {
- err := d.SetFollowingCache(c, mid, followings)
- cv.Convey("Then err should be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoFollowingCache(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(1)
- )
- convey.Convey("FollowingCache", t, func(cv convey.C) {
- followings, err := d.FollowingCache(c, mid)
- cv.Convey("Then err should be nil.followings should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(followings, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoDelFollowingCache(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(1)
- )
- convey.Convey("DelFollowingCache", t, func(cv convey.C) {
- err := d.DelFollowingCache(c, mid)
- cv.Convey("Then err should be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoSetFollowerCache(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(1)
- followers = []*model.Following{}
- )
- convey.Convey("SetFollowerCache", t, func(cv convey.C) {
- err := d.SetFollowerCache(c, mid, followers)
- cv.Convey("Then err should be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoFollowerCache(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(1)
- )
- convey.Convey("FollowerCache", t, func(cv convey.C) {
- followers, err := d.FollowerCache(c, mid)
- cv.Convey("Then err should be nil.followers should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(followers, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoDelFollowerCache(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(1)
- )
- convey.Convey("DelFollowerCache", t, func(cv convey.C) {
- err := d.DelFollowerCache(c, mid)
- cv.Convey("Then err should be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaosetFollowingCache(t *testing.T) {
- var (
- c = context.Background()
- key = followingKey(1)
- followings = []*model.Following{}
- )
- convey.Convey("setFollowingCache", t, func(cv convey.C) {
- err := d.setFollowingCache(c, key, followings)
- cv.Convey("Then err should be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaofollowingCache(t *testing.T) {
- var (
- c = context.Background()
- key = followingKey(1)
- )
- convey.Convey("followingCache", t, func(cv convey.C) {
- followings, err := d.followingCache(c, key)
- cv.Convey("Then err should be nil.followings should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(followings, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaodelFollowingCache(t *testing.T) {
- var (
- c = context.Background()
- key = followingKey(1)
- )
- convey.Convey("delFollowingCache", t, func(cv convey.C) {
- err := d.delFollowingCache(c, key)
- cv.Convey("Then err should be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoTagCountCache(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(1)
- tagCount = []*model.TagCount{
- {
- Tagid: 1,
- Name: "test",
- Count: 1,
- },
- }
- )
- convey.Convey("TagCountCache", t, func(cv convey.C) {
- err := d.SetTagCountCache(c, mid, tagCount)
- cv.So(err, convey.ShouldBeNil)
- tagCount, err := d.TagCountCache(c, mid)
- cv.So(err, convey.ShouldBeNil)
- cv.So(tagCount, convey.ShouldNotBeNil)
- err = d.DelTagCountCache(c, mid)
- cv.So(err, convey.ShouldBeNil)
- })
- }
- func TestDaoTagsCache(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(1)
- tags = &model.Tags{
- Tags: map[int64]*model.Tag{
- 1: {
- Id: 1,
- Name: "1",
- Status: 1,
- },
- },
- }
- )
- convey.Convey("TagsCache", t, func(cv convey.C) {
- err := d.SetTagsCache(c, mid, tags)
- cv.Convey("SetTagsCache; Then err should be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- })
- tags, err := d.TagsCache(c, mid)
- cv.Convey("TagsCache; Then err should be nil.tags should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(tags, convey.ShouldNotBeNil)
- })
- err = d.DelTagsCache(c, mid)
- cv.Convey("DelTagsCache; Then err should be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoSetGlobalHotRecCache(t *testing.T) {
- var (
- c = context.Background()
- fids = []int64{1}
- )
- convey.Convey("SetGlobalHotRecCache", t, func(cv convey.C) {
- err := d.SetGlobalHotRecCache(c, fids)
- cv.Convey("Then err should be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoGlobalHotRecCache(t *testing.T) {
- var (
- c = context.Background()
- )
- convey.Convey("GlobalHotRecCache", t, func(cv convey.C) {
- fs, err := d.GlobalHotRecCache(c)
- cv.Convey("Then err should be nil.fs should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(fs, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaostatCache(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(1)
- st = &model.Stat{
- Mid: 1,
- Follower: 1,
- Following: 1,
- Black: 1,
- Whisper: 1,
- }
- )
- convey.Convey("statCache", t, func(cv convey.C) {
- err := d.SetStatCache(c, mid, st)
- cv.Convey("SetStatCache; Then err should be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- })
- s1, err := d.statCache(c, mid)
- cv.Convey("statCache; Then err should be nil.p1 should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(s1, convey.ShouldNotBeNil)
- })
- p1, p2, err := d.statsCache(c, []int64{1})
- cv.Convey("statsCache; Then err should be nil.p1,p2 should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(p2, convey.ShouldNotBeNil)
- cv.So(p1, convey.ShouldNotBeNil)
- })
- err = d.DelStatCache(c, mid)
- cv.Convey("DelStatCache; Then err should be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoGetFollowerNotifyCache(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(1)
- val = &model.FollowerNotifySetting{
- Mid: 1,
- Enabled: true,
- }
- )
- convey.Convey("GetFollowerNotifyCache", t, func(cv convey.C) {
- err := d.SetFollowerNotifyCache(c, mid, val)
- cv.Convey("SetFollowerNotifyCache; Then err should be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- })
- res, err := d.GetFollowerNotifyCache(c, mid)
- cv.Convey("GetFollowerNotifyCache; Then err should be nil.res should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(res, convey.ShouldNotBeNil)
- })
- err = d.DelFollowerNotifyCache(c, mid)
- cv.Convey("DelFollowerNotifyCache; Then err should be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- })
- })
- }
|