123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- package http
- import (
- "context"
- "fmt"
- . "github.com/smartystreets/goconvey/convey"
- "go-common/app/service/live/wallet/model"
- "go-common/library/ecode"
- "net/url"
- "strconv"
- "testing"
- )
- type GetRes struct {
- Code int `json:"code"`
- Resp *model.MelonseedWithMetalResp `json:"data"`
- }
- type StatusRes struct {
- Code int `json:"code"`
- Resp *model.QueryResp `json:"data"`
- }
- type GetAllRes struct {
- Code int `json:"code"`
- Resp *model.DetailWithMetalResp `json:"data"`
- }
- func queryGet(t *testing.T, uid int64, platform string) *GetRes {
- params := url.Values{}
- params.Set("uid", fmt.Sprintf("%d", uid))
- req, _ := client.NewRequest("GET", _getURL, "127.0.0.1", params)
- req.Header.Set("platform", platform)
- var res GetRes
- err := client.Do(context.TODO(), req, &res)
- if err != nil {
- t.Errorf("client.Do() error(%v)", err)
- t.FailNow()
- }
- return &res
- }
- func queryStatus(t *testing.T, uid int64, tid string) *StatusRes {
- params := url.Values{}
- params.Set("uid", fmt.Sprintf("%d", uid))
- params.Set("transaction_id", tid)
- req, _ := client.NewRequest("GET", _queryURL, "127.0.0.1", params)
- req.Header.Set("platform", "pc")
- var res StatusRes
- err := client.Do(context.TODO(), req, &res)
- if err != nil {
- t.Errorf("client.Do() error(%v)", err)
- t.FailNow()
- }
- return &res
- }
- func queryGetAll(t *testing.T, uid int64, platform string) *GetAllRes {
- params := url.Values{}
- params.Set("uid", fmt.Sprintf("%d", uid))
- req, _ := client.NewRequest("GET", _getAllURL, "127.0.0.1", params)
- req.Header.Set("platform", platform)
- var res GetAllRes
- err := client.Do(context.TODO(), req, &res)
- if err != nil {
- t.Errorf("client.Do() error(%v)", err)
- t.FailNow()
- }
- return &res
- }
- func getTestWallet(t *testing.T, uid int64, platform string) *model.MelonseedWithMetalResp {
- res := queryGet(t, uid, platform)
- if res.Code != 0 {
- t.Errorf("get wallet failed uid : %d, code :%d", uid, res.Code)
- t.FailNow()
- }
- return res.Resp
- }
- /*
- useless now
- func getTestWalletDetail(t *testing.T, uid int64, platform string) *model.DetailWithMetalResp {
- res := queryGetAll(t, uid, platform)
- if res.Code != 0 {
- t.Errorf("get wallet failed uid : %d, code :%d", uid, res.Code)
- t.FailNow()
- }
- return res.Resp
- }*/
- func TestGet(t *testing.T) {
- once.Do(startHTTP)
- Convey("get normal", t, func() {
- res := queryGet(t, 1, "pc")
- So(res.Code, ShouldEqual, 0)
- melon := res.Resp
- coin, err := strconv.Atoi(melon.Gold)
- So(err, ShouldBeNil)
- So(coin, ShouldBeGreaterThan, -1)
- coin, err = strconv.Atoi(melon.Silver)
- So(err, ShouldBeNil)
- So(coin, ShouldBeGreaterThan, -1)
- })
- Convey("uid params error", t, func() {
- res := queryGet(t, -1, "pc")
- So(res.Code, ShouldEqual, ecode.RequestErr)
- })
- Convey("platform params error", t, func() {
- res := queryGet(t, 1, "pc1")
- So(res.Code, ShouldEqual, ecode.RequestErr)
- })
- }
- func TestGetAll(t *testing.T) {
- once.Do(startHTTP)
- Convey("normal", t, func() {
- res := queryGetAll(t, 1, "pc")
- t.Logf("all:%v", res)
- So(res.Code, ShouldEqual, 0)
- melon := res.Resp
- coin, err := strconv.Atoi(melon.Gold)
- So(err, ShouldBeNil)
- So(coin, ShouldBeGreaterThan, -1)
- coin, err = strconv.Atoi(melon.Silver)
- So(err, ShouldBeNil)
- So(coin, ShouldBeGreaterThan, -1)
- coin, err = strconv.Atoi(melon.SilverPayCnt)
- So(err, ShouldBeNil)
- So(coin, ShouldBeGreaterThan, -1)
- coin, err = strconv.Atoi(melon.GoldPayCnt)
- So(err, ShouldBeNil)
- So(coin, ShouldBeGreaterThan, -1)
- coin, err = strconv.Atoi(melon.GoldRechargeCnt)
- So(err, ShouldBeNil)
- So(coin, ShouldBeGreaterThan, -1)
- So(melon.CostBase, ShouldBeGreaterThanOrEqualTo, 0)
- })
- }
|