123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- package income
- import (
- "context"
- "testing"
- "github.com/smartystreets/goconvey/convey"
- )
- func TestIncomeUpIncomeCount(t *testing.T) {
- convey.Convey("UpIncomeCount", t, func(ctx convey.C) {
- var (
- c = context.Background()
- table = "up_income"
- query = "id > 0"
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- Exec(c, "INSERT INTO up_income(mid, income, date) VALUS(1993, 10, '2018-01-01')")
- count, err := d.UpIncomeCount(c, table, query)
- ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(count, convey.ShouldNotBeNil)
- })
- })
- })
- convey.Convey("UpIncomeCount table error", t, func(ctx convey.C) {
- var (
- c = context.Background()
- table = ""
- query = ""
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- _, err := d.UpIncomeCount(c, table, query)
- ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestIncomeGetUpIncome(t *testing.T) {
- convey.Convey("GetUpIncome", t, func(ctx convey.C) {
- var (
- c = context.Background()
- table = "up_income"
- incomeType = "av_income"
- query = "is_deleted = 0"
- id = int64(0)
- limit = int(10)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- upIncome, err := d.GetUpIncome(c, table, incomeType, query, id, limit)
- ctx.Convey("Then err should be nil.upIncome should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(upIncome, convey.ShouldNotBeNil)
- })
- })
- })
- convey.Convey("GetUpIncome query == nil", t, func(ctx convey.C) {
- var (
- c = context.Background()
- table = "up_income"
- incomeType = "av_income"
- query = ""
- id = int64(0)
- limit = int(10)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- _, err := d.GetUpIncome(c, table, incomeType, query, id, limit)
- ctx.Convey("Then err should be nil.upIncome should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestIncomeGetUpIncomeBySort(t *testing.T) {
- convey.Convey("GetUpIncomeBySort", t, func(ctx convey.C) {
- var (
- c = context.Background()
- table = "up_income"
- typeField = "av_income,av_tax,av_base_income,av_total_income"
- sort = "id"
- query = "id > 0"
- from = int(0)
- limit = int(10)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- upIncome, err := d.GetUpIncomeBySort(c, table, typeField, sort, query, from, limit)
- ctx.Convey("Then err should be nil.upIncome should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(upIncome, convey.ShouldNotBeNil)
- })
- })
- })
- convey.Convey("GetUpIncomeBySort table == nil", t, func(ctx convey.C) {
- var (
- c = context.Background()
- table = ""
- typeField = "av_income"
- sort = "id"
- query = "id > 0"
- from = int(0)
- limit = int(10)
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- _, err := d.GetUpIncomeBySort(c, table, typeField, sort, query, from, limit)
- ctx.Convey("Then err should be nil.upIncome should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestIncomeGetUpDailyStatis(t *testing.T) {
- convey.Convey("GetUpDailyStatis", t, func(ctx convey.C) {
- var (
- c = context.Background()
- table = "up_income_daily_statis"
- fromTime = "2018-01-01"
- toTime = "2018-01-10"
- )
- ctx.Convey("When everything goes positive", func(ctx convey.C) {
- Exec(c, "INSERT INTO up_income_daily_statis(ups, cdate) VALUES(10, '2018-01-02')")
- s, err := d.GetUpDailyStatis(c, table, fromTime, toTime)
- ctx.Convey("Then err should be nil.s should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(s, convey.ShouldNotBeNil)
- })
- })
- })
- }
|