123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506 |
- package dao
- import (
- "context"
- "go-common/app/service/main/relation/model"
- "go-common/app/service/main/relation/model/i64b"
- "math/rand"
- "testing"
- "time"
- "github.com/smartystreets/goconvey/convey"
- )
- func init() {
- rand.Seed(time.Now().UnixNano())
- }
- var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
- func RandStringRunes(n int) string {
- b := make([]rune, n)
- for i := range b {
- b[i] = letterRunes[rand.Intn(len(letterRunes))]
- }
- return string(b)
- }
- func TestDaohit(t *testing.T) {
- var (
- id = int64(1)
- )
- convey.Convey("hit", t, func(cv convey.C) {
- p1 := hit(id)
- cv.Convey("Then p1 should not be nil.", func(cv convey.C) {
- cv.So(p1, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaostatHit(t *testing.T) {
- var (
- id = int64(1)
- )
- convey.Convey("statHit", t, func(cv convey.C) {
- p1 := statHit(id)
- cv.Convey("Then p1 should not be nil.", func(cv convey.C) {
- cv.So(p1, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaotagHit(t *testing.T) {
- var (
- id = int64(1)
- )
- convey.Convey("tagHit", t, func(cv convey.C) {
- p1 := tagHit(id)
- cv.Convey("Then p1 should not be nil.", func(cv convey.C) {
- cv.So(p1, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaotagUserHit(t *testing.T) {
- var (
- id = int64(1)
- )
- convey.Convey("tagUserHit", t, func(cv convey.C) {
- p1 := tagUserHit(id)
- cv.Convey("Then p1 should not be nil.", func(cv convey.C) {
- cv.So(p1, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoBeginTran(t *testing.T) {
- var (
- c = context.Background()
- )
- convey.Convey("BeginTran", t, func(cv convey.C) {
- p1, err := d.BeginTran(c)
- cv.Convey("Then err should be nil.p1 should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(p1, convey.ShouldNotBeNil)
- })
- p1.Commit()
- })
- }
- func TestDaoFollowings(t *testing.T) {
- var (
- c = context.Background()
- tx, _ = d.BeginTran(c)
- mid = int64(1)
- fid = int64(2)
- mask = uint32(2)
- source = uint8(1)
- now = time.Now()
- )
- convey.Convey("Followings", t, func(cv convey.C) {
- affected, err := d.TxAddFollowing(c, tx, mid, fid, mask, source, now)
- cv.Convey("Then err should be nil.affected should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(affected, convey.ShouldNotBeNil)
- })
- tx.Commit()
- res, err := d.Followings(c, mid)
- cv.Convey("Then err should be nil.res should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(res, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoFollowingsIn(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(1)
- fids = []int64{1, 2}
- )
- convey.Convey("FollowingsIn", t, func(cv convey.C) {
- res, err := d.FollowingsIn(c, mid, fids)
- cv.Convey("Then err should be nil.res should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(res, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoTxSetFollowing(t *testing.T) {
- var (
- c = context.Background()
- tx, _ = d.BeginTran(c)
- mid = int64(1)
- fid = int64(2)
- attribute = uint32(2)
- source = uint8(1)
- status = int(0)
- now = time.Now()
- )
- convey.Convey("TxSetFollowing", t, func(cv convey.C) {
- affected, err := d.TxSetFollowing(c, tx, mid, fid, attribute, source, status, now)
- cv.Convey("Then err should be nil.affected should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(affected, convey.ShouldNotBeNil)
- })
- tx.Commit()
- })
- }
- func TestDaoFollowers(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(1)
- )
- convey.Convey("Followers", t, func(cv convey.C) {
- res, err := d.Followers(c, mid)
- cv.Convey("Then err should be nil.res should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(res, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoTxAddFollower(t *testing.T) {
- var (
- c = context.Background()
- tx, _ = d.BeginTran(c)
- mid = int64(1)
- fid = int64(2)
- mask = uint32(2)
- source = uint8(1)
- now = time.Now()
- )
- convey.Convey("TxAddFollower", t, func(cv convey.C) {
- affected, err := d.TxAddFollower(c, tx, mid, fid, mask, source, now)
- cv.Convey("Then err should be nil.affected should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(affected, convey.ShouldNotBeNil)
- })
- tx.Commit()
- })
- }
- func TestDaoTxSetFollower(t *testing.T) {
- var (
- c = context.Background()
- tx, _ = d.BeginTran(c)
- mid = int64(1)
- fid = int64(2)
- attribute = uint32(2)
- source = uint8(1)
- status = int(0)
- now = time.Now()
- )
- convey.Convey("TxSetFollower", t, func(cv convey.C) {
- affected, err := d.TxSetFollower(c, tx, mid, fid, attribute, source, status, now)
- cv.Convey("Then err should be nil.affected should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(affected, convey.ShouldNotBeNil)
- })
- tx.Commit()
- })
- }
- func TestDaoStat(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(1)
- )
- convey.Convey("Stat", t, func(cv convey.C) {
- stat, err := d.Stat(c, mid)
- cv.Convey("Then err should be nil.stat should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(stat, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoTxStat(t *testing.T) {
- var (
- c = context.Background()
- tx, _ = d.BeginTran(c)
- mid = int64(1)
- )
- convey.Convey("TxStat", t, func(cv convey.C) {
- stat, err := d.TxStat(c, tx, mid)
- cv.Convey("Then err should be nil.stat should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(stat, convey.ShouldNotBeNil)
- })
- tx.Commit()
- })
- }
- func TestDaoAddStat(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(1)
- stat = &model.Stat{
- Mid: 1,
- }
- now = time.Now()
- )
- convey.Convey("AddStat", t, func(cv convey.C) {
- affected, err := d.AddStat(c, mid, stat, now)
- cv.Convey("Then err should be nil.affected should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(affected, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoTxAddStat(t *testing.T) {
- var (
- c = context.Background()
- tx, _ = d.BeginTran(c)
- mid = int64(1)
- stat = &model.Stat{
- Mid: 1,
- }
- now = time.Now()
- )
- convey.Convey("TxAddStat", t, func(cv convey.C) {
- affected, err := d.TxAddStat(c, tx, mid, stat, now)
- cv.Convey("Then err should be nil.affected should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(affected, convey.ShouldNotBeNil)
- })
- tx.Commit()
- })
- }
- func TestDaoTxSetStat(t *testing.T) {
- var (
- c = context.Background()
- tx, _ = d.BeginTran(c)
- mid = int64(1)
- stat = &model.Stat{
- Mid: 1,
- }
- now = time.Now()
- )
- convey.Convey("TxSetStat", t, func(cv convey.C) {
- affected, err := d.TxSetStat(c, tx, mid, stat, now)
- cv.Convey("Then err should be nil.affected should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(affected, convey.ShouldNotBeNil)
- })
- tx.Commit()
- })
- }
- func TestDaoRelation(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(1)
- fid = int64(2)
- )
- convey.Convey("Relation", t, func(cv convey.C) {
- attr, err := d.Relation(c, mid, fid)
- cv.Convey("Then err should be nil.attr should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(attr, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoLoadMonitor(t *testing.T) {
- var (
- c = context.Background()
- )
- convey.Convey("LoadMonitor", t, func(cv convey.C) {
- affected, err := d.AddMonitor(c, 1, time.Now())
- cv.Convey("Then err should be nil.affected should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(affected, convey.ShouldNotBeNil)
- })
- mids, err := d.LoadMonitor(c)
- cv.Convey("Then err should be nil.mids should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(mids, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoDelMonitor(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(1)
- )
- convey.Convey("DelMonitor", t, func(cv convey.C) {
- affected, err := d.DelMonitor(c, mid)
- cv.Convey("Then err should be nil.affected should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(affected, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoTxDelTagUser(t *testing.T) {
- var (
- c = context.Background()
- tx, _ = d.BeginTran(c)
- mid = int64(1)
- fid = int64(2)
- )
- convey.Convey("TxDelTagUser", t, func(cv convey.C) {
- affected, err := d.TxDelTagUser(c, tx, mid, fid)
- cv.Convey("Then err should be nil.affected should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(affected, convey.ShouldNotBeNil)
- })
- tx.Commit()
- })
- }
- func TestDaoTags(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(1)
- )
- convey.Convey("Tags", t, func(cv convey.C) {
- res, err := d.Tags(c, mid)
- cv.Convey("Then err should be nil.res should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(res, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoDelTag(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(1)
- id = int64(2)
- )
- convey.Convey("DelTag", t, func(cv convey.C) {
- affected, err := d.DelTag(c, mid, id)
- cv.Convey("Then err should be nil.affected should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(affected, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoSetTagName(t *testing.T) {
- var (
- c = context.Background()
- id = int64(1)
- mid = int64(2)
- name = "test"
- now = time.Now()
- )
- convey.Convey("SetTagName", t, func(cv convey.C) {
- affected, err := d.SetTagName(c, id, mid, name, now)
- cv.Convey("Then err should be nil.affected should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(affected, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoTagUserByMidFid(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(1)
- fid = int64(2)
- )
- convey.Convey("TagUserByMidFid", t, func(cv convey.C) {
- lastID, err := d.AddTag(c, mid, fid, "test"+RandStringRunes(5), time.Now())
- cv.Convey("AddTag; Then err should be nil.lastID should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(lastID, convey.ShouldNotBeNil)
- })
- tids := i64b.Int64Bytes([]int64{lastID})
- affected, err := d.SetTagUser(c, mid, fid, tids, time.Now())
- cv.Convey("SetTagUser; Then err should be nil.affected should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(affected, convey.ShouldNotBeNil)
- })
- affected2, err := d.AddTagUser(c, mid, fid, tids, time.Now())
- cv.Convey("AddTagUser; Then err should be nil.affected should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(affected2, convey.ShouldNotBeNil)
- })
- tag1, err := d.TagUserByMidFid(c, mid, fid)
- cv.Convey("TagUserByMidFid; Then err should be nil.tag1 should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(tag1, convey.ShouldNotBeNil)
- })
- tags2, err := d.UsersTags(c, mid, []int64{fid})
- cv.Convey("UsersTags; Then err should be nil.tags2 should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(tags2, convey.ShouldNotBeNil)
- })
- tags3, err := d.UserTag(c, mid)
- cv.Convey("UserTag; Then err should be nil.tags3 should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(tags3, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoHasReachAchieve(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(1)
- achieve model.AchieveFlag
- )
- convey.Convey("HasReachAchieve", t, func(cv convey.C) {
- p1 := d.HasReachAchieve(c, mid, achieve)
- cv.Convey("Then p1 should not be nil.", func(cv convey.C) {
- cv.So(p1, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoFollowerNotifySetting(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(1)
- )
- convey.Convey("FollowerNotifySetting", t, func(cv convey.C) {
- p1, err := d.FollowerNotifySetting(c, mid)
- cv.Convey("Then err should be nil.p1 should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(p1, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoEnableFollowerNotify(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(1)
- )
- convey.Convey("EnableFollowerNotify", t, func(cv convey.C) {
- affected, err := d.EnableFollowerNotify(c, mid)
- cv.Convey("Then err should be nil.affected should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(affected, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoDisableFollowerNotify(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(1)
- )
- convey.Convey("DisableFollowerNotify", t, func(cv convey.C) {
- affected, err := d.DisableFollowerNotify(c, mid)
- cv.Convey("Then err should be nil.affected should not be nil.", func(cv convey.C) {
- cv.So(err, convey.ShouldBeNil)
- cv.So(affected, convey.ShouldNotBeNil)
- })
- })
- }
|