123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475 |
- package dao
- import (
- "context"
- "reflect"
- "testing"
- "github.com/bouk/monkey"
- "go-common/app/service/main/member/model"
- "go-common/library/cache/memcache"
- "github.com/smartystreets/goconvey/convey"
- )
- func TestDaoexpKey(t *testing.T) {
- var (
- mid = int64(111001740)
- )
- convey.Convey("expKey", t, func(ctx convey.C) {
- p1 := expKey(mid)
- ctx.Convey("p1 should not be nil", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaomoralKey(t *testing.T) {
- var (
- mid = int64(111001740)
- )
- convey.Convey("moralKey", t, func(ctx convey.C) {
- p1 := moralKey(mid)
- ctx.Convey("p1 should not be nil", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaopingMC(t *testing.T) {
- var (
- c = context.Background()
- )
- convey.Convey("pingMC", t, func(ctx convey.C) {
- err := d.pingMC(c)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoSetBaseInfoCache(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(19476037)
- info = &model.BaseInfo{
- Mid: 19476037,
- Name: "lala",
- Sign: "We are the world!",
- }
- )
- convey.Convey("SetBaseInfoCache", t, func(ctx convey.C) {
- err := d.SetBaseInfoCache(c, mid, info)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoBaseInfoCache(t *testing.T) {
- convey.Convey("BaseInfoCache", t, func(ctx convey.C) {
- var (
- c = context.Background()
- mid = int64(19476037)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- info, err := d.BaseInfoCache(c, mid)
- ctx.Convey("Error should be nil. info should not be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(info, convey.ShouldNotBeNil)
- })
- })
- ctx.Convey("When conn.Get gets error", func(ctx convey.C) {
- guard := monkey.PatchInstanceMethod(reflect.TypeOf(d.mc), "Get", func(_ *memcache.Pool,
- _ context.Context) memcache.Conn {
- return memcache.MockWith(memcache.ErrItemObject)
- })
- defer guard.Unpatch()
- _, err := d.BaseInfoCache(c, mid)
- ctx.Convey("Error should be equal to memcache.ErrItemObject", func(ctx convey.C) {
- ctx.So(err, convey.ShouldEqual, memcache.ErrItemObject)
- })
- })
- })
- }
- func TestDaoSetBatchBaseInfoCache(t *testing.T) {
- var (
- c = context.Background()
- bi1 = &model.BaseInfo{
- Mid: 19476037,
- Name: "lala",
- Sign: "We are the world!",
- }
- bi2 = &model.BaseInfo{
- Mid: 4780461,
- Name: "lala",
- Sign: "We are the world!",
- }
- bs = []*model.BaseInfo{bi1, bi2}
- )
- convey.Convey("SetBatchBaseInfoCache", t, func(ctx convey.C) {
- err := d.SetBatchBaseInfoCache(c, bs)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoBatchBaseInfoCache(t *testing.T) {
- var (
- c = context.Background()
- mids = []int64{19476037, 1}
- )
- convey.Convey("BatchBaseInfoCache", t, func(ctx convey.C) {
- cached, missed, err := d.BatchBaseInfoCache(c, mids)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- ctx.Convey("missed should not be nil", func(ctx convey.C) {
- ctx.So(missed, convey.ShouldNotBeNil)
- })
- ctx.Convey("cached should not be nil", func(ctx convey.C) {
- ctx.So(cached, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoDelBaseInfoCache(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(19476037)
- )
- convey.Convey("DelBaseInfoCache", t, func(ctx convey.C) {
- err := d.DelBaseInfoCache(c, mid)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoSetExpCache(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(19476037)
- exp = int64(10)
- )
- convey.Convey("SetExpCache", t, func(ctx convey.C) {
- err := d.SetExpCache(c, mid, exp)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoexpCache(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(19476037)
- )
- convey.Convey("expCache", t, func(ctx convey.C) {
- exp, err := d.expCache(c, mid)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- ctx.Convey("exp should not be nil", func(ctx convey.C) {
- ctx.So(exp, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoexpsCache(t *testing.T) {
- var (
- c = context.Background()
- mids = []int64{19476037, 4780461}
- )
- convey.Convey("expsCache", t, func(ctx convey.C) {
- exps, miss, err := d.expsCache(c, mids)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- ctx.Convey("miss should not be nil", func(ctx convey.C) {
- ctx.So(miss, convey.ShouldBeNil)
- })
- ctx.Convey("exps should not be nil", func(ctx convey.C) {
- ctx.So(exps, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoSetMoralCache(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(19476037)
- moral = &model.Moral{}
- )
- convey.Convey("SetMoralCache", t, func(ctx convey.C) {
- err := d.SetMoralCache(c, mid, moral)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaomoralCache(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(19476037)
- )
- convey.Convey("moralCache", t, func(ctx convey.C) {
- moral, err := d.moralCache(c, mid)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- ctx.Convey("moral should not be nil", func(ctx convey.C) {
- ctx.So(moral, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoDelMoralCache(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(19476037)
- )
- convey.Convey("DelMoralCache", t, func(ctx convey.C) {
- err := d.DelMoralCache(c, mid)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaorealnameInfoKey(t *testing.T) {
- var (
- mid = int64(19476037)
- )
- convey.Convey("realnameApplyKey", t, func(ctx convey.C) {
- key := realnameInfoKey(mid)
- ctx.Convey("p1 should equal realname_info_<mid>", func(ctx convey.C) {
- ctx.So(key, convey.ShouldEqual, "realname_info_19476037")
- })
- })
- }
- func TestDaorealnameCaptureTimesKey(t *testing.T) {
- var (
- mid = int64(19476037)
- )
- convey.Convey("realnameCaptureTimesKey", t, func(ctx convey.C) {
- p1 := realnameCaptureTimesKey(mid)
- ctx.Convey("p1 should not be nil", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaorealnameCaptureCodeKey(t *testing.T) {
- var (
- mid = int64(19476037)
- )
- convey.Convey("realnameCaptureCodeKey", t, func(ctx convey.C) {
- p1 := realnameCaptureCodeKey(mid)
- ctx.Convey("p1 should not be nil", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaorealnameCaptureErrTimesKey(t *testing.T) {
- var (
- mid = int64(19476037)
- )
- convey.Convey("realnameCaptureErrTimesKey", t, func(ctx convey.C) {
- p1 := realnameCaptureErrTimesKey(mid)
- ctx.Convey("p1 should not be nil", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoSetRealnameCaptureTimes(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(19476037)
- times = int(0)
- )
- convey.Convey("SetRealnameCaptureTimes", t, func(ctx convey.C) {
- err := d.SetRealnameCaptureTimes(c, mid, times)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoRealnameCaptureTimesCache(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(19476037)
- )
- convey.Convey("RealnameCaptureTimesCache", t, func(ctx convey.C) {
- times, err := d.RealnameCaptureTimesCache(c, mid)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- ctx.Convey("times should not be nil", func(ctx convey.C) {
- ctx.So(times, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoIncreaseRealnameCaptureTimes(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(19476037)
- )
- convey.Convey("IncreaseRealnameCaptureTimes", t, func(ctx convey.C) {
- err := d.IncreaseRealnameCaptureTimes(c, mid)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoRealnameCaptureCodeCache(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(19476037)
- )
- convey.Convey("RealnameCaptureCodeCache", t, func(ctx convey.C) {
- code, err := d.RealnameCaptureCodeCache(c, mid)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- ctx.Convey("code should not be nil", func(ctx convey.C) {
- ctx.So(code, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoSetRealnameInfo(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(19476037)
- info = &model.RealnameCacheInfo{}
- )
- convey.Convey("SetRealnameApplyInfo", t, func(ctx convey.C) {
- err := d.SetRealnameInfo(c, mid, info)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoRealnameInfoCache(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(19476037)
- )
- convey.Convey("RealnameApplyInfoCache", t, func(ctx convey.C) {
- info, err := d.RealnameInfoCache(c, mid)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- ctx.Convey("info should not be nil", func(ctx convey.C) {
- ctx.So(info, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoDeleteRealnameInfo(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(19476037)
- )
- convey.Convey("DeleteRealnameApplyInfo", t, func(ctx convey.C) {
- err := d.DeleteRealnameInfo(c, mid)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoSetRealnameCaptureCode(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(19476037)
- code = int(0)
- )
- convey.Convey("SetRealnameCaptureCode", t, func(ctx convey.C) {
- err := d.SetRealnameCaptureCode(c, mid, code)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoDeleteRealnameCaptureCode(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(19476037)
- )
- convey.Convey("DeleteRealnameCaptureCode", t, func(ctx convey.C) {
- err := d.DeleteRealnameCaptureCode(c, mid)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoSetRealnameCaptureErrTimes(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(19476037)
- times = int(0)
- )
- convey.Convey("SetRealnameCaptureErrTimes", t, func(ctx convey.C) {
- err := d.SetRealnameCaptureErrTimes(c, mid, times)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoRealnameCaptureErrTimesCache(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(19476037)
- )
- convey.Convey("RealnameCaptureErrTimesCache", t, func(ctx convey.C) {
- times, err := d.RealnameCaptureErrTimesCache(c, mid)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- ctx.Convey("times should not be nil", func(ctx convey.C) {
- ctx.So(times, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoIncreaseRealnameCaptureErrTimes(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(19476037)
- )
- convey.Convey("IncreaseRealnameCaptureErrTimes", t, func(ctx convey.C) {
- err := d.IncreaseRealnameCaptureErrTimes(c, mid)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
- func TestDaoDeleteRealnameCaptureErrTimes(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(19476037)
- )
- convey.Convey("DeleteRealnameCaptureErrTimes", t, func(ctx convey.C) {
- err := d.DeleteRealnameCaptureErrTimes(c, mid)
- ctx.Convey("Error should be nil", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- }
|