123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543 |
- package search
- import (
- "context"
- "flag"
- "fmt"
- "path/filepath"
- "testing"
- "time"
- "go-common/app/admin/main/feed/conf"
- searchModel "go-common/app/admin/main/feed/model/search"
- "go-common/library/log"
- "github.com/smartystreets/goconvey/convey"
- )
- var (
- s *Service
- c = context.Background()
- )
- func init() {
- var (
- err error
- )
- dir, _ := filepath.Abs("../../cmd/feed-admin-test.toml")
- flag.Set("conf", dir)
- conf.Init()
- if s = New(conf.Conf); err != nil {
- log.Error("bgmdao.New error(%v)", err)
- return
- }
- }
- func TestIsTodayAutoPubHot(t *testing.T) {
- convey.Convey("isTodayAutoPubHot", t, func(ctx convey.C) {
- var (
- c = context.Background()
- err error
- res bool
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- res, err = s.isTodayAutoPubHot(c)
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestIsTodayAutoPubDark(t *testing.T) {
- convey.Convey("isTodayAutoPubDark", t, func(ctx convey.C) {
- var (
- err error
- res bool
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- res, err = s.isTodayAutoPubDark(c)
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestParseTime(t *testing.T) {
- convey.Convey("parseTime", t, func(ctx convey.C) {
- var (
- err error
- res time.Time
- )
- timeTwelve := time.Now().Format("2006-01-02 ") + "12:00:00"
- layout := "2006-01-02 15:04:05"
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- res, err = s.parseTime(timeTwelve, layout)
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldNotBeNil)
- })
- fmt.Println(res)
- })
- })
- }
- func TestHotwordFromDB(t *testing.T) {
- convey.Convey("HotwordFromDB", t, func(ctx convey.C) {
- var (
- err error
- res []searchModel.Intervene
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- res, _, err = s.HotwordFromDB("2018-09-05")
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldNotBeNil)
- })
- fmt.Println(res)
- })
- })
- }
- func TestDarkwordFromDB(t *testing.T) {
- convey.Convey("HotwordFromDB", t, func(ctx convey.C) {
- var (
- err error
- res []searchModel.Dark
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- res, _, err = s.DarkwordFromDB(time.Now().Format("2006-01-02"))
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldNotBeNil)
- })
- fmt.Println(res)
- })
- })
- }
- func TestOpenHotList(t *testing.T) {
- convey.Convey("HotwordFromDB", t, func(ctx convey.C) {
- var (
- err error
- res []searchModel.Intervene
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- //c = context.Background()
- //res, err = s.OpenHotList(c)
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldNotBeNil)
- })
- fmt.Println(res)
- })
- })
- }
- func TestHotList(t *testing.T) {
- convey.Convey("HotList", t, func(ctx convey.C) {
- var (
- err error
- res []searchModel.Intervene
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- //res, err = s.HotList(c)
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldNotBeNil)
- })
- fmt.Println(res)
- })
- })
- }
- func TestDarkList(t *testing.T) {
- convey.Convey("DarkList", t, func(ctx convey.C) {
- var (
- err error
- res []searchModel.Intervene
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- //res, err = s.DarkList(c)
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldNotBeNil)
- })
- fmt.Println(res)
- })
- })
- }
- func TestBlackList(t *testing.T) {
- convey.Convey("BlackList", t, func(ctx convey.C) {
- var (
- err error
- res []searchModel.Black
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- res, err = s.BlackList()
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldNotBeNil)
- })
- fmt.Println(res)
- })
- })
- }
- func TestDelBlack(t *testing.T) {
- convey.Convey("DelBlack", t, func(ctx convey.C) {
- var (
- err error
- res []searchModel.Black
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- //res, err = s.DelBlack()
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldNotBeNil)
- })
- fmt.Println(res)
- })
- })
- }
- func TestAddBlack(t *testing.T) {
- convey.Convey("AddBlack", t, func(ctx convey.C) {
- var (
- err error
- res []searchModel.Black
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- //err = s.AddBlack()
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldNotBeNil)
- })
- fmt.Println(res)
- })
- })
- }
- func TestCheckBlack(t *testing.T) {
- convey.Convey("checkBlack", t, func(ctx convey.C) {
- var (
- err error
- res bool
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- res, err = s.checkBlack("test")
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldNotBeNil)
- })
- fmt.Println(res)
- })
- })
- }
- func TestCheckInter(t *testing.T) {
- convey.Convey("checkInter", t, func(ctx convey.C) {
- var (
- err error
- res bool
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- res, err = s.checkInter("test", 0)
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldNotBeNil)
- })
- fmt.Println(res)
- })
- })
- }
- func TestCheckTimeConflict(t *testing.T) {
- convey.Convey("checkTimeConflict", t, func(ctx convey.C) {
- var (
- err error
- res bool
- model = searchModel.InterveneAdd{
- Rank: 10,
- Stime: 1536134791,
- Etime: 1536134791,
- }
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- res, err = s.checkTimeConflict(model, 0)
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldNotBeNil)
- })
- fmt.Println(res)
- })
- })
- }
- func TestAddInter(t *testing.T) {
- convey.Convey("checkTimeConflict", t, func(ctx convey.C) {
- var (
- err error
- res bool
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- //res, err = s.AddInter(model, 0)
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldNotBeNil)
- })
- fmt.Println(res)
- })
- })
- }
- func TestUpdateInter(t *testing.T) {
- convey.Convey("UpdateInter", t, func(ctx convey.C) {
- var (
- err error
- res bool
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- //res, err = s.AddInter(model, 0)
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldNotBeNil)
- })
- fmt.Println(res)
- })
- })
- }
- func TestUpdateSearch(t *testing.T) {
- convey.Convey("UpdateSearch", t, func(ctx convey.C) {
- var (
- err error
- res bool
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- //res, err = s.AddInter(model, 0)
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldNotBeNil)
- })
- fmt.Println(res)
- })
- })
- }
- func TestDeleteHot(t *testing.T) {
- convey.Convey("DeleteHot", t, func(ctx convey.C) {
- var (
- err error
- res bool
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- err = s.DeleteHot(c, 10, 2, "quguolin", 100)
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldNotBeNil)
- })
- fmt.Println(res)
- })
- })
- }
- func TestDeleteDark(t *testing.T) {
- convey.Convey("DeleteDark", t, func(ctx convey.C) {
- var (
- err error
- res bool
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- err = s.DeleteDark(c, 10, "quguolin", 100)
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldNotBeNil)
- })
- fmt.Println(res)
- })
- })
- }
- func TestOpenAddDarkword(t *testing.T) {
- convey.Convey("OpenAddDarkword", t, func(ctx convey.C) {
- var (
- err error
- res bool
- value searchModel.OpenDark
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- err = s.OpenAddDarkword(c, value)
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldNotBeNil)
- })
- fmt.Println(res)
- })
- })
- }
- func TestOpenAddHotword(t *testing.T) {
- convey.Convey("OpenAddHotword", t, func(ctx convey.C) {
- var (
- err error
- res bool
- //value searchModel.OpenHot
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- //err = s.OpenAddHotword(c, value)
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldNotBeNil)
- })
- fmt.Println(res)
- })
- })
- }
- func TestGetHotPub(t *testing.T) {
- convey.Convey("GetHotPub", t, func(ctx convey.C) {
- var (
- err error
- res bool
- //value searchModel.OpenHot
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- //err = s.OpenAddHotword(c, value)
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldNotBeNil)
- })
- fmt.Println(res)
- })
- })
- }
- func TestGetDarkPub(t *testing.T) {
- convey.Convey("GetDarkPub", t, func(ctx convey.C) {
- var (
- err error
- res bool
- //value searchModel.OpenHot
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- //err = s.GetDarkPub(c, value)
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldNotBeNil)
- })
- fmt.Println(res)
- })
- })
- }
- func TestSetHotPub(t *testing.T) {
- convey.Convey("SetHotPub", t, func(ctx convey.C) {
- var (
- err error
- res bool
- //value searchModel.OpenHot
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- err = s.SetHotPub(c, "quguolin", 100)
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldNotBeNil)
- })
- fmt.Println(res)
- })
- })
- }
- func TestHotPubLog(t *testing.T) {
- convey.Convey("HotPubLog", t, func(ctx convey.C) {
- var (
- err error
- res bool
- value []searchModel.Intervene
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- err = s.HotPubLog(value)
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldNotBeNil)
- })
- fmt.Println(res)
- })
- })
- }
- func TestGetHotPubLog(t *testing.T) {
- convey.Convey("GetHotPubLog", t, func(ctx convey.C) {
- var (
- err error
- res []searchModel.Intervene
- pub bool
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- res, pub, err = s.GetHotPubLog("2018-09-03")
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- //ctx.So(res, convey.ShouldNotBeNil)
- })
- fmt.Println(res, pub)
- })
- })
- }
- func TestGetDarkPubLog(t *testing.T) {
- convey.Convey("GetDarkPubLog", t, func(ctx convey.C) {
- var (
- err error
- res []searchModel.Dark
- pub bool
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- res, pub, err = s.GetDarkPubLog("2018-09-03")
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- //ctx.So(res, convey.ShouldNotBeNil)
- })
- fmt.Println(res, pub)
- })
- })
- }
- func TestSetDarkPub(t *testing.T) {
- convey.Convey("SetDarkPub", t, func(ctx convey.C) {
- var (
- err error
- res []searchModel.Intervene
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- s.SetDarkPub(c, "quguolin", 10)
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- //ctx.So(res, convey.ShouldNotBeNil)
- })
- fmt.Println(res)
- })
- })
- }
- func TestDarkPubLog(t *testing.T) {
- convey.Convey("DarkPubLog", t, func(ctx convey.C) {
- var (
- err error
- dark []searchModel.Dark
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- s.DarkPubLog(dark)
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- //ctx.So(res, convey.ShouldNotBeNil)
- })
- })
- })
- }
|