123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- package dao
- import (
- "context"
- "testing"
- xtime "time"
- "go-common/app/interface/main/web/model"
- "go-common/library/time"
- "github.com/smartystreets/goconvey/convey"
- "gopkg.in/h2non/gock.v1"
- )
- func TestDaoHelpList(t *testing.T) {
- convey.Convey("HelpList", t, func(ctx convey.C) {
- var (
- c = context.Background()
- pTypeID = ""
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- defer gock.OffAll()
- httpMock("GET", d.helpListURL).Reply(200).JSON(`{"retCode":"000000"}`)
- data, err := d.HelpList(c, pTypeID)
- ctx.Convey("Then err should be nil.data should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.Printf("%+v", data)
- })
- })
- })
- }
- func TestDaokeyHl(t *testing.T) {
- convey.Convey("keyHl", t, func(ctx convey.C) {
- var (
- pTypeID = ""
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- p1 := keyHl(pTypeID)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaokeyHd(t *testing.T) {
- convey.Convey("keyHd", t, func(ctx convey.C) {
- var (
- qTypeID = ""
- keyFlag = int(0)
- pn = int(0)
- ps = int(0)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- p1 := keyHd(qTypeID, keyFlag, pn, ps)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoSetHlCache(t *testing.T) {
- convey.Convey("SetHlCache", t, func(ctx convey.C) {
- var (
- c = context.Background()
- pTypeID = ""
- Hl = []*model.HelpList{}
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- err := d.SetHlCache(c, pTypeID, Hl)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoHlCache(t *testing.T) {
- convey.Convey("HlCache", t, func(ctx convey.C) {
- var (
- c = context.Background()
- pTypeID = ""
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- res, err := d.HlCache(c, pTypeID)
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.Printf("%+v", res)
- })
- })
- })
- }
- func TestDaoHelpDetail(t *testing.T) {
- convey.Convey("HelpDetail", t, func(ctx convey.C) {
- var (
- c = context.Background()
- qTypeID = ""
- keyFlag = int(0)
- pn = int(0)
- ps = int(0)
- ip = ""
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- defer gock.OffAll()
- httpMock("GET", d.helpSearchURL).Reply(200).JSON(`{"retCode":"000000", "total":1}`)
- data, total, err := d.HelpDetail(c, qTypeID, keyFlag, pn, ps, ip)
- ctx.Convey("Then err should be nil.data,total should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(total, convey.ShouldNotBeNil)
- ctx.Printf("%+v", data)
- })
- })
- })
- }
- func TestDaoHelpSearch(t *testing.T) {
- convey.Convey("HelpSearch", t, func(ctx convey.C) {
- var (
- c = context.Background()
- pTypeID = ""
- keyWords = ""
- keyFlag = int(0)
- pn = int(0)
- ps = int(0)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- defer gock.OffAll()
- httpMock("GET", d.helpSearchURL).Reply(200).JSON(`{"retCode":"000000", "total":1}`)
- data, total, err := d.HelpSearch(c, pTypeID, keyWords, keyFlag, pn, ps)
- ctx.Convey("Then err should be nil.data,total should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(total, convey.ShouldNotBeNil)
- ctx.Printf("%+v", data)
- })
- })
- })
- }
- func TestDaoSetDetailCache(t *testing.T) {
- convey.Convey("SetDetailCache", t, func(ctx convey.C) {
- var (
- c = context.Background()
- qTypeID = ""
- keyFlag = int(0)
- pn = int(0)
- ps = int(0)
- total = int(0)
- data = []*model.HelpDeatil{{AllTypeName: "1111"}, {AllTypeName: "2222"}}
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- err := d.SetDetailCache(c, qTypeID, keyFlag, pn, ps, total, data)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoDetailCache(t *testing.T) {
- convey.Convey("DetailCache", t, func(ctx convey.C) {
- var (
- c = context.Background()
- qTypeID = ""
- keyFlag = int(0)
- pn = int(0)
- ps = int(0)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- res, count, err := d.DetailCache(c, qTypeID, keyFlag, pn, ps)
- ctx.Convey("Then err should be nil.res,count should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(count, convey.ShouldNotBeNil)
- convey.Printf("%+v", res)
- })
- })
- })
- }
- func TestDaofromHd(t *testing.T) {
- convey.Convey("fromHd", t, func(ctx convey.C) {
- var (
- i = int64(0)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- p1 := fromHd(i)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaocombineHd(t *testing.T) {
- convey.Convey("combineHd", t, func(ctx convey.C) {
- var (
- create = time.Time(xtime.Now().Unix())
- count = int(0)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- p1 := combineHd(create, count)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
|