123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- package dao
- import (
- "context"
- "testing"
- "github.com/smartystreets/goconvey/convey"
- "gopkg.in/h2non/gock.v1"
- )
- func TestDaoGetMidInfo(t *testing.T) {
- var (
- c = context.Background()
- qType = "1"
- qKey = "silg@yahoo.cn"
- )
- convey.Convey("GetMidInfo", t, func(ctx convey.C) {
- v, err := d.GetMidInfo(c, qType, qKey)
- ctx.Convey("Then err should be nil.v should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(v, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoGetUserInfo(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(1)
- )
- convey.Convey("GetUserInfo", t, func(ctx convey.C) {
- defer gock.OffAll()
- httpMock("GET", d.c.AccRecover.GetUserInfoURL).Reply(200).JSON(`{"code":0,"data":{"mid":21,"email":"raiden131@yahoo.cn","telphone":"","join_time":1245902140}}`)
- v, err := d.GetUserInfo(c, mid)
- ctx.Convey("Then err should be nil.v should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(v, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoUpdatePwd(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(1)
- )
- convey.Convey("UpdatePwd", t, func(ctx convey.C) {
- defer gock.OffAll()
- httpMock("POST", d.c.AccRecover.UpPwdURL).Reply(200).JSON(`{"code": 0, "data":{"pwd":"d4txsunbb1","userid":"minorin"}}`)
- user, err := d.UpdatePwd(c, mid, "账号找回服务")
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(user, convey.ShouldNotBeNil)
- })
- }
- func TestDaoCheckSafe(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(1)
- question = int8(0)
- answer = "1"
- )
- convey.Convey("CheckSafe", t, func(ctx convey.C) {
- check, err := d.CheckSafe(c, mid, question, answer)
- ctx.Convey("Then err should be nil.check should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(check, convey.ShouldNotBeNil)
- })
- })
- }
- //func httpMock(method, url string) *gock.Request {
- // r := gock.New(url)
- // r.Method = strings.ToUpper(method)
- // return r
- //}
- //func TestDaoGetUserType(t *testing.T) {
- // var (
- // c = context.Background()
- // mid = int64(2)
- // )
- // convey.Convey("When http request gets code != 0", t, func(ctx convey.C) {
- // defer gock.OffAll()
- // httpMock("GET", d.c.AccRecover.GameURL).Reply(0).JSON(`{"requestId":"0def8d70b7ef11e8a395fa163e01a2e9","ts":"1535440592","code":0,"items":[{"id":14,"name":"SDK测试2","lastLogin":"1500969010"}]}`)
- // games, err := d.GetUserType(c, mid)
- // ctx.So(err, convey.ShouldBeNil)
- // ctx.So(games, convey.ShouldNotBeNil)
- // })
- //}
- func TestDaoCheckReg(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(1)
- regTime = int64(1532441644)
- regType = int8(0)
- regAddr = "中国_上海"
- )
- convey.Convey("CheckReg", t, func(ctx convey.C) {
- v, err := d.CheckReg(c, mid, regTime, regType, regAddr)
- ctx.Convey("Then err should be nil.v should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(v, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoUpdateBatchPwd(t *testing.T) {
- var (
- c = context.Background()
- mids = "1,2"
- )
- convey.Convey("UpdateBatchPwd", t, func(ctx convey.C) {
- defer gock.OffAll()
- httpMock("POST", d.c.AccRecover.UpBatchPwdURL).Reply(200).JSON(`{"code":0,"data":{"6":{"pwd":"tgs52r1st9","userid":"腹黑君"},"7":{"pwd":"g20ahzrf7j","userid":"Tzwcard"}}}`)
- userMap, err := d.UpdateBatchPwd(c, mids, "账号找回服务")
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(userMap, convey.ShouldNotBeNil)
- })
- }
- func TestDaoCheckCard(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(1)
- cardType = int8(1)
- cardCode = "123"
- )
- convey.Convey("CheckCard", t, func(ctx convey.C) {
- ok, err := d.CheckCard(c, mid, cardType, cardCode)
- ctx.Convey("Then err should be nil.ok should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(ok, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoCheckPwds(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(1)
- pwds = "123"
- )
- convey.Convey("CheckPwds", t, func(ctx convey.C) {
- v, err := d.CheckPwds(c, mid, pwds)
- ctx.Convey("Then err should be nil.v should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(v, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoGetLoginIPs(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(2)
- limit = int64(10)
- )
- convey.Convey("GetLoginIPs", t, func(ctx convey.C) {
- ipInfo, err := d.GetLoginIPs(c, mid, limit)
- ctx.Convey("Then err should be nil.ipInfo should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(ipInfo, convey.ShouldNotBeNil)
- })
- })
- }
- func TestDaoGetAddrByIP(t *testing.T) {
- var (
- c = context.Background()
- mid = int64(111001254)
- limit = int64(10)
- )
- convey.Convey("GetAddrByIP", t, func(ctx convey.C) {
- addrs, err := d.GetAddrByIP(c, mid, limit)
- ctx.Convey("Then err should be nil.addrs should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(addrs, convey.ShouldNotBeNil)
- })
- })
- }
|