123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- package dao
- import (
- "context"
- "database/sql"
- "database/sql/driver"
- "fmt"
- "reflect"
- "testing"
- "go-common/app/service/main/passport-sns/model"
- xsql "go-common/library/database/sql"
- "github.com/bouk/monkey"
- "github.com/smartystreets/goconvey/convey"
- )
- func TestDao_SnsApps(t *testing.T) {
- convey.Convey("SnsApps", t, func(ctx convey.C) {
- var (
- c = context.Background()
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- res, err := d.SnsApps(c)
- ctx.Convey("Then err should be nil.res should not nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDao_SnsUsers(t *testing.T) {
- convey.Convey("SnsUsers", t, func(ctx convey.C) {
- var (
- c = context.Background()
- mid = int64(0)
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- res, err := d.SnsUsers(c, mid)
- ctx.Convey("Then err should be nil.res should not nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDao_SnsTokens(t *testing.T) {
- convey.Convey("SnsTokens", t, func(ctx convey.C) {
- var (
- c = context.Background()
- mid = int64(0)
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- res, err := d.SnsTokens(c, mid)
- ctx.Convey("Then err should be nil.res should not nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDao_SnsUserByMid(t *testing.T) {
- convey.Convey("SnsUserByMid", t, func(ctx convey.C) {
- var (
- c = context.Background()
- mid = int64(0)
- platform = model.PlatformQQ
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- res, err := d.SnsUserByMid(c, mid, platform)
- ctx.Convey("Then err should be nil.res should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDao_SnsUserByUnionID(t *testing.T) {
- convey.Convey("SnsUserByUnionID", t, func(ctx convey.C) {
- var (
- c = context.Background()
- unionID = ""
- platform = model.PlatformQQ
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- res, err := d.SnsUserByUnionID(c, unionID, platform)
- ctx.Convey("Then err should be nil.res should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(res, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDao_TxAddSnsUser(t *testing.T) {
- convey.Convey("TxAddSnsUser", t, func(ctx convey.C) {
- var (
- tx, _ = d.BeginTran(context.Background())
- a = &model.SnsUser{}
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- mock := monkey.PatchInstanceMethod(reflect.TypeOf(tx), "Exec", func(_ *xsql.Tx, _ string, _ ...interface{}) (res sql.Result, err error) {
- return driver.RowsAffected(1), nil
- })
- defer mock.Unpatch()
- affected, err := d.TxAddSnsUser(tx, a)
- ctx.Convey("Then err should be nil.affected should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(affected, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDao_TxAddSnsOpenID(t *testing.T) {
- convey.Convey("TxAddSnsOpenID", t, func(ctx convey.C) {
- var (
- tx, _ = d.BeginTran(context.Background())
- a = &model.SnsOpenID{}
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- mock := monkey.PatchInstanceMethod(reflect.TypeOf(tx), "Exec", func(_ *xsql.Tx, _ string, _ ...interface{}) (res sql.Result, err error) {
- return driver.RowsAffected(1), nil
- })
- defer mock.Unpatch()
- affected, err := d.TxAddSnsOpenID(tx, a)
- ctx.Convey("Then err should be nil.affected should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(affected, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDao_TxAddSnsToken(t *testing.T) {
- convey.Convey("TxAddSnsToken", t, func(ctx convey.C) {
- var (
- tx, _ = d.BeginTran(context.Background())
- a = &model.SnsToken{}
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- mock := monkey.PatchInstanceMethod(reflect.TypeOf(tx), "Exec", func(_ *xsql.Tx, _ string, _ ...interface{}) (res sql.Result, err error) {
- return driver.RowsAffected(1), nil
- })
- defer mock.Unpatch()
- affected, err := d.TxAddSnsToken(tx, a)
- ctx.Convey("Then err should be nil.affected should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(affected, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDao_TxUpdateSnsUser(t *testing.T) {
- convey.Convey("TxUpdateSnsUser", t, func(ctx convey.C) {
- var (
- tx, _ = d.BeginTran(context.Background())
- a = &model.SnsUser{}
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- mock := monkey.PatchInstanceMethod(reflect.TypeOf(tx), "Exec", func(_ *xsql.Tx, _ string, _ ...interface{}) (res sql.Result, err error) {
- return driver.RowsAffected(1), nil
- })
- defer mock.Unpatch()
- affected, err := d.TxUpdateSnsUser(tx, a)
- ctx.Convey("Then err should be nil.affected should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(affected, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDao_TxUpdateSnsToken(t *testing.T) {
- convey.Convey("TxUpdateSnsToken", t, func(ctx convey.C) {
- var (
- tx, _ = d.BeginTran(context.Background())
- a = &model.SnsToken{}
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- mock := monkey.PatchInstanceMethod(reflect.TypeOf(tx), "Exec", func(_ *xsql.Tx, _ string, _ ...interface{}) (res sql.Result, err error) {
- return driver.RowsAffected(1), nil
- })
- defer mock.Unpatch()
- affected, err := d.TxUpdateSnsToken(tx, a)
- ctx.Convey("Then err should be nil.affected should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(affected, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDao_DelSnsUser(t *testing.T) {
- convey.Convey("DelSnsUser", t, func(ctx convey.C) {
- var (
- c = context.Background()
- mid = int64(0)
- platform = model.PlatformQQ
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- mock := monkey.PatchInstanceMethod(reflect.TypeOf(d.db), "Exec", func(_ *xsql.DB, _ context.Context, _ string, _ ...interface{}) (res sql.Result, err error) {
- return driver.RowsAffected(1), nil
- })
- defer mock.Unpatch()
- affected, err := d.DelSnsUser(c, mid, platform)
- ctx.Convey("Then err should be nil.affected should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(affected, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDao_DelAllSnsUser(t *testing.T) {
- convey.Convey("DelAllSnsUser", t, func(ctx convey.C) {
- var (
- c = context.Background()
- mid = int64(0)
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- mock := monkey.PatchInstanceMethod(reflect.TypeOf(d.db), "Exec", func(_ *xsql.DB, _ context.Context, _ string, _ ...interface{}) (res sql.Result, err error) {
- return driver.RowsAffected(1), nil
- })
- defer mock.Unpatch()
- affected, err := d.DelSnsUsers(c, mid)
- ctx.Convey("Then err should be nil.affected should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(affected, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDao_openIDSuffix(t *testing.T) {
- convey.Convey("openIDSuffix", t, func(ctx convey.C) {
- res := openIDSuffix("test")
- fmt.Println(res)
- ctx.Convey("Then res should not be nil.", func(ctx convey.C) {
- ctx.So(res, convey.ShouldNotBeNil)
- })
- })
- }
|