From 44c44ec4ac59ae3a79658650c86ba9d6d20b998d Mon Sep 17 00:00:00 2001 From: yufeiminds Date: Thu, 15 Nov 2018 15:39:00 +0800 Subject: [PATCH] add test cases for #20 --- services/ubill/describe_order_detail_info.go | 21 +- services/ubill/types_ubill_order_infos.go | 15 +- tests/set_2301_test.go | 332 +++++++++++++++++++ tests/setup_test.go | 3 + ucloud/version/version.go | 2 +- 5 files changed, 361 insertions(+), 12 deletions(-) create mode 100644 tests/set_2301_test.go diff --git a/services/ubill/describe_order_detail_info.go b/services/ubill/describe_order_detail_info.go index 3ccb8e81..8d3aa54d 100644 --- a/services/ubill/describe_order_detail_info.go +++ b/services/ubill/describe_order_detail_info.go @@ -10,38 +10,52 @@ type DescribeOrderDetailInfoRequest struct { //开始时间,UNIX time format BeginTime *int `required:"true"` + //结束时间,时间跨度不超过3个月 - EndTime *int `required:"true"` + EndTime *int `required:"true"` + Regions []string `required:"true"` + //产品类型,默认全部的产品类型 ResourceTypes []string `required:"false"` + //订单类型,默认全部订单类型 OrderTypes []string `required:"false"` + //付费类型,默认全部的计费方式 ChargeTypes []string + //订单状态,默认选中全部的可选参数 OrderStates []string `required:"false"` + //是否开过发票,默认选中全部的可选参数 Invoiceds []string `required:"false"` + //返回数据长度,默认25 Limit *int `required:"false"` + //数据偏移量,默认0 Offset *int `required:"false"` + //资源ID - ResourceIDs []string `required:"false"` + ResourceIds []string `required:"false"` + //交易单号,该字段存在时,可以不传BeginTime和EndTime TradeNos []string `required:"false"` + //true表示查询全部,默认全部,其他选项按照项目自查询 QueryAll *string `required:"false"` } +// DescribeOrderDetailInfoResponse is response schema for DescribeOrderDetailInfo action type DescribeOrderDetailInfoResponse struct { response.CommonBase //json格式的订单信息 - OrderInfo []OrderInfo `json:"order_info"` + OrderInfos []OrderInfo } +// NewDescribeOrderDetailInfoRequest will create request of DescribeOrderDetailInfo action. func (c *UBillClient) NewDescribeOrderDetailInfoRequest() *DescribeOrderDetailInfoRequest { req := &DescribeOrderDetailInfoRequest{} @@ -53,6 +67,7 @@ func (c *UBillClient) NewDescribeOrderDetailInfoRequest() *DescribeOrderDetailIn return req } +// DescribeOrderDetailInfo - 获取订单信息 func (c *UBillClient) DescribeOrderDetailInfo(req *DescribeOrderDetailInfoRequest) (*DescribeOrderDetailInfoResponse, error) { var err error var res DescribeOrderDetailInfoResponse diff --git a/services/ubill/types_ubill_order_infos.go b/services/ubill/types_ubill_order_infos.go index 4f623b07..78b49c7b 100644 --- a/services/ubill/types_ubill_order_infos.go +++ b/services/ubill/types_ubill_order_infos.go @@ -2,25 +2,24 @@ package ubill type OrderInfo struct { OrderNo string `json:"OrderNo"` - ReourceId string OrderType string ChargeType string ResourceId string - ResourceTag string + ResourceTag []ResourceTag OrderState string - CreateTime string + CreateTime int Amount string //订单总金额 AmountReal string //现金账户金额 AmountFree string //赠送账户金额(元) AmountCoupon string //优惠金额 CouponCode string //如果AmountCoupon不为0,显示代金券号码 ResourceType string - UpdateTime string - Quantity int64 //计费周期数 - Count int64 //资源数量 + UpdateTime int + Quantity string //计费周期数 + Count int //资源数量 Invoiced string //是否开过发票 - StartTime string //开始时间 - EndTime string //结束时间 + StartTime int //开始时间 + EndTime int //结束时间 OrderDetails []OrderDetail RegionId string //region TradeNo string //交易号 diff --git a/tests/set_2301_test.go b/tests/set_2301_test.go new file mode 100644 index 00000000..0f24854a --- /dev/null +++ b/tests/set_2301_test.go @@ -0,0 +1,332 @@ +package tests + +import ( + "testing" + "time" + + "github.com/ucloud/ucloud-sdk-go/internal/utest" +) + +func TestSet2301(t *testing.T) { + t.Parallel() + + ctx := utest.NewTestContext() + ctx.T = t + ctx.Vars = map[string]interface{}{} + + ctx.SetVar("Region", "cn-sh2") + ctx.SetVar("Zone", "cn-sh2-02") + + ctx.SetVar("begin_time", ctx.Must(utest.Calculate("-", ctx.Must(utest.GetTimestamp("10")), 86400*7))) + + testSet2301GetEIPPrice00(&ctx) + testSet2301AllocateEIP01(&ctx) + testSet2301DescribeOrderDetailInfo02(&ctx) + testSet2301GetEIPUpgradePrice03(&ctx) + testSet2301ModifyEIPBandwidth04(&ctx) + testSet2301DescribeOrderDetailInfo05(&ctx) + testSet2301GetEIPUpgradePrice06(&ctx) + testSet2301ModifyEIPBandwidth07(&ctx) + testSet2301DescribeOrderDetailInfo08(&ctx) + testSet2301ReleaseEIP09(&ctx) +} + +func testSet2301GetEIPPrice00(ctx *utest.TestContext) { + time.Sleep(time.Duration(0) * time.Second) + + req := unetClient.NewGetEIPPriceRequest() + + ctx.NoError(utest.SetReqValue(req, "Region", ctx.GetVar("Region"))) + + ctx.NoError(utest.SetReqValue(req, "OperatorName", "Bgp")) + ctx.NoError(utest.SetReqValue(req, "Bandwidth", "2")) + ctx.NoError(utest.SetReqValue(req, "ChargeType", "Month")) + + testCase := utest.TestCase{ + Invoker: func() (interface{}, error) { + return unetClient.GetEIPPrice(req) + }, + Validators: []utest.TestValidator{ + ctx.NewValidator("RetCode", "0", "str_eq"), + }, + MaxRetries: 3, + RetryInterval: 1 * time.Second, + T: ctx.T, + } + + resp, err := testCase.Run() + if resp == nil || err != nil { + ctx.T.Fatal(err) + } + + ctx.Vars["buy_price"] = ctx.Must(utest.GetValue(resp, "PriceSet.0.Price")) +} + +func testSet2301AllocateEIP01(ctx *utest.TestContext) { + time.Sleep(time.Duration(0) * time.Second) + + req := unetClient.NewAllocateEIPRequest() + + ctx.NoError(utest.SetReqValue(req, "Region", ctx.GetVar("Region"))) + ctx.NoError(utest.SetReqValue(req, "OperatorName", "Bgp")) + ctx.NoError(utest.SetReqValue(req, "Bandwidth", "2")) + + testCase := utest.TestCase{ + Invoker: func() (interface{}, error) { + return unetClient.AllocateEIP(req) + }, + Validators: []utest.TestValidator{ + ctx.NewValidator("RetCode", "0", "str_eq"), + }, + MaxRetries: 0, + RetryInterval: 0 * time.Second, + T: ctx.T, + } + + resp, err := testCase.Run() + if resp == nil || err != nil { + ctx.T.Fatal(err) + } + + ctx.Vars["eip_id"] = ctx.Must(utest.GetValue(resp, "EIPSet.0.EIPId")) +} + +func testSet2301DescribeOrderDetailInfo02(ctx *utest.TestContext) { + time.Sleep(time.Duration(5) * time.Second) + + req := ubillClient.NewDescribeOrderDetailInfoRequest() + + ctx.NoError(utest.SetReqValue(req, "BeginTime", ctx.GetVar("begin_time"))) + ctx.NoError(utest.SetReqValue(req, "EndTime", ctx.Must(utest.GetTimestamp("10")))) + + ctx.NoError(utest.SetReqValue(req, "ResourceTypes", "EIP")) + ctx.NoError(utest.SetReqValue(req, "OrderTypes", "OT_BUY")) + + ctx.NoError(utest.SetReqValue(req, "ResourceIds", ctx.GetVar("eip_id"))) + + testCase := utest.TestCase{ + Invoker: func() (interface{}, error) { + return ubillClient.DescribeOrderDetailInfo(req) + }, + Validators: []utest.TestValidator{ + ctx.NewValidator("RetCode", "0", "str_eq"), + ctx.NewValidator("OrderInfos.0.Amount", ctx.GetVar("buy_price"), "float_eq"), + }, + MaxRetries: 3, + RetryInterval: 1 * time.Second, + T: ctx.T, + } + + resp, err := testCase.Run() + if resp == nil || err != nil { + ctx.T.Fatal(err) + } + +} + +func testSet2301GetEIPUpgradePrice03(ctx *utest.TestContext) { + time.Sleep(time.Duration(0) * time.Second) + + req := unetClient.NewGetEIPUpgradePriceRequest() + + ctx.NoError(utest.SetReqValue(req, "Region", ctx.GetVar("Region"))) + ctx.NoError(utest.SetReqValue(req, "EIPId", ctx.GetVar("eip_id"))) + ctx.NoError(utest.SetReqValue(req, "Bandwidth", "3")) + + testCase := utest.TestCase{ + Invoker: func() (interface{}, error) { + return unetClient.GetEIPUpgradePrice(req) + }, + Validators: []utest.TestValidator{ + ctx.NewValidator("RetCode", "0", "str_eq"), + }, + MaxRetries: 0, + RetryInterval: 0 * time.Second, + T: ctx.T, + } + + resp, err := testCase.Run() + if resp == nil || err != nil { + ctx.T.Fatal(err) + } + + ctx.Vars["upgrade_price"] = ctx.Must(utest.GetValue(resp, "Price")) +} + +func testSet2301ModifyEIPBandwidth04(ctx *utest.TestContext) { + time.Sleep(time.Duration(0) * time.Second) + + req := unetClient.NewModifyEIPBandwidthRequest() + + ctx.NoError(utest.SetReqValue(req, "Region", ctx.GetVar("Region"))) + ctx.NoError(utest.SetReqValue(req, "EIPId", ctx.GetVar("eip_id"))) + ctx.NoError(utest.SetReqValue(req, "Bandwidth", "3")) + + testCase := utest.TestCase{ + Invoker: func() (interface{}, error) { + return unetClient.ModifyEIPBandwidth(req) + }, + Validators: []utest.TestValidator{ + ctx.NewValidator("RetCode", "0", "str_eq"), + }, + MaxRetries: 0, + RetryInterval: 0 * time.Second, + T: ctx.T, + } + + resp, err := testCase.Run() + if resp == nil || err != nil { + ctx.T.Fatal(err) + } + +} + +func testSet2301DescribeOrderDetailInfo05(ctx *utest.TestContext) { + time.Sleep(time.Duration(5) * time.Second) + + req := ubillClient.NewDescribeOrderDetailInfoRequest() + + ctx.NoError(utest.SetReqValue(req, "BeginTime", ctx.GetVar("begin_time"))) + ctx.NoError(utest.SetReqValue(req, "EndTime", ctx.Must(utest.GetTimestamp("10")))) + + ctx.NoError(utest.SetReqValue(req, "ResourceTypes", "EIP")) + ctx.NoError(utest.SetReqValue(req, "OrderTypes", "OT_UPGRADE")) + + ctx.NoError(utest.SetReqValue(req, "ResourceIds", ctx.GetVar("eip_id"))) + + testCase := utest.TestCase{ + Invoker: func() (interface{}, error) { + return ubillClient.DescribeOrderDetailInfo(req) + }, + Validators: []utest.TestValidator{ + ctx.NewValidator("RetCode", "0", "str_eq"), + ctx.NewValidator("OrderInfos.0.Amount", ctx.GetVar("upgrade_price"), "float_eq"), + }, + MaxRetries: 3, + RetryInterval: 1 * time.Second, + T: ctx.T, + } + + resp, err := testCase.Run() + if resp == nil || err != nil { + ctx.T.Fatal(err) + } + +} + +func testSet2301GetEIPUpgradePrice06(ctx *utest.TestContext) { + time.Sleep(time.Duration(0) * time.Second) + + req := unetClient.NewGetEIPUpgradePriceRequest() + + ctx.NoError(utest.SetReqValue(req, "Region", ctx.GetVar("Region"))) + ctx.NoError(utest.SetReqValue(req, "EIPId", ctx.GetVar("eip_id"))) + ctx.NoError(utest.SetReqValue(req, "Bandwidth", "2")) + + testCase := utest.TestCase{ + Invoker: func() (interface{}, error) { + return unetClient.GetEIPUpgradePrice(req) + }, + Validators: []utest.TestValidator{ + ctx.NewValidator("RetCode", "0", "str_eq"), + }, + MaxRetries: 0, + RetryInterval: 0 * time.Second, + T: ctx.T, + } + + resp, err := testCase.Run() + if resp == nil || err != nil { + ctx.T.Fatal(err) + } + + ctx.Vars["down_price"] = ctx.Must(utest.GetValue(resp, "Price")) +} + +func testSet2301ModifyEIPBandwidth07(ctx *utest.TestContext) { + time.Sleep(time.Duration(2) * time.Second) + + req := unetClient.NewModifyEIPBandwidthRequest() + + ctx.NoError(utest.SetReqValue(req, "Region", ctx.GetVar("Region"))) + ctx.NoError(utest.SetReqValue(req, "EIPId", ctx.GetVar("eip_id"))) + ctx.NoError(utest.SetReqValue(req, "Bandwidth", "2")) + + testCase := utest.TestCase{ + Invoker: func() (interface{}, error) { + return unetClient.ModifyEIPBandwidth(req) + }, + Validators: []utest.TestValidator{ + ctx.NewValidator("RetCode", "0", "str_eq"), + }, + MaxRetries: 3, + RetryInterval: 1 * time.Second, + T: ctx.T, + } + + resp, err := testCase.Run() + if resp == nil || err != nil { + ctx.T.Fatal(err) + } + +} + +func testSet2301DescribeOrderDetailInfo08(ctx *utest.TestContext) { + time.Sleep(time.Duration(5) * time.Second) + + req := ubillClient.NewDescribeOrderDetailInfoRequest() + + ctx.NoError(utest.SetReqValue(req, "BeginTime", ctx.GetVar("begin_time"))) + ctx.NoError(utest.SetReqValue(req, "EndTime", ctx.Must(utest.GetTimestamp("10")))) + + ctx.NoError(utest.SetReqValue(req, "ResourceTypes", "EIP")) + ctx.NoError(utest.SetReqValue(req, "OrderTypes", "OT_DOWNGRADE")) + + ctx.NoError(utest.SetReqValue(req, "ResourceIds", ctx.GetVar("eip_id"))) + + testCase := utest.TestCase{ + Invoker: func() (interface{}, error) { + return ubillClient.DescribeOrderDetailInfo(req) + }, + Validators: []utest.TestValidator{ + ctx.NewValidator("RetCode", "0", "str_eq"), + ctx.NewValidator("OrderInfos.0.Amount", ctx.GetVar("down_price"), "float_eq"), + }, + MaxRetries: 3, + RetryInterval: 1 * time.Second, + T: ctx.T, + } + + resp, err := testCase.Run() + if resp == nil || err != nil { + ctx.T.Fatal(err) + } + +} + +func testSet2301ReleaseEIP09(ctx *utest.TestContext) { + time.Sleep(time.Duration(0) * time.Second) + + req := unetClient.NewReleaseEIPRequest() + + ctx.NoError(utest.SetReqValue(req, "Region", ctx.GetVar("Region"))) + ctx.NoError(utest.SetReqValue(req, "EIPId", ctx.GetVar("eip_id"))) + + testCase := utest.TestCase{ + Invoker: func() (interface{}, error) { + return unetClient.ReleaseEIP(req) + }, + Validators: []utest.TestValidator{ + ctx.NewValidator("RetCode", "0", "str_eq"), + }, + MaxRetries: 0, + RetryInterval: 0 * time.Second, + T: ctx.T, + } + + resp, err := testCase.Run() + if resp == nil || err != nil { + ctx.T.Fatal(err) + } + +} diff --git a/tests/setup_test.go b/tests/setup_test.go index 8189c0a1..7453ccca 100644 --- a/tests/setup_test.go +++ b/tests/setup_test.go @@ -10,6 +10,7 @@ import ( "github.com/ucloud/ucloud-sdk-go/services/pathx" "github.com/ucloud/ucloud-sdk-go/services/uaccount" + "github.com/ucloud/ucloud-sdk-go/services/ubill" "github.com/ucloud/ucloud-sdk-go/services/udb" "github.com/ucloud/ucloud-sdk-go/services/udisk" "github.com/ucloud/ucloud-sdk-go/services/udpn" @@ -43,6 +44,7 @@ var udiskClient *udisk.UDiskClient var udbClient *udb.UDBClient var umemClient *umem.UMemClient var udpnClient *udpn.UDPNClient +var ubillClient *ubill.UBillClient var iuhostClient *iuhost.UHostClient var iunetClient *iunet.UNetClient @@ -86,6 +88,7 @@ func testSetup() { udbClient = udb.NewClient(&cfg, &credential) umemClient = umem.NewClient(&cfg, &credential) udpnClient = udpn.NewClient(&cfg, &credential) + ubillClient = ubill.NewClient(&cfg, &credential) iudataarkClient = iudataark.NewClient(&cfg, &credential) iudiskClient = iudisk.NewClient(&cfg, &credential) diff --git a/ucloud/version/version.go b/ucloud/version/version.go index 98dcc724..bfb012be 100644 --- a/ucloud/version/version.go +++ b/ucloud/version/version.go @@ -4,4 +4,4 @@ Package version is the version of sdk package version // Version see also semantic version: https://semver.org/ -const Version = "0.6.1" +const Version = "0.6.2"