123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534 |
- package dao
- import (
- "context"
- "fmt"
- "testing"
- "time"
- "github.com/smartystreets/goconvey/convey"
- )
- var awardID = time.Now().Unix()
- func TestDaoAddAward(t *testing.T) {
- convey.Convey("AddAward", t, func(ctx convey.C) {
- var (
- tx, _ = d.BeginTran(context.TODO())
- awardName = string(time.Now().Unix())
- cycleStart = time.Now().Format("2006-01-02 15:04:05")
- cycleEnd = time.Now().Format("2006-01-02 15:04:05")
- announceDate = time.Now().Format("2006-01-02")
- openTime = time.Now().Format("2006-01-02 15:04:00")
- displayStatus = int(1)
- totalWinner = int(0)
- totalBonus = int(0)
- createdBy = "test"
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- defer tx.Commit()
- p1, err := AddAward(tx, awardID, awardName, cycleStart, cycleEnd, announceDate, openTime, displayStatus, totalWinner, totalBonus, createdBy)
- 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 TestDaoAward(t *testing.T) {
- convey.Convey("Award", t, func(ctx convey.C) {
- var (
- c = context.Background()
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- data, err := d.Award(c, awardID)
- ctx.Convey("Then err should be nil.data should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(data, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoSelectAwardForUpdate(t *testing.T) {
- convey.Convey("SelectAwardForUpdate", t, func(ctx convey.C) {
- var (
- tx, _ = d.BeginTran(context.TODO())
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- defer tx.Commit()
- award, err := SelectAwardForUpdate(tx, awardID)
- ctx.Convey("Then err should be nil.award should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(award, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoUpdateAward(t *testing.T) {
- convey.Convey("UpdateAward", t, func(ctx convey.C) {
- var (
- tx, _ = d.BeginTran(context.TODO())
- values = ""
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- defer tx.Commit()
- p1, err := UpdateAward(tx, awardID, values)
- 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 TestDaoTxAward(t *testing.T) {
- convey.Convey("Award", t, func(ctx convey.C) {
- var (
- tx, _ = d.BeginTran(context.TODO())
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- defer tx.Commit()
- data, err := Award(tx, awardID)
- ctx.Convey("Then err should be nil.data should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(data, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoListAwardsDivision(t *testing.T) {
- convey.Convey("ListAwardsDivision", t, func(ctx convey.C) {
- var (
- tx, _ = d.BeginTran(context.TODO())
- where = fmt.Sprintf("award_id=%d", awardID)
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- defer tx.Commit()
- res, err := ListAwardsDivision(tx, where)
- 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 TestDaoListDivision(t *testing.T) {
- convey.Convey("ListDivision", t, func(ctx convey.C) {
- var (
- tx, _ = d.BeginTran(context.TODO())
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- defer tx.Commit()
- res, err := ListDivision(tx, awardID)
- 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 TestDaoTxDivisionInfo(t *testing.T) {
- convey.Convey("DivisionInfo", t, func(ctx convey.C) {
- var (
- tx, _ = d.BeginTran(context.TODO())
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- defer tx.Commit()
- res, err := DivisionInfo(tx, awardID)
- 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 TestDaoDivisionInfo(t *testing.T) {
- convey.Convey("DivisionInfo", t, func(ctx convey.C) {
- var (
- c = context.Background()
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- res, err := d.AwardDivisionInfo(c, awardID)
- 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 TestDaoListPrize(t *testing.T) {
- convey.Convey("ListPrize", t, func(ctx convey.C) {
- var (
- tx, _ = d.BeginTran(context.TODO())
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- defer tx.Commit()
- res, err := ListPrize(tx, awardID)
- 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 TestDaoListResource(t *testing.T) {
- convey.Convey("ListResource", t, func(ctx convey.C) {
- var (
- tx, _ = d.BeginTran(context.TODO())
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- defer tx.Commit()
- res, err := ListResource(tx, awardID)
- 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 TestDaoPrizeInfo(t *testing.T) {
- convey.Convey("PrizeInfo", t, func(ctx convey.C) {
- var (
- tx, _ = d.BeginTran(context.TODO())
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- defer tx.Commit()
- res, err := PrizeInfo(tx, awardID)
- 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 TestDaoCountAward(t *testing.T) {
- convey.Convey("CountAward", t, func(ctx convey.C) {
- var (
- tx, _ = d.BeginTran(context.TODO())
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- defer tx.Commit()
- total, err := CountAward(tx)
- ctx.Convey("Then err should be nil.total should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(total, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoCountAwardWinner(t *testing.T) {
- convey.Convey("CountAwardWinner", t, func(ctx convey.C) {
- var (
- tx, _ = d.BeginTran(context.TODO())
- where = ""
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- defer tx.Commit()
- total, err := CountAwardWinner(tx, awardID, where)
- ctx.Convey("Then err should be nil.total should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(total, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoGroupCountAwardWinner(t *testing.T) {
- convey.Convey("GroupCountAwardWinner", t, func(ctx convey.C) {
- var (
- tx, _ = d.BeginTran(context.TODO())
- where = fmt.Sprintf("award_id=%d", awardID)
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- defer tx.Commit()
- res, err := GroupCountAwardWinner(tx, where)
- 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 TestDaoAwardWinnerAll(t *testing.T) {
- convey.Convey("AwardWinnerAll", t, func(ctx convey.C) {
- var (
- tx, _ = d.BeginTran(context.TODO())
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- defer tx.Commit()
- res, err := AwardWinnerAll(tx, awardID)
- 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 TestDaoListAwardRecord(t *testing.T) {
- convey.Convey("ListAwardRecord", t, func(ctx convey.C) {
- var (
- c = context.Background()
- where = ""
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- res, err := d.ListAwardRecord(c, awardID, where)
- 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 TestDaoQueryAwardWinner(t *testing.T) {
- convey.Convey("QueryAwardWinner", t, func(ctx convey.C) {
- var (
- tx, _ = d.BeginTran(context.TODO())
- where = ""
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- defer tx.Commit()
- res, err := QueryAwardWinner(tx, awardID, where)
- 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 TestDaoListAward(t *testing.T) {
- convey.Convey("ListAward", t, func(ctx convey.C) {
- var (
- c = context.Background()
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- res, err := d.ListAward(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 TestDaoTxListAward(t *testing.T) {
- convey.Convey("ListAward", t, func(ctx convey.C) {
- var (
- tx, _ = d.BeginTran(context.TODO())
- from = int(1)
- limit = int(20)
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- defer tx.Commit()
- res, err := ListAward(tx, from, limit)
- 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 TestDaoDelDivisionAll(t *testing.T) {
- convey.Convey("DelDivisionAll", t, func(ctx convey.C) {
- var (
- tx, _ = d.BeginTran(context.TODO())
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- defer tx.Commit()
- p1, err := DelDivisionAll(tx, awardID)
- 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 TestDaoDelWinner(t *testing.T) {
- convey.Convey("DelWinner", t, func(ctx convey.C) {
- var (
- tx, _ = d.BeginTran(context.TODO())
- where = ""
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- defer tx.Commit()
- rows, err := DelWinner(tx, awardID, where)
- ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(rows, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoDelWinnerAll(t *testing.T) {
- convey.Convey("DelWinnerAll", t, func(ctx convey.C) {
- var (
- tx, _ = d.BeginTran(context.TODO())
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- defer tx.Commit()
- p1, err := DelWinnerAll(tx, awardID)
- 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 TestDaoDelDivisionsExclude(t *testing.T) {
- convey.Convey("DelDivisionsExclude", t, func(ctx convey.C) {
- var (
- tx, _ = d.BeginTran(context.TODO())
- divisionIDs = []int64{1, 2}
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- defer tx.Commit()
- p1, err := DelDivisionsExclude(tx, awardID, divisionIDs)
- 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 TestDaoDelPrizeAll(t *testing.T) {
- convey.Convey("DelPrizeAll", t, func(ctx convey.C) {
- var (
- tx, _ = d.BeginTran(context.TODO())
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- defer tx.Commit()
- p1, err := DelPrizeAll(tx, awardID)
- 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 TestDaoDelPrizesExclude(t *testing.T) {
- convey.Convey("DelPrizesExclude", t, func(ctx convey.C) {
- var (
- tx, _ = d.BeginTran(context.TODO())
- prizeIDs = []int64{1, 2}
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- defer tx.Commit()
- p1, err := DelPrizesExclude(tx, awardID, prizeIDs)
- 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 TestDaoDelResources(t *testing.T) {
- convey.Convey("DelResources", t, func(ctx convey.C) {
- var (
- tx, _ = d.BeginTran(context.TODO())
- where = fmt.Sprintf("award_id=%d", awardID)
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- defer tx.Commit()
- p1, err := DelResources(tx, where)
- 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 TestDaoSaveWinners(t *testing.T) {
- convey.Convey("SaveWinners", t, func(ctx convey.C) {
- var (
- tx, _ = d.BeginTran(context.TODO())
- fields = "award_id,mid,division_id,prize_id,tag_id"
- values = fmt.Sprintf("(%d,1,1,1,1)", awardID)
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- defer tx.Commit()
- rows, err := SaveWinners(tx, fields, values)
- ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(rows, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoSaveDivisions(t *testing.T) {
- convey.Convey("SaveDivisions", t, func(ctx convey.C) {
- var (
- tx, _ = d.BeginTran(context.TODO())
- fields = "award_id,division_id,division_name,tag_id"
- values = fmt.Sprintf("(%d,1,'test-division-name',1)", awardID)
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- defer tx.Commit()
- rows, err := SaveDivisions(tx, fields, values)
- ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(rows, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoSaveResource(t *testing.T) {
- convey.Convey("SaveResource", t, func(ctx convey.C) {
- var (
- tx, _ = d.BeginTran(context.TODO())
- fields = "award_id,resource_type,resource_index,content"
- values = fmt.Sprintf("(%d,1,1,'test-content')", awardID)
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- defer tx.Commit()
- rows, err := SaveResource(tx, fields, values)
- ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(rows, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDaoSavePrizes(t *testing.T) {
- convey.Convey("SavePrizes", t, func(ctx convey.C) {
- var (
- tx, _ = d.BeginTran(context.TODO())
- fields = "award_id,prize_id,bonus,quota"
- values = fmt.Sprintf("(%d,1,100,100)", awardID)
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- defer tx.Commit()
- rows, err := SavePrizes(tx, fields, values)
- ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(rows, convey.ShouldNotBeNil)
- })
- })
- })
- }
|