diff --git a/service/qingcloud.go b/service/qingcloud.go index 9507be7..8fe6f63 100644 --- a/service/qingcloud.go +++ b/service/qingcloud.go @@ -82,3 +82,48 @@ type DescribeZonesOutput struct { TotalCount *int `json:"total_count" name:"total_count" location:"elements"` ZoneSet []*Zone `json:"zone_set" name:"zone_set" location:"elements"` } +type GetBalanceInput struct { + +} + +func (v *GetBalanceInput) Validate() error { + + return nil +} + +type GetBalanceOutput struct { + Action string `json:"action" name:"action" location:"elements"` + UserID string `json:"user_id" name:"user_id" location:"elements"` + Balance string `json:"balance" name:"balance" location:"elements"` + Bonus string `json:"bonus" name:"onus" location:"elements"` + Coupons []*string `json:"coupons" name:"coupons" location:"elements"` + RetCode *int `json:"ret_code" name:"ret_code" location:"elements"` +} + + + +// Documentation URL: https://docsv4.qingcloud.com/user_guide/development_docs/api/api_list/billing/get_balance/ +func (s *QingCloudService) GetBalance(i *GetBalanceInput) (*DescribeZonesOutput, error) { + if i == nil { + i = &GetBalanceInput{} + } + o := &data.Operation{ + Config: s.Config, + Properties: s.Properties, + APIName: "GetBalance", + RequestMethod: "GET", + } + + x := &DescribeZonesOutput{} + r, err := request.New(o, i, x) + if err != nil { + return nil, err + } + + err = r.Send() + if err != nil { + return nil, err + } + + return x, err +} \ No newline at end of file diff --git a/test/service_test.go b/test/service_test.go index 10bade4..576abd5 100644 --- a/test/service_test.go +++ b/test/service_test.go @@ -32,6 +32,9 @@ func QingCloudServiceFeatureContext(s *godog.Suite) { s.Step(`^describe zones$`, describeZones) s.Step(`^describe zones should get (\d+) zone at least$`, describeZonesShouldGetZoneAtLeast) s.Step(`^describe zones should have the zone I\'m using$`, describeZonesShouldHaveTheZoneIamUsing) + + s.Step(`^get balance$`, getBalance()) + s.Step(`^get balance should not error$`, getBalanceShouldNotError) } // -------------------------------------------------------------------------- @@ -72,3 +75,17 @@ func describeZonesShouldHaveTheZoneIamUsing() error { return fmt.Errorf("DescribeZones dosen't have zone \"%s\"", tc.Zone) } + +// -------------------------------------------------------------------------- +var getBalanceOutput *qc.GetBalanceOutput + +func getBalance() error { + describeZonesOutput, err = qcService.GetBalance(nil) + return err +} +func getBalanceShouldNotError() error { + if *getBalanceOutput.RetCode == 0 { + return nil + } + return fmt.Errorf("DescribeZones dosen't have zone \"%s\"", tc.Zone) +} \ No newline at end of file