123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498 |
- package dao
- import (
- "context"
- "fmt"
- "testing"
- "time"
- "go-common/app/service/main/spy/model"
- xtime "go-common/library/time"
- "github.com/smartystreets/goconvey/convey"
- )
- func TestDaoService(t *testing.T) {
- convey.Convey("Service", t, func(ctx convey.C) {
- var (
- c = context.Background()
- serviceName = "account-service"
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- service, err := d.Service(c, serviceName)
- ctx.Convey("Then err should be nil.service should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(service, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoEvent(t *testing.T) {
- convey.Convey("Event", t, func(ctx convey.C) {
- var (
- c = context.Background()
- eventName = "init_user_info"
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- _, err := d.Event(c, eventName)
- ctx.Convey("Then err should be nil.event should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoAddService(t *testing.T) {
- convey.Convey("AddService", t, func(ctx convey.C) {
- var (
- c = context.Background()
- service = &model.Service{
- Name: fmt.Sprintf("ut_%d", time.Now().Unix()),
- NickName: "test",
- Status: 0,
- CTime: xtime.Time(time.Now().Unix()),
- MTime: xtime.Time(time.Now().Unix()),
- }
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- id, err := d.AddService(c, service)
- ctx.Convey("Then err should be nil.id should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(id, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoAddEvent(t *testing.T) {
- convey.Convey("AddEvent", t, func(ctx convey.C) {
- var (
- c = context.Background()
- event = &model.Event{
- Name: fmt.Sprintf("ut_%d", time.Now().Unix()),
- NickName: "test",
- Status: 1,
- CTime: xtime.Time(time.Now().Unix()),
- MTime: xtime.Time(time.Now().Unix()),
- }
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- id, err := d.AddEvent(c, event)
- ctx.Convey("Then err should be nil.id should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(id, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoFactor(t *testing.T) {
- convey.Convey("Factor", t, func(ctx convey.C) {
- var (
- c = context.Background()
- serviceID = int64(1)
- eventID = int64(1)
- riskLevel = int8(1)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- factor, err := d.Factor(c, serviceID, eventID, riskLevel)
- ctx.Convey("Then err should be nil.factor should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(factor, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoFactorGroup(t *testing.T) {
- convey.Convey("FactorGroup", t, func(ctx convey.C) {
- var (
- c = context.Background()
- groupName = "基础资料分值"
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- _, err := d.FactorGroup(c, groupName)
- ctx.Convey("Then err should be nil.factorGroup should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaohitInfo(t *testing.T) {
- convey.Convey("hitInfo", t, func(ctx convey.C) {
- var (
- id = int64(0)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- p1 := hitInfo(id)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaohitHistory(t *testing.T) {
- convey.Convey("hitHistory", t, func(ctx convey.C) {
- var (
- id = int64(0)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- p1 := hitHistory(id)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoBeginTran(t *testing.T) {
- convey.Convey("BeginTran", t, func(ctx convey.C) {
- var (
- c = context.Background()
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- p1, err := d.BeginTran(c)
- ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoUserInfo(t *testing.T) {
- convey.Convey("UserInfo", t, func(ctx convey.C) {
- var (
- c = context.Background()
- mid = int64(1)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- res, err := d.UserInfo(c, mid)
- 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 TestDaoTxUpdateInfo(t *testing.T) {
- convey.Convey("TxUpdateInfo", t, func(ctx convey.C) {
- var (
- c = context.Background()
- info = &model.UserInfo{
- Mid: 1,
- }
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- tx, err := d.BeginTran(c)
- ctx.So(err, convey.ShouldBeNil)
- err = d.TxUpdateInfo(c, tx, info)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoTxAddInfo(t *testing.T) {
- convey.Convey("TxAddInfo", t, func(ctx convey.C) {
- var (
- c = context.Background()
- info = &model.UserInfo{
- Mid: time.Now().Unix(),
- }
- id int64
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- tx, err := d.BeginTran(c)
- ctx.So(err, convey.ShouldBeNil)
- id, err = d.TxAddInfo(c, tx, info)
- ctx.Convey("Then err should be nil.id should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(id, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoTxAddEventHistory(t *testing.T) {
- convey.Convey("TxAddEventHistory", t, func(ctx convey.C) {
- var (
- c = context.Background()
- ueh = &model.UserEventHistory{
- Mid: 1,
- Remark: "un_test",
- }
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- tx, err := d.BeginTran(c)
- ctx.So(err, convey.ShouldBeNil)
- err = d.TxAddEventHistory(c, tx, ueh)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoTxAddPunishment(t *testing.T) {
- convey.Convey("TxAddPunishment", t, func(ctx convey.C) {
- var (
- c = context.Background()
- mid = int64(1)
- no = int8(0)
- reason = "unit test"
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- tx, err := d.BeginTran(c)
- ctx.So(err, convey.ShouldBeNil)
- err = d.TxAddPunishment(c, tx, mid, no, reason)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoTxAddPunishmentQueue(t *testing.T) {
- convey.Convey("TxAddPunishmentQueue", t, func(ctx convey.C) {
- var (
- c = context.Background()
- mid = int64(1)
- blockNo = int64(1)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- tx, err := d.BeginTran(c)
- ctx.So(err, convey.ShouldBeNil)
- err = d.TxAddPunishmentQueue(c, tx, mid, blockNo)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoAddPunishmentQueue(t *testing.T) {
- convey.Convey("AddPunishmentQueue", t, func(ctx convey.C) {
- var (
- c = context.Background()
- mid = int64(1)
- blockNo = int64(0)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- err := d.AddPunishmentQueue(c, mid, blockNo)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoTxUpdateEventScore(t *testing.T) {
- convey.Convey("TxUpdateEventScore", t, func(ctx convey.C) {
- var (
- c = context.Background()
- mid = int64(0)
- escore = int8(0)
- score = int8(0)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- tx, err := d.BeginTran(c)
- ctx.So(err, convey.ShouldBeNil)
- err = d.TxUpdateEventScore(c, tx, mid, escore, score)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoTxUpdateBaseScore(t *testing.T) {
- convey.Convey("TxUpdateBaseScore", t, func(ctx convey.C) {
- var (
- c = context.Background()
- ui = &model.UserInfo{Mid: 1}
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- tx, err := d.BeginTran(c)
- ctx.So(err, convey.ShouldBeNil)
- err = d.TxUpdateBaseScore(c, tx, ui)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoTxClearReliveTimes(t *testing.T) {
- convey.Convey("TxClearReliveTimes", t, func(ctx convey.C) {
- var (
- c = context.Background()
- ui = &model.UserInfo{Mid: 1}
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- tx, err := d.BeginTran(c)
- ctx.So(err, convey.ShouldBeNil)
- err = d.TxClearReliveTimes(c, tx, ui)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoConfigs(t *testing.T) {
- convey.Convey("Configs", t, func(ctx convey.C) {
- var (
- c = context.Background()
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- res, err := d.Configs(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 TestDaoHistoryList(t *testing.T) {
- convey.Convey("HistoryList", t, func(ctx convey.C) {
- var (
- c = context.Background()
- mid = int64(1)
- size = int(10)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- res, err := d.HistoryList(c, mid, size)
- 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 TestDaoTxUpdateEventScoreReLive(t *testing.T) {
- convey.Convey("TxUpdateEventScoreReLive", t, func(ctx convey.C) {
- var (
- c = context.Background()
- mid = int64(1)
- escore = int8(0)
- score = int8(0)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- tx, err := d.BeginTran(c)
- ctx.So(err, convey.ShouldBeNil)
- err = d.TxUpdateEventScoreReLive(c, tx, mid, escore, score)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoStatListByMid(t *testing.T) {
- convey.Convey("StatListByMid", t, func(ctx convey.C) {
- var (
- c = context.Background()
- mid = int64(1)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- list, err := d.StatListByMid(c, mid)
- ctx.Convey("Then err should be nil.list should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(list, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoStatListByIDAndMid(t *testing.T) {
- convey.Convey("StatListByIDAndMid", t, func(ctx convey.C) {
- var (
- c = context.Background()
- mid = int64(1)
- id = int64(0)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- list, err := d.StatListByIDAndMid(c, mid, id)
- ctx.Convey("Then err should be nil.list should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(list, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoStatListByID(t *testing.T) {
- convey.Convey("StatListByID", t, func(ctx convey.C) {
- var (
- c = context.Background()
- id = int64(0)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- list, err := d.StatListByID(c, id)
- ctx.Convey("Then err should be nil.list should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(list, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoAllEvent(t *testing.T) {
- convey.Convey("AllEvent", t, func(ctx convey.C) {
- var (
- c = context.Background()
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- list, err := d.AllEvent(c)
- ctx.Convey("Then err should be nil.list should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(list, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoTelLevel(t *testing.T) {
- convey.Convey("TelLevel", t, func(ctx convey.C) {
- var (
- c = context.Background()
- mid = int64(1)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- _, err := d.TelLevel(c, mid)
- ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDaoAddTelLevelInfo(t *testing.T) {
- convey.Convey("AddTelLevelInfo", t, func(ctx convey.C) {
- var (
- c = context.Background()
- no = &model.TelRiskLevel{
- Mid: time.Now().Unix(),
- Level: 1,
- Origin: 1,
- Ctime: time.Now(),
- Mtime: time.Now(),
- }
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- id, err := d.AddTelLevelInfo(c, no)
- ctx.Convey("Then err should be nil.id should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(id, convey.ShouldNotBeNil)
- })
- })
- })
- }
|