123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401 |
- package dao
- import (
- "context"
- "testing"
- "go-common/app/job/main/reply-feed/model"
- "github.com/smartystreets/goconvey/convey"
- )
- func TestDaokeyUV(t *testing.T) {
- convey.Convey("keyUV", t, func(ctx convey.C) {
- var (
- action = ""
- hour = 0
- slot = 0
- kind = ""
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- p1 := keyUV(action, hour, slot, kind)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoUV(t *testing.T) {
- convey.Convey("addUV+countUV", t, func(ctx convey.C) {
- var (
- action = "test"
- hour = 0
- slot = 0
- kind = "test"
- mid = int64(0)
- err error
- counts []int64
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- err = d.AddUV(context.Background(), action, hour, slot, mid, kind)
- ctx.So(err, convey.ShouldBeNil)
- keys := []string{keyUV(action, hour, slot, kind)}
- counts, err = d.CountUV(context.Background(), keys)
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(len(counts), convey.ShouldEqual, 1)
- })
- })
- }
- func TestDaokeyRefreshChecker(t *testing.T) {
- convey.Convey("keyRefreshChecker", t, func(ctx convey.C) {
- var (
- oid = int64(0)
- tp = int(0)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- p1 := keyRefreshChecker(oid, tp)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaokeyReplyZSet(t *testing.T) {
- convey.Convey("keyReplyZSet", t, func(ctx convey.C) {
- var (
- name = ""
- oid = int64(0)
- tp = int(0)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- p1 := keyReplyZSet(name, oid, tp)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaokeyReplySet(t *testing.T) {
- convey.Convey("keyReplySet", t, func(ctx convey.C) {
- var (
- oid = int64(0)
- tp = int(0)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- p1 := keyReplySet(oid, tp)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoPingRedis(t *testing.T) {
- convey.Convey("PingRedis", t, func(ctx convey.C) {
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- err := d.PingRedis(context.Background())
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoExpireCheckerRds(t *testing.T) {
- convey.Convey("ExpireCheckerRds", t, func(ctx convey.C) {
- var (
- oid = int64(0)
- tp = int(0)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- ok, err := d.ExpireCheckerRds(context.Background(), oid, tp)
- 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 TestDaoExpireReplyZSetRds(t *testing.T) {
- convey.Convey("ExpireReplyZSetRds", t, func(ctx convey.C) {
- var (
- name = ""
- oid = int64(0)
- tp = int(0)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- ok, err := d.ExpireReplyZSetRds(context.Background(), name, oid, tp)
- 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 TestDaoExpireReplySetRds(t *testing.T) {
- convey.Convey("ExpireReplySetRds", t, func(ctx convey.C) {
- var (
- oid = int64(0)
- tp = int(0)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- ok, err := d.ExpireReplySetRds(context.Background(), oid, tp)
- 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 TestDaoGetReplySetRds(t *testing.T) {
- convey.Convey("ReplySetRds", t, func(ctx convey.C) {
- var (
- oid = int64(-1)
- tp = int(-1)
- idMap = make(map[int64]struct{})
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- for i := 0; i < 10; i++ {
- if err := d.AddReplySetRds(context.Background(), oid, tp, int64(i)); err != nil {
- return
- }
- idMap[int64(i)] = struct{}{}
- }
- d.ExpireReplySetRds(context.Background(), oid, tp)
- rpIDs, err := d.ReplySetRds(context.Background(), oid, tp)
- ctx.Convey("Then err should be nil.rpIDs should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(len(rpIDs), convey.ShouldEqual, 10)
- for _, rpID := range rpIDs {
- if _, ok := idMap[rpID]; !ok {
- t.Fatal("id not match")
- }
- }
- })
- })
- })
- }
- func TestDaoSetReplySetRds(t *testing.T) {
- convey.Convey("SetReplySetRds", t, func(ctx convey.C) {
- var (
- oid = int64(0)
- tp = int(0)
- rpIDs = []int64{}
- c = context.Background()
- )
- for i := 0; i < 10000; i++ {
- rpIDs = append(rpIDs, int64(i))
- }
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- err := d.SetReplySetRds(c, oid, tp, rpIDs)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- receivedRpIDs, err := d.ReplySetRds(c, oid, tp)
- if err != nil {
- t.Fatal(err)
- }
- ctx.So(len(receivedRpIDs), convey.ShouldEqual, len(rpIDs))
- })
- d.DelReplySetRds(c, oid, tp)
- })
- }
- func TestDaoRemReplySetRds(t *testing.T) {
- convey.Convey("RemReplySetRds", t, func(ctx convey.C) {
- var (
- oid = int64(0)
- rpID = int64(0)
- tp = int(0)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- err := d.RemReplySetRds(context.Background(), oid, rpID, tp)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoDelReplySetRds(t *testing.T) {
- convey.Convey("DelReplySetRds", t, func(ctx convey.C) {
- var (
- oid = int64(0)
- tp = int(0)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- err := d.DelReplySetRds(context.Background(), oid, tp)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoAddReplySetRds(t *testing.T) {
- convey.Convey("AddReplySetRds", t, func(ctx convey.C) {
- var (
- oid = int64(0)
- tp = int(0)
- rpID = int64(0)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- err := d.AddReplySetRds(context.Background(), oid, tp, rpID)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoGetReplyZSetRds(t *testing.T) {
- convey.Convey("ReplyZSetRds", t, func(ctx convey.C) {
- var (
- name = ""
- oid = int64(0)
- tp = int(0)
- start = int(0)
- end = int(0)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- rpIDs, err := d.ReplyZSetRds(context.Background(), name, oid, tp, start, end)
- ctx.Convey("Then err should be nil.rpIDs should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(rpIDs, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoSetReplyZSetRds(t *testing.T) {
- convey.Convey("SetReplyZSetRds", t, func(ctx convey.C) {
- var (
- name = "test"
- oid = int64(0)
- tp = int(0)
- c = context.Background()
- rs = []*model.ReplyScore{}
- )
- for i := 0; i < 10000; i++ {
- rs = append(rs, &model.ReplyScore{RpID: int64(i), Score: float64(i)})
- }
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- err := d.SetReplyZSetRds(c, name, oid, tp, rs)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- rpIDs, err := d.ReplyZSetRds(c, name, oid, tp, 0, -1)
- if err != nil {
- t.Fatal(err)
- }
- ctx.So(len(rpIDs), convey.ShouldEqual, len(rs))
- })
- d.DelReplyZSetRds(c, []string{name}, oid, tp)
- })
- }
- func TestDaoAddReplyZSetRds(t *testing.T) {
- convey.Convey("AddReplyZSetRds", t, func(ctx convey.C) {
- var (
- name = ""
- oid = int64(0)
- tp = int(0)
- rs = &model.ReplyScore{}
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- err := d.AddReplyZSetRds(context.Background(), name, oid, tp, rs)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoRemReplyZSetRds(t *testing.T) {
- convey.Convey("RemReplyZSetRds", t, func(ctx convey.C) {
- var (
- name = ""
- oid = int64(0)
- tp = int(0)
- rpID = int64(0)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- err := d.RemReplyZSetRds(context.Background(), name, oid, tp, rpID)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoDelReplyZSetRds(t *testing.T) {
- convey.Convey("DelReplyZSetRds", t, func(ctx convey.C) {
- var (
- names = []string{}
- oid = int64(0)
- tp = int(0)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- err := d.DelReplyZSetRds(context.Background(), names, oid, tp)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoGetCheckerTsRds(t *testing.T) {
- convey.Convey("CheckerTsRds", t, func(ctx convey.C) {
- var (
- oid = int64(-1)
- tp = int(0)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- ts, err := d.CheckerTsRds(context.Background(), oid, tp)
- ctx.Convey("Then err should be nil.ts should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(ts, convey.ShouldEqual, 0)
- })
- })
- })
- }
- func TestDaoSetCheckerTsRds(t *testing.T) {
- convey.Convey("SetCheckerTsRds", t, func(ctx convey.C) {
- var (
- oid = int64(0)
- tp = int(0)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- err := d.SetCheckerTsRds(context.Background(), oid, tp)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoRangeReplyZSetRds(t *testing.T) {
- convey.Convey("RangeReplyZSetRds", t, func(ctx convey.C) {
- var (
- oid = int64(0)
- tp = int(0)
- name = ""
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- rpIDs, err := d.RangeReplyZSetRds(context.Background(), name, oid, tp, 0, 0)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(len(rpIDs), convey.ShouldEqual, 0)
- })
- })
- })
- }
|