From 21ded7e3829b8948e0e0e231daaf130ced805638 Mon Sep 17 00:00:00 2001 From: "manu.k.m" Date: Mon, 21 Aug 2023 23:49:52 +0530 Subject: [PATCH] feat(Usage Reports): add billing snapshot config service to usage reports --- usagereportsv4/usage_reports_v4.go | 1478 ++++++++++++++++- .../usage_reports_v4_integration_test.go | 482 ++++-- usagereportsv4/usage_reports_v4_test.go | 1287 +++++++++++++- 3 files changed, 2954 insertions(+), 293 deletions(-) diff --git a/usagereportsv4/usage_reports_v4.go b/usagereportsv4/usage_reports_v4.go index 18af7f7e..a67f2aba 100644 --- a/usagereportsv4/usage_reports_v4.go +++ b/usagereportsv4/usage_reports_v4.go @@ -15,7 +15,7 @@ */ /* - * IBM OpenAPI SDK Code Generator Version: 3.64.1-cee95189-20230124-211647 + * IBM OpenAPI SDK Code Generator Version: 3.75.0-726bc7e3-20230713-221716 */ // Package usagereportsv4 : Operations and models for the UsageReportsV4 service @@ -407,6 +407,9 @@ func (usageReports *UsageReportsV4) GetResourceUsageAccountWithContext(ctx conte if getResourceUsageAccountOptions.Names != nil { builder.AddQuery("_names", fmt.Sprint(*getResourceUsageAccountOptions.Names)) } + if getResourceUsageAccountOptions.Tags != nil { + builder.AddQuery("_tags", fmt.Sprint(*getResourceUsageAccountOptions.Tags)) + } if getResourceUsageAccountOptions.Limit != nil { builder.AddQuery("_limit", fmt.Sprint(*getResourceUsageAccountOptions.Limit)) } @@ -501,6 +504,9 @@ func (usageReports *UsageReportsV4) GetResourceUsageResourceGroupWithContext(ctx if getResourceUsageResourceGroupOptions.Names != nil { builder.AddQuery("_names", fmt.Sprint(*getResourceUsageResourceGroupOptions.Names)) } + if getResourceUsageResourceGroupOptions.Tags != nil { + builder.AddQuery("_tags", fmt.Sprint(*getResourceUsageResourceGroupOptions.Tags)) + } if getResourceUsageResourceGroupOptions.Limit != nil { builder.AddQuery("_limit", fmt.Sprint(*getResourceUsageResourceGroupOptions.Limit)) } @@ -589,6 +595,9 @@ func (usageReports *UsageReportsV4) GetResourceUsageOrgWithContext(ctx context.C if getResourceUsageOrgOptions.Names != nil { builder.AddQuery("_names", fmt.Sprint(*getResourceUsageOrgOptions.Names)) } + if getResourceUsageOrgOptions.Tags != nil { + builder.AddQuery("_tags", fmt.Sprint(*getResourceUsageOrgOptions.Tags)) + } if getResourceUsageOrgOptions.Limit != nil { builder.AddQuery("_limit", fmt.Sprint(*getResourceUsageOrgOptions.Limit)) } @@ -699,6 +708,344 @@ func (usageReports *UsageReportsV4) GetOrgUsageWithContext(ctx context.Context, return } +// CreateReportsSnapshotConfig : Setup the snapshot configuration +// Snapshots of the billing reports would be taken on a periodic interval and stored based on the configuration setup by +// the customer for the given Account Id. +func (usageReports *UsageReportsV4) CreateReportsSnapshotConfig(createReportsSnapshotConfigOptions *CreateReportsSnapshotConfigOptions) (result *SnapshotConfig, response *core.DetailedResponse, err error) { + return usageReports.CreateReportsSnapshotConfigWithContext(context.Background(), createReportsSnapshotConfigOptions) +} + +// CreateReportsSnapshotConfigWithContext is an alternate form of the CreateReportsSnapshotConfig method which supports a Context parameter +func (usageReports *UsageReportsV4) CreateReportsSnapshotConfigWithContext(ctx context.Context, createReportsSnapshotConfigOptions *CreateReportsSnapshotConfigOptions) (result *SnapshotConfig, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(createReportsSnapshotConfigOptions, "createReportsSnapshotConfigOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(createReportsSnapshotConfigOptions, "createReportsSnapshotConfigOptions") + if err != nil { + return + } + + builder := core.NewRequestBuilder(core.POST) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = usageReports.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(usageReports.Service.Options.URL, `/v1/billing-reports-snapshot-config`, nil) + if err != nil { + return + } + + for headerName, headerValue := range createReportsSnapshotConfigOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("usage_reports", "V4", "CreateReportsSnapshotConfig") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + + body := make(map[string]interface{}) + if createReportsSnapshotConfigOptions.AccountID != nil { + body["account_id"] = createReportsSnapshotConfigOptions.AccountID + } + if createReportsSnapshotConfigOptions.Interval != nil { + body["interval"] = createReportsSnapshotConfigOptions.Interval + } + if createReportsSnapshotConfigOptions.CosBucket != nil { + body["cos_bucket"] = createReportsSnapshotConfigOptions.CosBucket + } + if createReportsSnapshotConfigOptions.CosLocation != nil { + body["cos_location"] = createReportsSnapshotConfigOptions.CosLocation + } + if createReportsSnapshotConfigOptions.CosReportsFolder != nil { + body["cos_reports_folder"] = createReportsSnapshotConfigOptions.CosReportsFolder + } + if createReportsSnapshotConfigOptions.ReportTypes != nil { + body["report_types"] = createReportsSnapshotConfigOptions.ReportTypes + } + if createReportsSnapshotConfigOptions.Versioning != nil { + body["versioning"] = createReportsSnapshotConfigOptions.Versioning + } + _, err = builder.SetBodyContentJSON(body) + if err != nil { + return + } + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = usageReports.Service.Request(request, &rawResponse) + if err != nil { + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalSnapshotConfig) + if err != nil { + return + } + response.Result = result + } + + return +} + +// GetReportsSnapshotConfig : Fetch the snapshot configuration +// Returns the configuration of snapshot of the billing reports setup by the customer for the given Account Id. +func (usageReports *UsageReportsV4) GetReportsSnapshotConfig(getReportsSnapshotConfigOptions *GetReportsSnapshotConfigOptions) (result *SnapshotConfig, response *core.DetailedResponse, err error) { + return usageReports.GetReportsSnapshotConfigWithContext(context.Background(), getReportsSnapshotConfigOptions) +} + +// GetReportsSnapshotConfigWithContext is an alternate form of the GetReportsSnapshotConfig method which supports a Context parameter +func (usageReports *UsageReportsV4) GetReportsSnapshotConfigWithContext(ctx context.Context, getReportsSnapshotConfigOptions *GetReportsSnapshotConfigOptions) (result *SnapshotConfig, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(getReportsSnapshotConfigOptions, "getReportsSnapshotConfigOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(getReportsSnapshotConfigOptions, "getReportsSnapshotConfigOptions") + if err != nil { + return + } + + builder := core.NewRequestBuilder(core.GET) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = usageReports.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(usageReports.Service.Options.URL, `/v1/billing-reports-snapshot-config`, nil) + if err != nil { + return + } + + for headerName, headerValue := range getReportsSnapshotConfigOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("usage_reports", "V4", "GetReportsSnapshotConfig") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + + builder.AddQuery("account_id", fmt.Sprint(*getReportsSnapshotConfigOptions.AccountID)) + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = usageReports.Service.Request(request, &rawResponse) + if err != nil { + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalSnapshotConfig) + if err != nil { + return + } + response.Result = result + } + + return +} + +// UpdateReportsSnapshotConfig : Update the snapshot configuration +// Updates the configuration of snapshot of the billing reports setup by the customer for the given Account Id. +func (usageReports *UsageReportsV4) UpdateReportsSnapshotConfig(updateReportsSnapshotConfigOptions *UpdateReportsSnapshotConfigOptions) (result *SnapshotConfig, response *core.DetailedResponse, err error) { + return usageReports.UpdateReportsSnapshotConfigWithContext(context.Background(), updateReportsSnapshotConfigOptions) +} + +// UpdateReportsSnapshotConfigWithContext is an alternate form of the UpdateReportsSnapshotConfig method which supports a Context parameter +func (usageReports *UsageReportsV4) UpdateReportsSnapshotConfigWithContext(ctx context.Context, updateReportsSnapshotConfigOptions *UpdateReportsSnapshotConfigOptions) (result *SnapshotConfig, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(updateReportsSnapshotConfigOptions, "updateReportsSnapshotConfigOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(updateReportsSnapshotConfigOptions, "updateReportsSnapshotConfigOptions") + if err != nil { + return + } + + builder := core.NewRequestBuilder(core.PATCH) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = usageReports.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(usageReports.Service.Options.URL, `/v1/billing-reports-snapshot-config`, nil) + if err != nil { + return + } + + for headerName, headerValue := range updateReportsSnapshotConfigOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("usage_reports", "V4", "UpdateReportsSnapshotConfig") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + + body := make(map[string]interface{}) + if updateReportsSnapshotConfigOptions.AccountID != nil { + body["account_id"] = updateReportsSnapshotConfigOptions.AccountID + } + if updateReportsSnapshotConfigOptions.Interval != nil { + body["interval"] = updateReportsSnapshotConfigOptions.Interval + } + if updateReportsSnapshotConfigOptions.CosBucket != nil { + body["cos_bucket"] = updateReportsSnapshotConfigOptions.CosBucket + } + if updateReportsSnapshotConfigOptions.CosLocation != nil { + body["cos_location"] = updateReportsSnapshotConfigOptions.CosLocation + } + if updateReportsSnapshotConfigOptions.CosReportsFolder != nil { + body["cos_reports_folder"] = updateReportsSnapshotConfigOptions.CosReportsFolder + } + if updateReportsSnapshotConfigOptions.ReportTypes != nil { + body["report_types"] = updateReportsSnapshotConfigOptions.ReportTypes + } + if updateReportsSnapshotConfigOptions.Versioning != nil { + body["versioning"] = updateReportsSnapshotConfigOptions.Versioning + } + _, err = builder.SetBodyContentJSON(body) + if err != nil { + return + } + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = usageReports.Service.Request(request, &rawResponse) + if err != nil { + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalSnapshotConfig) + if err != nil { + return + } + response.Result = result + } + + return +} + +// DeleteReportsSnapshotConfig : Delete the snapshot configuration +// Delete the configuration of snapshot of the billing reports setup by the customer for the given Account Id. +func (usageReports *UsageReportsV4) DeleteReportsSnapshotConfig(deleteReportsSnapshotConfigOptions *DeleteReportsSnapshotConfigOptions) (response *core.DetailedResponse, err error) { + return usageReports.DeleteReportsSnapshotConfigWithContext(context.Background(), deleteReportsSnapshotConfigOptions) +} + +// DeleteReportsSnapshotConfigWithContext is an alternate form of the DeleteReportsSnapshotConfig method which supports a Context parameter +func (usageReports *UsageReportsV4) DeleteReportsSnapshotConfigWithContext(ctx context.Context, deleteReportsSnapshotConfigOptions *DeleteReportsSnapshotConfigOptions) (response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(deleteReportsSnapshotConfigOptions, "deleteReportsSnapshotConfigOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(deleteReportsSnapshotConfigOptions, "deleteReportsSnapshotConfigOptions") + if err != nil { + return + } + + builder := core.NewRequestBuilder(core.DELETE) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = usageReports.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(usageReports.Service.Options.URL, `/v1/billing-reports-snapshot-config`, nil) + if err != nil { + return + } + + for headerName, headerValue := range deleteReportsSnapshotConfigOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("usage_reports", "V4", "DeleteReportsSnapshotConfig") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + + builder.AddQuery("account_id", fmt.Sprint(*deleteReportsSnapshotConfigOptions.AccountID)) + + request, err := builder.Build() + if err != nil { + return + } + + response, err = usageReports.Service.Request(request, nil) + + return +} + +// GetReportsSnapshot : Fetch the current or past snapshots +// Returns the billing reports snapshots captured for the given Account Id in the specific time period. +func (usageReports *UsageReportsV4) GetReportsSnapshot(getReportsSnapshotOptions *GetReportsSnapshotOptions) (result *SnapshotList, response *core.DetailedResponse, err error) { + return usageReports.GetReportsSnapshotWithContext(context.Background(), getReportsSnapshotOptions) +} + +// GetReportsSnapshotWithContext is an alternate form of the GetReportsSnapshot method which supports a Context parameter +func (usageReports *UsageReportsV4) GetReportsSnapshotWithContext(ctx context.Context, getReportsSnapshotOptions *GetReportsSnapshotOptions) (result *SnapshotList, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(getReportsSnapshotOptions, "getReportsSnapshotOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(getReportsSnapshotOptions, "getReportsSnapshotOptions") + if err != nil { + return + } + + builder := core.NewRequestBuilder(core.GET) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = usageReports.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(usageReports.Service.Options.URL, `/v1/billing-reports-snapshots`, nil) + if err != nil { + return + } + + for headerName, headerValue := range getReportsSnapshotOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("usage_reports", "V4", "GetReportsSnapshot") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + + builder.AddQuery("account_id", fmt.Sprint(*getReportsSnapshotOptions.AccountID)) + builder.AddQuery("month", fmt.Sprint(*getReportsSnapshotOptions.Month)) + if getReportsSnapshotOptions.DateFrom != nil { + builder.AddQuery("date_from", fmt.Sprint(*getReportsSnapshotOptions.DateFrom)) + } + if getReportsSnapshotOptions.DateTo != nil { + builder.AddQuery("date_to", fmt.Sprint(*getReportsSnapshotOptions.DateTo)) + } + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = usageReports.Service.Request(request, &rawResponse) + if err != nil { + return + } + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalSnapshotList) + if err != nil { + return + } + response.Result = result + } + + return +} + // AccountSummary : A summary of charges and credits for an account. type AccountSummary struct { // The ID of the account. @@ -831,25 +1178,161 @@ func UnmarshalAccountUsage(m map[string]json.RawMessage, result interface{}) (er return } -// Discount : Information about a discount that is associated with a metric. -type Discount struct { - // The reference ID of the discount. - Ref *string `json:"ref" validate:"required"` +// CreateReportsSnapshotConfigOptions : The CreateReportsSnapshotConfig options. +type CreateReportsSnapshotConfigOptions struct { + // Account ID for which billing report snapshot is configured. + AccountID *string `json:"account_id" validate:"required"` - // The name of the discount indicating category. - Name *string `json:"name,omitempty"` + // Frequency of taking the snapshot of the billing reports. + Interval *string `json:"interval" validate:"required"` - // The name of the discount. - DisplayName *string `json:"display_name,omitempty"` + // The name of the COS bucket to store the snapshot of the billing reports. + CosBucket *string `json:"cos_bucket" validate:"required"` - // The discount percentage. - Discount *float64 `json:"discount" validate:"required"` + // Region of the COS instance. + CosLocation *string `json:"cos_location" validate:"required"` + + // The billing reports root folder to store the billing reports snapshots. Defaults to "IBMCloud-Billing-Reports". + CosReportsFolder *string `json:"cos_reports_folder,omitempty"` + + // The type of billing reports to take snapshot of. Possible values are [account_summary, enterprise_summary, + // account_resource_instance_usage]. + ReportTypes []string `json:"report_types,omitempty"` + + // A new version of report is created or the existing report version is overwritten with every update. Defaults to + // "new". + Versioning *string `json:"versioning,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string } -// UnmarshalDiscount unmarshals an instance of Discount from the specified map of raw messages. -func UnmarshalDiscount(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(Discount) - err = core.UnmarshalPrimitive(m, "ref", &obj.Ref) +// Constants associated with the CreateReportsSnapshotConfigOptions.Interval property. +// Frequency of taking the snapshot of the billing reports. +const ( + CreateReportsSnapshotConfigOptionsIntervalDailyConst = "daily" +) + +// Constants associated with the CreateReportsSnapshotConfigOptions.ReportTypes property. +const ( + CreateReportsSnapshotConfigOptionsReportTypesAccountResourceInstanceUsageConst = "account_resource_instance_usage" + CreateReportsSnapshotConfigOptionsReportTypesAccountSummaryConst = "account_summary" + CreateReportsSnapshotConfigOptionsReportTypesEnterpriseSummaryConst = "enterprise_summary" +) + +// Constants associated with the CreateReportsSnapshotConfigOptions.Versioning property. +// A new version of report is created or the existing report version is overwritten with every update. Defaults to +// "new". +const ( + CreateReportsSnapshotConfigOptionsVersioningNewConst = "new" + CreateReportsSnapshotConfigOptionsVersioningOverwriteConst = "overwrite" +) + +// NewCreateReportsSnapshotConfigOptions : Instantiate CreateReportsSnapshotConfigOptions +func (*UsageReportsV4) NewCreateReportsSnapshotConfigOptions(accountID string, interval string, cosBucket string, cosLocation string) *CreateReportsSnapshotConfigOptions { + return &CreateReportsSnapshotConfigOptions{ + AccountID: core.StringPtr(accountID), + Interval: core.StringPtr(interval), + CosBucket: core.StringPtr(cosBucket), + CosLocation: core.StringPtr(cosLocation), + } +} + +// SetAccountID : Allow user to set AccountID +func (_options *CreateReportsSnapshotConfigOptions) SetAccountID(accountID string) *CreateReportsSnapshotConfigOptions { + _options.AccountID = core.StringPtr(accountID) + return _options +} + +// SetInterval : Allow user to set Interval +func (_options *CreateReportsSnapshotConfigOptions) SetInterval(interval string) *CreateReportsSnapshotConfigOptions { + _options.Interval = core.StringPtr(interval) + return _options +} + +// SetCosBucket : Allow user to set CosBucket +func (_options *CreateReportsSnapshotConfigOptions) SetCosBucket(cosBucket string) *CreateReportsSnapshotConfigOptions { + _options.CosBucket = core.StringPtr(cosBucket) + return _options +} + +// SetCosLocation : Allow user to set CosLocation +func (_options *CreateReportsSnapshotConfigOptions) SetCosLocation(cosLocation string) *CreateReportsSnapshotConfigOptions { + _options.CosLocation = core.StringPtr(cosLocation) + return _options +} + +// SetCosReportsFolder : Allow user to set CosReportsFolder +func (_options *CreateReportsSnapshotConfigOptions) SetCosReportsFolder(cosReportsFolder string) *CreateReportsSnapshotConfigOptions { + _options.CosReportsFolder = core.StringPtr(cosReportsFolder) + return _options +} + +// SetReportTypes : Allow user to set ReportTypes +func (_options *CreateReportsSnapshotConfigOptions) SetReportTypes(reportTypes []string) *CreateReportsSnapshotConfigOptions { + _options.ReportTypes = reportTypes + return _options +} + +// SetVersioning : Allow user to set Versioning +func (_options *CreateReportsSnapshotConfigOptions) SetVersioning(versioning string) *CreateReportsSnapshotConfigOptions { + _options.Versioning = core.StringPtr(versioning) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *CreateReportsSnapshotConfigOptions) SetHeaders(param map[string]string) *CreateReportsSnapshotConfigOptions { + options.Headers = param + return options +} + +// DeleteReportsSnapshotConfigOptions : The DeleteReportsSnapshotConfig options. +type DeleteReportsSnapshotConfigOptions struct { + // Account ID for which the billing report snapshot is configured. + AccountID *string `json:"account_id" validate:"required"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewDeleteReportsSnapshotConfigOptions : Instantiate DeleteReportsSnapshotConfigOptions +func (*UsageReportsV4) NewDeleteReportsSnapshotConfigOptions(accountID string) *DeleteReportsSnapshotConfigOptions { + return &DeleteReportsSnapshotConfigOptions{ + AccountID: core.StringPtr(accountID), + } +} + +// SetAccountID : Allow user to set AccountID +func (_options *DeleteReportsSnapshotConfigOptions) SetAccountID(accountID string) *DeleteReportsSnapshotConfigOptions { + _options.AccountID = core.StringPtr(accountID) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *DeleteReportsSnapshotConfigOptions) SetHeaders(param map[string]string) *DeleteReportsSnapshotConfigOptions { + options.Headers = param + return options +} + +// Discount : Information about a discount that is associated with a metric. +type Discount struct { + // The reference ID of the discount. + Ref *string `json:"ref" validate:"required"` + + // The name of the discount indicating category. + Name *string `json:"name,omitempty"` + + // The name of the discount. + DisplayName *string `json:"display_name,omitempty"` + + // The discount percentage. + Discount *float64 `json:"discount" validate:"required"` +} + +// UnmarshalDiscount unmarshals an instance of Discount from the specified map of raw messages. +func UnmarshalDiscount(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(Discount) + err = core.UnmarshalPrimitive(m, "ref", &obj.Ref) if err != nil { return } @@ -1029,6 +1512,90 @@ func (options *GetOrgUsageOptions) SetHeaders(param map[string]string) *GetOrgUs return options } +// GetReportsSnapshotConfigOptions : The GetReportsSnapshotConfig options. +type GetReportsSnapshotConfigOptions struct { + // Account ID for which the billing report snapshot is configured. + AccountID *string `json:"account_id" validate:"required"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewGetReportsSnapshotConfigOptions : Instantiate GetReportsSnapshotConfigOptions +func (*UsageReportsV4) NewGetReportsSnapshotConfigOptions(accountID string) *GetReportsSnapshotConfigOptions { + return &GetReportsSnapshotConfigOptions{ + AccountID: core.StringPtr(accountID), + } +} + +// SetAccountID : Allow user to set AccountID +func (_options *GetReportsSnapshotConfigOptions) SetAccountID(accountID string) *GetReportsSnapshotConfigOptions { + _options.AccountID = core.StringPtr(accountID) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *GetReportsSnapshotConfigOptions) SetHeaders(param map[string]string) *GetReportsSnapshotConfigOptions { + options.Headers = param + return options +} + +// GetReportsSnapshotOptions : The GetReportsSnapshot options. +type GetReportsSnapshotOptions struct { + // Account ID for which the billing report snapshot is requested. + AccountID *string `json:"account_id" validate:"required"` + + // The month for which billing report snapshot is requested. Format is yyyy-mm. + Month *string `json:"month" validate:"required"` + + // Timestamp in milliseconds for which billing report snapshot is requested. + DateFrom *float64 `json:"date_from,omitempty"` + + // Timestamp in milliseconds for which billing report snapshot is requested. + DateTo *float64 `json:"date_to,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewGetReportsSnapshotOptions : Instantiate GetReportsSnapshotOptions +func (*UsageReportsV4) NewGetReportsSnapshotOptions(accountID string, month string) *GetReportsSnapshotOptions { + return &GetReportsSnapshotOptions{ + AccountID: core.StringPtr(accountID), + Month: core.StringPtr(month), + } +} + +// SetAccountID : Allow user to set AccountID +func (_options *GetReportsSnapshotOptions) SetAccountID(accountID string) *GetReportsSnapshotOptions { + _options.AccountID = core.StringPtr(accountID) + return _options +} + +// SetMonth : Allow user to set Month +func (_options *GetReportsSnapshotOptions) SetMonth(month string) *GetReportsSnapshotOptions { + _options.Month = core.StringPtr(month) + return _options +} + +// SetDateFrom : Allow user to set DateFrom +func (_options *GetReportsSnapshotOptions) SetDateFrom(dateFrom float64) *GetReportsSnapshotOptions { + _options.DateFrom = core.Float64Ptr(dateFrom) + return _options +} + +// SetDateTo : Allow user to set DateTo +func (_options *GetReportsSnapshotOptions) SetDateTo(dateTo float64) *GetReportsSnapshotOptions { + _options.DateTo = core.Float64Ptr(dateTo) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *GetReportsSnapshotOptions) SetHeaders(param map[string]string) *GetReportsSnapshotOptions { + options.Headers = param + return options +} + // GetResourceGroupUsageOptions : The GetResourceGroupUsage options. type GetResourceGroupUsageOptions struct { // Account ID for which the usage report is requested. @@ -1106,6 +1673,9 @@ type GetResourceUsageAccountOptions struct { // Include the name of every resource, plan, resource instance, organization, and resource group. Names *bool `json:"_names,omitempty"` + // Include the user tags associated with every resource instance. By default it is always `true`. + Tags *bool `json:"_tags,omitempty"` + // Prioritize the names returned in the order of the specified languages. Language will default to English. AcceptLanguage *string `json:"Accept-Language,omitempty"` @@ -1163,6 +1733,12 @@ func (_options *GetResourceUsageAccountOptions) SetNames(names bool) *GetResourc return _options } +// SetTags : Allow user to set Tags +func (_options *GetResourceUsageAccountOptions) SetTags(tags bool) *GetResourceUsageAccountOptions { + _options.Tags = core.BoolPtr(tags) + return _options +} + // SetAcceptLanguage : Allow user to set AcceptLanguage func (_options *GetResourceUsageAccountOptions) SetAcceptLanguage(acceptLanguage string) *GetResourceUsageAccountOptions { _options.AcceptLanguage = core.StringPtr(acceptLanguage) @@ -1237,6 +1813,9 @@ type GetResourceUsageOrgOptions struct { // Include the name of every resource, plan, resource instance, organization, and resource group. Names *bool `json:"_names,omitempty"` + // Include the user tags associated with every resource instance. By default it is always `true`. + Tags *bool `json:"_tags,omitempty"` + // Prioritize the names returned in the order of the specified languages. Language will default to English. AcceptLanguage *string `json:"Accept-Language,omitempty"` @@ -1295,6 +1874,12 @@ func (_options *GetResourceUsageOrgOptions) SetNames(names bool) *GetResourceUsa return _options } +// SetTags : Allow user to set Tags +func (_options *GetResourceUsageOrgOptions) SetTags(tags bool) *GetResourceUsageOrgOptions { + _options.Tags = core.BoolPtr(tags) + return _options +} + // SetAcceptLanguage : Allow user to set AcceptLanguage func (_options *GetResourceUsageOrgOptions) SetAcceptLanguage(acceptLanguage string) *GetResourceUsageOrgOptions { _options.AcceptLanguage = core.StringPtr(acceptLanguage) @@ -1357,6 +1942,9 @@ type GetResourceUsageResourceGroupOptions struct { // Include the name of every resource, plan, resource instance, organization, and resource group. Names *bool `json:"_names,omitempty"` + // Include the user tags associated with every resource instance. By default it is always `true`. + Tags *bool `json:"_tags,omitempty"` + // Prioritize the names returned in the order of the specified languages. Language will default to English. AcceptLanguage *string `json:"Accept-Language,omitempty"` @@ -1415,6 +2003,12 @@ func (_options *GetResourceUsageResourceGroupOptions) SetNames(names bool) *GetR return _options } +// SetTags : Allow user to set Tags +func (_options *GetResourceUsageResourceGroupOptions) SetTags(tags bool) *GetResourceUsageResourceGroupOptions { + _options.Tags = core.BoolPtr(tags) + return _options +} + // SetAcceptLanguage : Allow user to set AcceptLanguage func (_options *GetResourceUsageResourceGroupOptions) SetAcceptLanguage(acceptLanguage string) *GetResourceUsageResourceGroupOptions { _options.AcceptLanguage = core.StringPtr(acceptLanguage) @@ -1522,6 +2116,9 @@ type InstanceUsage struct { // The name of the plan where the instance was provisioned and rated. PlanName *string `json:"plan_name,omitempty"` + // The ID of the pricing plan used to rate the usage. + PricingPlanID *string `json:"pricing_plan_id,omitempty"` + // The month. Month *string `json:"month" validate:"required"` @@ -1533,6 +2130,9 @@ type InstanceUsage struct { // The value of the account's currency in USD. CurrencyRate *float64 `json:"currency_rate,omitempty"` + + // The user tags associated with a resource instance. + Tags []interface{} `json:"tags,omitempty"` } // UnmarshalInstanceUsage unmarshals an instance of InstanceUsage from the specified map of raw messages. @@ -1614,6 +2214,10 @@ func UnmarshalInstanceUsage(m map[string]json.RawMessage, result interface{}) (e if err != nil { return } + err = core.UnmarshalPrimitive(m, "pricing_plan_id", &obj.PricingPlanID) + if err != nil { + return + } err = core.UnmarshalPrimitive(m, "month", &obj.Month) if err != nil { return @@ -1630,6 +2234,10 @@ func UnmarshalInstanceUsage(m map[string]json.RawMessage, result interface{}) (e if err != nil { return } + err = core.UnmarshalPrimitive(m, "tags", &obj.Tags) + if err != nil { + return + } reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) return } @@ -1979,6 +2587,7 @@ type Plan struct { // The pricing region for the plan. PricingRegion *string `json:"pricing_region,omitempty"` + // The ID of the pricing plan used to rate the usage. PricingPlanID *string `json:"pricing_plan_id,omitempty"` // Indicates if the plan charges are billed to the customer. @@ -2203,89 +2812,149 @@ func UnmarshalResourcesSummary(m map[string]json.RawMessage, result interface{}) return } -// Subscription : Subscription struct -type Subscription struct { - // The ID of the subscription. - SubscriptionID *string `json:"subscription_id" validate:"required"` +// SnapshotConfigHistoryItem : SnapshotConfigHistoryItem struct +type SnapshotConfigHistoryItem struct { + // Timestamp in milliseconds when the snapshot configuration was created. + StartTime *float64 `json:"start_time,omitempty"` - // The charge agreement number of the subsciption. - ChargeAgreementNumber *string `json:"charge_agreement_number" validate:"required"` + // Timestamp in milliseconds when the snapshot configuration ends. + EndTime *float64 `json:"end_time,omitempty"` - // Type of the subscription. - Type *string `json:"type" validate:"required"` + // Account that updated the billing snapshot configuration. + UpdatedBy *string `json:"updated_by,omitempty"` - // The credits available in the subscription for the month. - SubscriptionAmount *float64 `json:"subscription_amount" validate:"required"` + // Account ID for which billing report snapshot is configured. + AccountID *string `json:"account_id,omitempty"` - // The date from which the subscription was active. - Start *strfmt.DateTime `json:"start" validate:"required"` + // Status of the billing snapshot configuration. Possible values are [enabled, disabled]. + State *string `json:"state,omitempty"` - // The date until which the subscription is active. End time is unavailable for PayGO accounts. - End *strfmt.DateTime `json:"end,omitempty"` + // Type of account. Possible values [enterprise, account]. + AccountType *string `json:"account_type,omitempty"` - // The total credits available in the subscription. - CreditsTotal *float64 `json:"credits_total" validate:"required"` + // Frequency of taking the snapshot of the billing reports. + Interval *string `json:"interval,omitempty"` - // The terms through which the subscription is split into. - Terms []SubscriptionTerm `json:"terms" validate:"required"` + // A new version of report is created or the existing report version is overwritten with every update. + Versioning *string `json:"versioning,omitempty"` + + // The type of billing reports to take snapshot of. Possible values are [account_summary, enterprise_summary, + // account_resource_instance_usage]. + ReportTypes []string `json:"report_types,omitempty"` + + // Compression format of the snapshot report. + Compression *string `json:"compression,omitempty"` + + // Type of content stored in snapshot report. + ContentType *string `json:"content_type,omitempty"` + + // The billing reports root folder to store the billing reports snapshots. Defaults to "IBMCloud-Billing-Reports". + CosReportsFolder *string `json:"cos_reports_folder,omitempty"` + + // The name of the COS bucket to store the snapshot of the billing reports. + CosBucket *string `json:"cos_bucket,omitempty"` + + // Region of the COS instance. + CosLocation *string `json:"cos_location,omitempty"` + + // The endpoint of the COS instance. + CosEndpoint *string `json:"cos_endpoint,omitempty"` } -// UnmarshalSubscription unmarshals an instance of Subscription from the specified map of raw messages. -func UnmarshalSubscription(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(Subscription) - err = core.UnmarshalPrimitive(m, "subscription_id", &obj.SubscriptionID) +// Constants associated with the SnapshotConfigHistoryItem.State property. +// Status of the billing snapshot configuration. Possible values are [enabled, disabled]. +const ( + SnapshotConfigHistoryItemStateDisabledConst = "disabled" + SnapshotConfigHistoryItemStateEnabledConst = "enabled" +) + +// Constants associated with the SnapshotConfigHistoryItem.AccountType property. +// Type of account. Possible values [enterprise, account]. +const ( + SnapshotConfigHistoryItemAccountTypeAccountConst = "account" + SnapshotConfigHistoryItemAccountTypeEnterpriseConst = "enterprise" +) + +// Constants associated with the SnapshotConfigHistoryItem.Interval property. +// Frequency of taking the snapshot of the billing reports. +const ( + SnapshotConfigHistoryItemIntervalDailyConst = "daily" +) + +// Constants associated with the SnapshotConfigHistoryItem.Versioning property. +// A new version of report is created or the existing report version is overwritten with every update. +const ( + SnapshotConfigHistoryItemVersioningNewConst = "new" + SnapshotConfigHistoryItemVersioningOverwriteConst = "overwrite" +) + +// Constants associated with the SnapshotConfigHistoryItem.ReportTypes property. +const ( + SnapshotConfigHistoryItemReportTypesAccountResourceInstanceUsageConst = "account_resource_instance_usage" + SnapshotConfigHistoryItemReportTypesAccountSummaryConst = "account_summary" + SnapshotConfigHistoryItemReportTypesEnterpriseSummaryConst = "enterprise_summary" +) + +// UnmarshalSnapshotConfigHistoryItem unmarshals an instance of SnapshotConfigHistoryItem from the specified map of raw messages. +func UnmarshalSnapshotConfigHistoryItem(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(SnapshotConfigHistoryItem) + err = core.UnmarshalPrimitive(m, "start_time", &obj.StartTime) if err != nil { return } - err = core.UnmarshalPrimitive(m, "charge_agreement_number", &obj.ChargeAgreementNumber) + err = core.UnmarshalPrimitive(m, "end_time", &obj.EndTime) if err != nil { return } - err = core.UnmarshalPrimitive(m, "type", &obj.Type) + err = core.UnmarshalPrimitive(m, "updated_by", &obj.UpdatedBy) if err != nil { return } - err = core.UnmarshalPrimitive(m, "subscription_amount", &obj.SubscriptionAmount) + err = core.UnmarshalPrimitive(m, "account_id", &obj.AccountID) if err != nil { return } - err = core.UnmarshalPrimitive(m, "start", &obj.Start) + err = core.UnmarshalPrimitive(m, "state", &obj.State) if err != nil { return } - err = core.UnmarshalPrimitive(m, "end", &obj.End) + err = core.UnmarshalPrimitive(m, "account_type", &obj.AccountType) if err != nil { return } - err = core.UnmarshalPrimitive(m, "credits_total", &obj.CreditsTotal) + err = core.UnmarshalPrimitive(m, "interval", &obj.Interval) if err != nil { return } - err = core.UnmarshalModel(m, "terms", &obj.Terms, UnmarshalSubscriptionTerm) + err = core.UnmarshalPrimitive(m, "versioning", &obj.Versioning) if err != nil { return } - reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) - return -} - -// SubscriptionSummary : A summary of charges and credits related to a subscription. -type SubscriptionSummary struct { - // The charges after exhausting subscription credits and offers credits. - Overage *float64 `json:"overage,omitempty"` - - // The list of subscriptions applicable for the month. - Subscriptions []Subscription `json:"subscriptions,omitempty"` -} - -// UnmarshalSubscriptionSummary unmarshals an instance of SubscriptionSummary from the specified map of raw messages. -func UnmarshalSubscriptionSummary(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(SubscriptionSummary) - err = core.UnmarshalPrimitive(m, "overage", &obj.Overage) + err = core.UnmarshalPrimitive(m, "report_types", &obj.ReportTypes) if err != nil { return } - err = core.UnmarshalModel(m, "subscriptions", &obj.Subscriptions, UnmarshalSubscription) + err = core.UnmarshalPrimitive(m, "compression", &obj.Compression) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "content_type", &obj.ContentType) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "cos_reports_folder", &obj.CosReportsFolder) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "cos_bucket", &obj.CosBucket) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "cos_location", &obj.CosLocation) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "cos_endpoint", &obj.CosEndpoint) if err != nil { return } @@ -2293,30 +2962,36 @@ func UnmarshalSubscriptionSummary(m map[string]json.RawMessage, result interface return } -// SubscriptionTerm : SubscriptionTerm struct -type SubscriptionTerm struct { - // The start date of the term. - Start *strfmt.DateTime `json:"start" validate:"required"` +// SnapshotList : List of billing reports snapshots. +type SnapshotList struct { + // Number of total snapshots. + Count *float64 `json:"count,omitempty"` - // The end date of the term. - End *strfmt.DateTime `json:"end" validate:"required"` + // Reference to the first page of the search query. + First *SnapshotListFirst `json:"first,omitempty"` - // Information about credits related to a subscription. - Credits *SubscriptionTermCredits `json:"credits" validate:"required"` + // Reference to the next page of the search query if any. + Next *SnapshotListNext `json:"next,omitempty"` + + Snapshots []SnapshotListSnapshotsItem `json:"snapshots,omitempty"` } -// UnmarshalSubscriptionTerm unmarshals an instance of SubscriptionTerm from the specified map of raw messages. -func UnmarshalSubscriptionTerm(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(SubscriptionTerm) - err = core.UnmarshalPrimitive(m, "start", &obj.Start) +// UnmarshalSnapshotList unmarshals an instance of SnapshotList from the specified map of raw messages. +func UnmarshalSnapshotList(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(SnapshotList) + err = core.UnmarshalPrimitive(m, "count", &obj.Count) if err != nil { return } - err = core.UnmarshalPrimitive(m, "end", &obj.End) + err = core.UnmarshalModel(m, "first", &obj.First, UnmarshalSnapshotListFirst) if err != nil { return } - err = core.UnmarshalModel(m, "credits", &obj.Credits, UnmarshalSubscriptionTermCredits) + err = core.UnmarshalModel(m, "next", &obj.Next, UnmarshalSnapshotListNext) + if err != nil { + return + } + err = core.UnmarshalModel(m, "snapshots", &obj.Snapshots, UnmarshalSnapshotListSnapshotsItem) if err != nil { return } @@ -2324,11 +2999,549 @@ func UnmarshalSubscriptionTerm(m map[string]json.RawMessage, result interface{}) return } -// SubscriptionTermCredits : Information about credits related to a subscription. -type SubscriptionTermCredits struct { - // The total credits available for the term. - Total *float64 `json:"total" validate:"required"` - +// SnapshotListFirst : Reference to the first page of the search query. +type SnapshotListFirst struct { + Href *string `json:"href,omitempty"` +} + +// UnmarshalSnapshotListFirst unmarshals an instance of SnapshotListFirst from the specified map of raw messages. +func UnmarshalSnapshotListFirst(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(SnapshotListFirst) + err = core.UnmarshalPrimitive(m, "href", &obj.Href) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// SnapshotListNext : Reference to the next page of the search query if any. +type SnapshotListNext struct { + Href *string `json:"href,omitempty"` +} + +// UnmarshalSnapshotListNext unmarshals an instance of SnapshotListNext from the specified map of raw messages. +func UnmarshalSnapshotListNext(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(SnapshotListNext) + err = core.UnmarshalPrimitive(m, "href", &obj.Href) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// SnapshotListSnapshotsItem : Snapshot Schema. +type SnapshotListSnapshotsItem struct { + // Account ID for which billing report snapshot is configured. + AccountID *string `json:"account_id,omitempty"` + + // Month of captured snapshot. + Month *string `json:"month,omitempty"` + + // Type of account. Possible values are [enterprise, account]. + AccountType *string `json:"account_type,omitempty"` + + // Timestamp of snapshot processed. + ExpectedProcessedAt *float64 `json:"expected_processed_at,omitempty"` + + // Status of the billing snapshot configuration. Possible values are [enabled, disabled]. + State *string `json:"state,omitempty"` + + // Period of billing in snapshot. + BillingPeriod *SnapshotListSnapshotsItemBillingPeriod `json:"billing_period,omitempty"` + + // Id of the snapshot captured. + SnapshotID *string `json:"snapshot_id,omitempty"` + + // Character encoding used. + Charset *string `json:"charset,omitempty"` + + // Compression format of the snapshot report. + Compression *string `json:"compression,omitempty"` + + // Type of content stored in snapshot report. + ContentType *string `json:"content_type,omitempty"` + + // The name of the COS bucket to store the snapshot of the billing reports. + Bucket *string `json:"bucket,omitempty"` + + // Version of the snapshot. + Version *string `json:"version,omitempty"` + + // Date and time of creation of snapshot. + CreatedOn *string `json:"created_on,omitempty"` + + // List of report types configured for the snapshot. + ReportTypes []SnapshotListSnapshotsItemReportTypesItem `json:"report_types,omitempty"` + + // List of location of reports. + Files []SnapshotListSnapshotsItemFilesItem `json:"files,omitempty"` + + // Timestamp at which snapshot is captured. + ProcessedAt *float64 `json:"processed_at,omitempty"` +} + +// Constants associated with the SnapshotListSnapshotsItem.AccountType property. +// Type of account. Possible values are [enterprise, account]. +const ( + SnapshotListSnapshotsItemAccountTypeAccountConst = "account" + SnapshotListSnapshotsItemAccountTypeEnterpriseConst = "enterprise" +) + +// Constants associated with the SnapshotListSnapshotsItem.State property. +// Status of the billing snapshot configuration. Possible values are [enabled, disabled]. +const ( + SnapshotListSnapshotsItemStateDisabledConst = "disabled" + SnapshotListSnapshotsItemStateEnabledConst = "enabled" +) + +// UnmarshalSnapshotListSnapshotsItem unmarshals an instance of SnapshotListSnapshotsItem from the specified map of raw messages. +func UnmarshalSnapshotListSnapshotsItem(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(SnapshotListSnapshotsItem) + err = core.UnmarshalPrimitive(m, "account_id", &obj.AccountID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "month", &obj.Month) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "account_type", &obj.AccountType) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "expected_processed_at", &obj.ExpectedProcessedAt) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "state", &obj.State) + if err != nil { + return + } + err = core.UnmarshalModel(m, "billing_period", &obj.BillingPeriod, UnmarshalSnapshotListSnapshotsItemBillingPeriod) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "snapshot_id", &obj.SnapshotID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "charset", &obj.Charset) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "compression", &obj.Compression) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "content_type", &obj.ContentType) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "bucket", &obj.Bucket) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "version", &obj.Version) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "created_on", &obj.CreatedOn) + if err != nil { + return + } + err = core.UnmarshalModel(m, "report_types", &obj.ReportTypes, UnmarshalSnapshotListSnapshotsItemReportTypesItem) + if err != nil { + return + } + err = core.UnmarshalModel(m, "files", &obj.Files, UnmarshalSnapshotListSnapshotsItemFilesItem) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "processed_at", &obj.ProcessedAt) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// SnapshotListSnapshotsItemBillingPeriod : Period of billing in snapshot. +type SnapshotListSnapshotsItemBillingPeriod struct { + // Date and time of start of billing in the respective snapshot. + Start *string `json:"start,omitempty"` + + // Date and time of end of billing in the respective snapshot. + End *string `json:"end,omitempty"` +} + +// UnmarshalSnapshotListSnapshotsItemBillingPeriod unmarshals an instance of SnapshotListSnapshotsItemBillingPeriod from the specified map of raw messages. +func UnmarshalSnapshotListSnapshotsItemBillingPeriod(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(SnapshotListSnapshotsItemBillingPeriod) + err = core.UnmarshalPrimitive(m, "start", &obj.Start) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "end", &obj.End) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// SnapshotListSnapshotsItemFilesItem : SnapshotListSnapshotsItemFilesItem struct +type SnapshotListSnapshotsItemFilesItem struct { + // The type of billing report stored. Possible values are [account_summary, enterprise_summary, + // account_resource_instance_usage]. + ReportTypes *string `json:"report_types,omitempty"` + + // Absolute path of the billing report in the COS instance. + Location *string `json:"location,omitempty"` + + // Account ID for which billing report is captured. + AccountID *string `json:"account_id,omitempty"` +} + +// Constants associated with the SnapshotListSnapshotsItemFilesItem.ReportTypes property. +// The type of billing report stored. Possible values are [account_summary, enterprise_summary, +// account_resource_instance_usage]. +const ( + SnapshotListSnapshotsItemFilesItemReportTypesAccountResourceInstanceUsageConst = "account_resource_instance_usage" + SnapshotListSnapshotsItemFilesItemReportTypesAccountSummaryConst = "account_summary" + SnapshotListSnapshotsItemFilesItemReportTypesEnterpriseSummaryConst = "enterprise_summary" +) + +// UnmarshalSnapshotListSnapshotsItemFilesItem unmarshals an instance of SnapshotListSnapshotsItemFilesItem from the specified map of raw messages. +func UnmarshalSnapshotListSnapshotsItemFilesItem(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(SnapshotListSnapshotsItemFilesItem) + err = core.UnmarshalPrimitive(m, "report_types", &obj.ReportTypes) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "location", &obj.Location) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "account_id", &obj.AccountID) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// SnapshotListSnapshotsItemReportTypesItem : SnapshotListSnapshotsItemReportTypesItem struct +type SnapshotListSnapshotsItemReportTypesItem struct { + // The type of billing report of the snapshot. Possible values are [account_summary, enterprise_summary, + // account_resource_instance_usage]. + Type *string `json:"type,omitempty"` + + // Version of the snapshot. + Version *string `json:"version,omitempty"` +} + +// Constants associated with the SnapshotListSnapshotsItemReportTypesItem.Type property. +// The type of billing report of the snapshot. Possible values are [account_summary, enterprise_summary, +// account_resource_instance_usage]. +const ( + SnapshotListSnapshotsItemReportTypesItemTypeAccountResourceInstanceUsageConst = "account_resource_instance_usage" + SnapshotListSnapshotsItemReportTypesItemTypeAccountSummaryConst = "account_summary" + SnapshotListSnapshotsItemReportTypesItemTypeEnterpriseSummaryConst = "enterprise_summary" +) + +// UnmarshalSnapshotListSnapshotsItemReportTypesItem unmarshals an instance of SnapshotListSnapshotsItemReportTypesItem from the specified map of raw messages. +func UnmarshalSnapshotListSnapshotsItemReportTypesItem(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(SnapshotListSnapshotsItemReportTypesItem) + err = core.UnmarshalPrimitive(m, "type", &obj.Type) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "version", &obj.Version) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// SnapshotConfig : Billing reports snapshot configuration. +type SnapshotConfig struct { + // Account ID for which billing report snapshot is configured. + AccountID *string `json:"account_id,omitempty"` + + // Status of the billing snapshot configuration. Possible values are [enabled, disabled]. + State *string `json:"state,omitempty"` + + // Type of account. Possible values are [enterprise, account]. + AccountType *string `json:"account_type,omitempty"` + + // Frequency of taking the snapshot of the billing reports. + Interval *string `json:"interval,omitempty"` + + // A new version of report is created or the existing report version is overwritten with every update. + Versioning *string `json:"versioning,omitempty"` + + // The type of billing reports to take snapshot of. Possible values are [account_summary, enterprise_summary, + // account_resource_instance_usage]. + ReportTypes []string `json:"report_types,omitempty"` + + // Compression format of the snapshot report. + Compression *string `json:"compression,omitempty"` + + // Type of content stored in snapshot report. + ContentType *string `json:"content_type,omitempty"` + + // The billing reports root folder to store the billing reports snapshots. Defaults to "IBMCloud-Billing-Reports". + CosReportsFolder *string `json:"cos_reports_folder,omitempty"` + + // The name of the COS bucket to store the snapshot of the billing reports. + CosBucket *string `json:"cos_bucket,omitempty"` + + // Region of the COS instance. + CosLocation *string `json:"cos_location,omitempty"` + + // The endpoint of the COS instance. + CosEndpoint *string `json:"cos_endpoint,omitempty"` + + // Timestamp in milliseconds when the snapshot configuration was created. + CreatedAt *float64 `json:"created_at,omitempty"` + + // Timestamp in milliseconds when the snapshot configuration was last updated. + LastUpdatedAt *float64 `json:"last_updated_at,omitempty"` + + // List of previous versions of the snapshot configurations. + History []SnapshotConfigHistoryItem `json:"history,omitempty"` +} + +// Constants associated with the SnapshotConfig.State property. +// Status of the billing snapshot configuration. Possible values are [enabled, disabled]. +const ( + SnapshotConfigStateDisabledConst = "disabled" + SnapshotConfigStateEnabledConst = "enabled" +) + +// Constants associated with the SnapshotConfig.AccountType property. +// Type of account. Possible values are [enterprise, account]. +const ( + SnapshotConfigAccountTypeAccountConst = "account" + SnapshotConfigAccountTypeEnterpriseConst = "enterprise" +) + +// Constants associated with the SnapshotConfig.Interval property. +// Frequency of taking the snapshot of the billing reports. +const ( + SnapshotConfigIntervalDailyConst = "daily" +) + +// Constants associated with the SnapshotConfig.Versioning property. +// A new version of report is created or the existing report version is overwritten with every update. +const ( + SnapshotConfigVersioningNewConst = "new" + SnapshotConfigVersioningOverwriteConst = "overwrite" +) + +// Constants associated with the SnapshotConfig.ReportTypes property. +const ( + SnapshotConfigReportTypesAccountResourceInstanceUsageConst = "account_resource_instance_usage" + SnapshotConfigReportTypesAccountSummaryConst = "account_summary" + SnapshotConfigReportTypesEnterpriseSummaryConst = "enterprise_summary" +) + +// UnmarshalSnapshotConfig unmarshals an instance of SnapshotConfig from the specified map of raw messages. +func UnmarshalSnapshotConfig(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(SnapshotConfig) + err = core.UnmarshalPrimitive(m, "account_id", &obj.AccountID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "state", &obj.State) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "account_type", &obj.AccountType) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "interval", &obj.Interval) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "versioning", &obj.Versioning) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "report_types", &obj.ReportTypes) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "compression", &obj.Compression) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "content_type", &obj.ContentType) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "cos_reports_folder", &obj.CosReportsFolder) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "cos_bucket", &obj.CosBucket) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "cos_location", &obj.CosLocation) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "cos_endpoint", &obj.CosEndpoint) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "created_at", &obj.CreatedAt) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "last_updated_at", &obj.LastUpdatedAt) + if err != nil { + return + } + err = core.UnmarshalModel(m, "history", &obj.History, UnmarshalSnapshotConfigHistoryItem) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// Subscription : Subscription struct +type Subscription struct { + // The ID of the subscription. + SubscriptionID *string `json:"subscription_id" validate:"required"` + + // The charge agreement number of the subsciption. + ChargeAgreementNumber *string `json:"charge_agreement_number" validate:"required"` + + // Type of the subscription. + Type *string `json:"type" validate:"required"` + + // The credits available in the subscription for the month. + SubscriptionAmount *float64 `json:"subscription_amount" validate:"required"` + + // The date from which the subscription was active. + Start *strfmt.DateTime `json:"start" validate:"required"` + + // The date until which the subscription is active. End time is unavailable for PayGO accounts. + End *strfmt.DateTime `json:"end,omitempty"` + + // The total credits available in the subscription. + CreditsTotal *float64 `json:"credits_total" validate:"required"` + + // The terms through which the subscription is split into. + Terms []SubscriptionTerm `json:"terms" validate:"required"` +} + +// UnmarshalSubscription unmarshals an instance of Subscription from the specified map of raw messages. +func UnmarshalSubscription(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(Subscription) + err = core.UnmarshalPrimitive(m, "subscription_id", &obj.SubscriptionID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "charge_agreement_number", &obj.ChargeAgreementNumber) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "type", &obj.Type) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "subscription_amount", &obj.SubscriptionAmount) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "start", &obj.Start) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "end", &obj.End) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "credits_total", &obj.CreditsTotal) + if err != nil { + return + } + err = core.UnmarshalModel(m, "terms", &obj.Terms, UnmarshalSubscriptionTerm) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// SubscriptionSummary : A summary of charges and credits related to a subscription. +type SubscriptionSummary struct { + // The charges after exhausting subscription credits and offers credits. + Overage *float64 `json:"overage,omitempty"` + + // The list of subscriptions applicable for the month. + Subscriptions []Subscription `json:"subscriptions,omitempty"` +} + +// UnmarshalSubscriptionSummary unmarshals an instance of SubscriptionSummary from the specified map of raw messages. +func UnmarshalSubscriptionSummary(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(SubscriptionSummary) + err = core.UnmarshalPrimitive(m, "overage", &obj.Overage) + if err != nil { + return + } + err = core.UnmarshalModel(m, "subscriptions", &obj.Subscriptions, UnmarshalSubscription) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// SubscriptionTerm : SubscriptionTerm struct +type SubscriptionTerm struct { + // The start date of the term. + Start *strfmt.DateTime `json:"start" validate:"required"` + + // The end date of the term. + End *strfmt.DateTime `json:"end" validate:"required"` + + // Information about credits related to a subscription. + Credits *SubscriptionTermCredits `json:"credits" validate:"required"` +} + +// UnmarshalSubscriptionTerm unmarshals an instance of SubscriptionTerm from the specified map of raw messages. +func UnmarshalSubscriptionTerm(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(SubscriptionTerm) + err = core.UnmarshalPrimitive(m, "start", &obj.Start) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "end", &obj.End) + if err != nil { + return + } + err = core.UnmarshalModel(m, "credits", &obj.Credits, UnmarshalSubscriptionTermCredits) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// SubscriptionTermCredits : Information about credits related to a subscription. +type SubscriptionTermCredits struct { + // The total credits available for the term. + Total *float64 `json:"total" validate:"required"` + // The unused credits in the term at the beginning of the month. StartingBalance *float64 `json:"starting_balance" validate:"required"` @@ -2393,6 +3606,109 @@ func UnmarshalSupportSummary(m map[string]json.RawMessage, result interface{}) ( return } +// UpdateReportsSnapshotConfigOptions : The UpdateReportsSnapshotConfig options. +type UpdateReportsSnapshotConfigOptions struct { + // Account ID for which billing report snapshot is configured. + AccountID *string `json:"account_id" validate:"required"` + + // Frequency of taking the snapshot of the billing reports. + Interval *string `json:"interval,omitempty"` + + // The name of the COS bucket to store the snapshot of the billing reports. + CosBucket *string `json:"cos_bucket,omitempty"` + + // Region of the COS instance. + CosLocation *string `json:"cos_location,omitempty"` + + // The billing reports root folder to store the billing reports snapshots. + CosReportsFolder *string `json:"cos_reports_folder,omitempty"` + + // The type of billing reports to take snapshot of. Possible values are [account_summary, enterprise_summary, + // account_resource_instance_usage]. + ReportTypes []string `json:"report_types,omitempty"` + + // A new version of report is created or the existing report version is overwritten with every update. + Versioning *string `json:"versioning,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// Constants associated with the UpdateReportsSnapshotConfigOptions.Interval property. +// Frequency of taking the snapshot of the billing reports. +const ( + UpdateReportsSnapshotConfigOptionsIntervalDailyConst = "daily" +) + +// Constants associated with the UpdateReportsSnapshotConfigOptions.ReportTypes property. +const ( + UpdateReportsSnapshotConfigOptionsReportTypesAccountResourceInstanceUsageConst = "account_resource_instance_usage" + UpdateReportsSnapshotConfigOptionsReportTypesAccountSummaryConst = "account_summary" + UpdateReportsSnapshotConfigOptionsReportTypesEnterpriseSummaryConst = "enterprise_summary" +) + +// Constants associated with the UpdateReportsSnapshotConfigOptions.Versioning property. +// A new version of report is created or the existing report version is overwritten with every update. +const ( + UpdateReportsSnapshotConfigOptionsVersioningNewConst = "new" + UpdateReportsSnapshotConfigOptionsVersioningOverwriteConst = "overwrite" +) + +// NewUpdateReportsSnapshotConfigOptions : Instantiate UpdateReportsSnapshotConfigOptions +func (*UsageReportsV4) NewUpdateReportsSnapshotConfigOptions(accountID string) *UpdateReportsSnapshotConfigOptions { + return &UpdateReportsSnapshotConfigOptions{ + AccountID: core.StringPtr(accountID), + } +} + +// SetAccountID : Allow user to set AccountID +func (_options *UpdateReportsSnapshotConfigOptions) SetAccountID(accountID string) *UpdateReportsSnapshotConfigOptions { + _options.AccountID = core.StringPtr(accountID) + return _options +} + +// SetInterval : Allow user to set Interval +func (_options *UpdateReportsSnapshotConfigOptions) SetInterval(interval string) *UpdateReportsSnapshotConfigOptions { + _options.Interval = core.StringPtr(interval) + return _options +} + +// SetCosBucket : Allow user to set CosBucket +func (_options *UpdateReportsSnapshotConfigOptions) SetCosBucket(cosBucket string) *UpdateReportsSnapshotConfigOptions { + _options.CosBucket = core.StringPtr(cosBucket) + return _options +} + +// SetCosLocation : Allow user to set CosLocation +func (_options *UpdateReportsSnapshotConfigOptions) SetCosLocation(cosLocation string) *UpdateReportsSnapshotConfigOptions { + _options.CosLocation = core.StringPtr(cosLocation) + return _options +} + +// SetCosReportsFolder : Allow user to set CosReportsFolder +func (_options *UpdateReportsSnapshotConfigOptions) SetCosReportsFolder(cosReportsFolder string) *UpdateReportsSnapshotConfigOptions { + _options.CosReportsFolder = core.StringPtr(cosReportsFolder) + return _options +} + +// SetReportTypes : Allow user to set ReportTypes +func (_options *UpdateReportsSnapshotConfigOptions) SetReportTypes(reportTypes []string) *UpdateReportsSnapshotConfigOptions { + _options.ReportTypes = reportTypes + return _options +} + +// SetVersioning : Allow user to set Versioning +func (_options *UpdateReportsSnapshotConfigOptions) SetVersioning(versioning string) *UpdateReportsSnapshotConfigOptions { + _options.Versioning = core.StringPtr(versioning) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *UpdateReportsSnapshotConfigOptions) SetHeaders(param map[string]string) *UpdateReportsSnapshotConfigOptions { + options.Headers = param + return options +} + // // GetResourceUsageAccountPager can be used to simplify the use of the "GetResourceUsageAccount" method. // diff --git a/usagereportsv4/usage_reports_v4_integration_test.go b/usagereportsv4/usage_reports_v4_integration_test.go index 2f4eecdd..4ac15766 100644 --- a/usagereportsv4/usage_reports_v4_integration_test.go +++ b/usagereportsv4/usage_reports_v4_integration_test.go @@ -1,7 +1,7 @@ // +build integration /** - * (C) Copyright IBM Corp. 2020. + * (C) Copyright IBM Corp. 2023. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,6 @@ import ( "time" "github.com/IBM/go-sdk-core/v5/core" - common "github.com/IBM/platform-services-go-sdk/common" "github.com/IBM/platform-services-go-sdk/usagereportsv4" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -40,19 +39,13 @@ import ( */ var _ = Describe(`UsageReportsV4 Integration Tests`, func() { - - const externalConfigFile = "../usage_reports.env" + const externalConfigFile = "../usage_reports_v4.env" var ( - err error + err error usageReportsService *usagereportsv4.UsageReportsV4 - serviceURL string - config map[string]string - - accountID string - resourceGroupID string - orgID string - billingMonth string + serviceURL string + config map[string]string ) var shouldSkipTest = func() { @@ -76,20 +69,7 @@ var _ = Describe(`UsageReportsV4 Integration Tests`, func() { Skip("Unable to load service URL configuration property, skipping tests") } - fmt.Fprintf(GinkgoWriter, "Service URL: %s\n", serviceURL) - - accountID = config["ACCOUNT_ID"] - Expect(accountID).ToNot(BeEmpty()) - - resourceGroupID = config["RESOURCE_GROUP_ID"] - Expect(resourceGroupID).ToNot(BeEmpty()) - - orgID = config["ORG_ID"] - Expect(orgID).ToNot(BeEmpty()) - - billingMonth = config["BILLING_MONTH"] - Expect(billingMonth).ToNot(BeEmpty()) - + fmt.Fprintf(GinkgoWriter, "Service URL: %v\n", serviceURL) shouldSkipTest = func() {} }) }) @@ -99,11 +79,9 @@ var _ = Describe(`UsageReportsV4 Integration Tests`, func() { shouldSkipTest() }) It("Successfully construct the service client instance", func() { - usageReportsServiceOptions := &usagereportsv4.UsageReportsV4Options{} usageReportsService, err = usagereportsv4.NewUsageReportsV4UsingExternalConfig(usageReportsServiceOptions) - Expect(err).To(BeNil()) Expect(usageReportsService).ToNot(BeNil()) Expect(usageReportsService.Service.Options.URL).To(Equal(serviceURL)) @@ -118,22 +96,15 @@ var _ = Describe(`UsageReportsV4 Integration Tests`, func() { shouldSkipTest() }) It(`GetAccountSummary(getAccountSummaryOptions *GetAccountSummaryOptions)`, func() { - getAccountSummaryOptions := &usagereportsv4.GetAccountSummaryOptions{ - AccountID: &accountID, - Billingmonth: &billingMonth, + AccountID: core.StringPtr("testString"), + Billingmonth: core.StringPtr("testString"), } accountSummary, response, err := usageReportsService.GetAccountSummary(getAccountSummaryOptions) - Expect(err).To(BeNil()) Expect(response.StatusCode).To(Equal(200)) Expect(accountSummary).ToNot(BeNil()) - fmt.Fprintf(GinkgoWriter, "\nGetAccountSummary response:\n%s", common.ToJSON(accountSummary)) - - Expect(*accountSummary.AccountID).To(Equal(accountID)) - Expect(accountSummary.Offers).ToNot(BeEmpty()) - Expect(accountSummary.Subscription).ToNot(BeNil()) }) }) @@ -142,24 +113,17 @@ var _ = Describe(`UsageReportsV4 Integration Tests`, func() { shouldSkipTest() }) It(`GetAccountUsage(getAccountUsageOptions *GetAccountUsageOptions)`, func() { - getAccountUsageOptions := &usagereportsv4.GetAccountUsageOptions{ - AccountID: &accountID, - Billingmonth: &billingMonth, - Names: core.BoolPtr(true), - AcceptLanguage: core.StringPtr("English"), + AccountID: core.StringPtr("testString"), + Billingmonth: core.StringPtr("testString"), + Names: core.BoolPtr(true), + AcceptLanguage: core.StringPtr("testString"), } accountUsage, response, err := usageReportsService.GetAccountUsage(getAccountUsageOptions) - Expect(err).To(BeNil()) Expect(response.StatusCode).To(Equal(200)) Expect(accountUsage).ToNot(BeNil()) - fmt.Fprintf(GinkgoWriter, "\nGetAccountUsage response:\n%s", common.ToJSON(accountUsage)) - - Expect(*accountUsage.AccountID).To(Equal(accountID)) - Expect(*accountUsage.Month).To(Equal(billingMonth)) - Expect(accountUsage.Resources).ToNot(BeEmpty()) }) }) @@ -168,191 +132,381 @@ var _ = Describe(`UsageReportsV4 Integration Tests`, func() { shouldSkipTest() }) It(`GetResourceGroupUsage(getResourceGroupUsageOptions *GetResourceGroupUsageOptions)`, func() { - getResourceGroupUsageOptions := &usagereportsv4.GetResourceGroupUsageOptions{ - AccountID: &accountID, - ResourceGroupID: &resourceGroupID, - Billingmonth: &billingMonth, - Names: core.BoolPtr(true), + AccountID: core.StringPtr("testString"), + ResourceGroupID: core.StringPtr("testString"), + Billingmonth: core.StringPtr("testString"), + Names: core.BoolPtr(true), + AcceptLanguage: core.StringPtr("testString"), } resourceGroupUsage, response, err := usageReportsService.GetResourceGroupUsage(getResourceGroupUsageOptions) - Expect(err).To(BeNil()) Expect(response.StatusCode).To(Equal(200)) Expect(resourceGroupUsage).ToNot(BeNil()) - fmt.Fprintf(GinkgoWriter, "\nGetResourceGroupUsage response:\n%s", common.ToJSON(resourceGroupUsage)) - - Expect(*resourceGroupUsage.AccountID).To(Equal(accountID)) - Expect(*resourceGroupUsage.Month).To(Equal(billingMonth)) - Expect(resourceGroupUsage.Resources).ToNot(BeEmpty()) }) }) - Describe(`GetOrgUsage - Get organization usage`, func() { + Describe(`GetResourceUsageAccount - Get resource instance usage in an account`, func() { BeforeEach(func() { shouldSkipTest() }) - It(`GetOrgUsage(getOrgUsageOptions *GetOrgUsageOptions)`, func() { + It(`GetResourceUsageAccount(getResourceUsageAccountOptions *GetResourceUsageAccountOptions) with pagination`, func(){ + getResourceUsageAccountOptions := &usagereportsv4.GetResourceUsageAccountOptions{ + AccountID: core.StringPtr("testString"), + Billingmonth: core.StringPtr("testString"), + Names: core.BoolPtr(true), + Tags: core.BoolPtr(true), + AcceptLanguage: core.StringPtr("testString"), + Limit: core.Int64Ptr(int64(30)), + Start: core.StringPtr("testString"), + ResourceGroupID: core.StringPtr("testString"), + OrganizationID: core.StringPtr("testString"), + ResourceInstanceID: core.StringPtr("testString"), + ResourceID: core.StringPtr("testString"), + PlanID: core.StringPtr("testString"), + Region: core.StringPtr("testString"), + } - getOrgUsageOptions := &usagereportsv4.GetOrgUsageOptions{ - AccountID: &accountID, - OrganizationID: &orgID, - Billingmonth: &billingMonth, - Names: core.BoolPtr(true), + getResourceUsageAccountOptions.Start = nil + + var allResults []usagereportsv4.InstanceUsage + for { + instancesUsage, response, err := usageReportsService.GetResourceUsageAccount(getResourceUsageAccountOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(instancesUsage).ToNot(BeNil()) + allResults = append(allResults, instancesUsage.Resources...) + + getResourceUsageAccountOptions.Start, err = instancesUsage.GetNextStart() + Expect(err).To(BeNil()) + + if getResourceUsageAccountOptions.Start == nil { + break + } + } + fmt.Fprintf(GinkgoWriter, "Retrieved a total of %d item(s) with pagination.\n", len(allResults)) + }) + It(`GetResourceUsageAccount(getResourceUsageAccountOptions *GetResourceUsageAccountOptions) using GetResourceUsageAccountPager`, func(){ + getResourceUsageAccountOptions := &usagereportsv4.GetResourceUsageAccountOptions{ + AccountID: core.StringPtr("testString"), + Billingmonth: core.StringPtr("testString"), + Names: core.BoolPtr(true), + Tags: core.BoolPtr(true), + AcceptLanguage: core.StringPtr("testString"), + Limit: core.Int64Ptr(int64(30)), + ResourceGroupID: core.StringPtr("testString"), + OrganizationID: core.StringPtr("testString"), + ResourceInstanceID: core.StringPtr("testString"), + ResourceID: core.StringPtr("testString"), + PlanID: core.StringPtr("testString"), + Region: core.StringPtr("testString"), } - orgUsage, response, err := usageReportsService.GetOrgUsage(getOrgUsageOptions) + // Test GetNext(). + pager, err := usageReportsService.NewGetResourceUsageAccountPager(getResourceUsageAccountOptions) + Expect(err).To(BeNil()) + Expect(pager).ToNot(BeNil()) + var allResults []usagereportsv4.InstanceUsage + for pager.HasNext() { + nextPage, err := pager.GetNext() + Expect(err).To(BeNil()) + Expect(nextPage).ToNot(BeNil()) + allResults = append(allResults, nextPage...) + } + + // Test GetAll(). + pager, err = usageReportsService.NewGetResourceUsageAccountPager(getResourceUsageAccountOptions) Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(orgUsage).ToNot(BeNil()) - fmt.Fprintf(GinkgoWriter, "\nGetOrgUsage response:\n%s", common.ToJSON(orgUsage)) + Expect(pager).ToNot(BeNil()) + + allItems, err := pager.GetAll() + Expect(err).To(BeNil()) + Expect(allItems).ToNot(BeNil()) - Expect(*orgUsage.AccountID).To(Equal(accountID)) - Expect(*orgUsage.Month).To(Equal(billingMonth)) - Expect(orgUsage.Resources).ToNot(BeEmpty()) + Expect(len(allItems)).To(Equal(len(allResults))) + fmt.Fprintf(GinkgoWriter, "GetResourceUsageAccount() returned a total of %d item(s) using GetResourceUsageAccountPager.\n", len(allResults)) }) }) - Describe(`GetResourceUsageAccount - Get resource instance usage in an account`, func() { + Describe(`GetResourceUsageResourceGroup - Get resource instance usage in a resource group`, func() { BeforeEach(func() { shouldSkipTest() }) - It(`GetResourceUsageAccount(getResourceUsageAccountOptions *GetResourceUsageAccountOptions)`, func() { - - // Retrieve results one page at a time. - getResourceUsageAccountOptions := &usagereportsv4.GetResourceUsageAccountOptions{ - AccountID: &accountID, - Billingmonth: &billingMonth, - Names: core.BoolPtr(true), - Limit: core.Int64Ptr(50), + It(`GetResourceUsageResourceGroup(getResourceUsageResourceGroupOptions *GetResourceUsageResourceGroupOptions) with pagination`, func(){ + getResourceUsageResourceGroupOptions := &usagereportsv4.GetResourceUsageResourceGroupOptions{ + AccountID: core.StringPtr("testString"), + ResourceGroupID: core.StringPtr("testString"), + Billingmonth: core.StringPtr("testString"), + Names: core.BoolPtr(true), + Tags: core.BoolPtr(true), + AcceptLanguage: core.StringPtr("testString"), + Limit: core.Int64Ptr(int64(30)), + Start: core.StringPtr("testString"), + ResourceInstanceID: core.StringPtr("testString"), + ResourceID: core.StringPtr("testString"), + PlanID: core.StringPtr("testString"), + Region: core.StringPtr("testString"), } - var results []usagereportsv4.InstanceUsage = make([]usagereportsv4.InstanceUsage, 0) - var offset *string = nil - var moreResults bool = true - - for moreResults { - // Set "Start" parameter for next page of results. - getResourceUsageAccountOptions.Start = offset + getResourceUsageResourceGroupOptions.Start = nil - instancesUsage, response, err := usageReportsService.GetResourceUsageAccount(getResourceUsageAccountOptions) + var allResults []usagereportsv4.InstanceUsage + for { + instancesUsage, response, err := usageReportsService.GetResourceUsageResourceGroup(getResourceUsageResourceGroupOptions) Expect(err).To(BeNil()) Expect(response.StatusCode).To(Equal(200)) Expect(instancesUsage).ToNot(BeNil()) + allResults = append(allResults, instancesUsage.Resources...) - // Add the just-retrieved page to the results. - if len(instancesUsage.Resources) > 0 { - results = append(results, instancesUsage.Resources...) - } + getResourceUsageResourceGroupOptions.Start, err = instancesUsage.GetNextStart() + Expect(err).To(BeNil()) - // Determine offset for next page of results. - if instancesUsage.Next != nil { - offset = instancesUsage.Next.Offset - } else { - offset = nil - moreResults = false + if getResourceUsageResourceGroupOptions.Start == nil { + break } } + fmt.Fprintf(GinkgoWriter, "Retrieved a total of %d item(s) with pagination.\n", len(allResults)) + }) + It(`GetResourceUsageResourceGroup(getResourceUsageResourceGroupOptions *GetResourceUsageResourceGroupOptions) using GetResourceUsageResourceGroupPager`, func(){ + getResourceUsageResourceGroupOptions := &usagereportsv4.GetResourceUsageResourceGroupOptions{ + AccountID: core.StringPtr("testString"), + ResourceGroupID: core.StringPtr("testString"), + Billingmonth: core.StringPtr("testString"), + Names: core.BoolPtr(true), + Tags: core.BoolPtr(true), + AcceptLanguage: core.StringPtr("testString"), + Limit: core.Int64Ptr(int64(30)), + ResourceInstanceID: core.StringPtr("testString"), + ResourceID: core.StringPtr("testString"), + PlanID: core.StringPtr("testString"), + Region: core.StringPtr("testString"), + } + + // Test GetNext(). + pager, err := usageReportsService.NewGetResourceUsageResourceGroupPager(getResourceUsageResourceGroupOptions) + Expect(err).To(BeNil()) + Expect(pager).ToNot(BeNil()) + + var allResults []usagereportsv4.InstanceUsage + for pager.HasNext() { + nextPage, err := pager.GetNext() + Expect(err).To(BeNil()) + Expect(nextPage).ToNot(BeNil()) + allResults = append(allResults, nextPage...) + } + + // Test GetAll(). + pager, err = usageReportsService.NewGetResourceUsageResourceGroupPager(getResourceUsageResourceGroupOptions) + Expect(err).To(BeNil()) + Expect(pager).ToNot(BeNil()) + + allItems, err := pager.GetAll() + Expect(err).To(BeNil()) + Expect(allItems).ToNot(BeNil()) - fmt.Fprintf(GinkgoWriter, "\nGetResourceUsageAccount response contained %d total resources.", len(results)) - Expect(results).ToNot(BeEmpty()) + Expect(len(allItems)).To(Equal(len(allResults))) + fmt.Fprintf(GinkgoWriter, "GetResourceUsageResourceGroup() returned a total of %d item(s) using GetResourceUsageResourceGroupPager.\n", len(allResults)) }) }) - Describe(`GetResourceUsageResourceGroup - Get resource instance usage in a resource group`, func() { + Describe(`GetResourceUsageOrg - Get resource instance usage in an organization`, func() { BeforeEach(func() { shouldSkipTest() }) - It(`GetResourceUsageResourceGroup(getResourceUsageResourceGroupOptions *GetResourceUsageResourceGroupOptions)`, func() { - - getResourceUsageResourceGroupOptions := &usagereportsv4.GetResourceUsageResourceGroupOptions{ - AccountID: &accountID, - ResourceGroupID: &resourceGroupID, - Billingmonth: &billingMonth, - Names: core.BoolPtr(true), - Limit: core.Int64Ptr(50), + It(`GetResourceUsageOrg(getResourceUsageOrgOptions *GetResourceUsageOrgOptions) with pagination`, func(){ + getResourceUsageOrgOptions := &usagereportsv4.GetResourceUsageOrgOptions{ + AccountID: core.StringPtr("testString"), + OrganizationID: core.StringPtr("testString"), + Billingmonth: core.StringPtr("testString"), + Names: core.BoolPtr(true), + Tags: core.BoolPtr(true), + AcceptLanguage: core.StringPtr("testString"), + Limit: core.Int64Ptr(int64(30)), + Start: core.StringPtr("testString"), + ResourceInstanceID: core.StringPtr("testString"), + ResourceID: core.StringPtr("testString"), + PlanID: core.StringPtr("testString"), + Region: core.StringPtr("testString"), } - var results []usagereportsv4.InstanceUsage = make([]usagereportsv4.InstanceUsage, 0) - var offset *string = nil - var moreResults bool = true - - for moreResults { - // Set "Start" parameter for next page of results. - getResourceUsageResourceGroupOptions.Start = offset - - instancesUsage, response, err := usageReportsService.GetResourceUsageResourceGroup(getResourceUsageResourceGroupOptions) + getResourceUsageOrgOptions.Start = nil + var allResults []usagereportsv4.InstanceUsage + for { + instancesUsage, response, err := usageReportsService.GetResourceUsageOrg(getResourceUsageOrgOptions) Expect(err).To(BeNil()) Expect(response.StatusCode).To(Equal(200)) Expect(instancesUsage).ToNot(BeNil()) + allResults = append(allResults, instancesUsage.Resources...) - // Add the just-retrieved page to the results. - if len(instancesUsage.Resources) > 0 { - results = append(results, instancesUsage.Resources...) - } + getResourceUsageOrgOptions.Start, err = instancesUsage.GetNextStart() + Expect(err).To(BeNil()) - // Determine offset for next page of results. - if instancesUsage.Next != nil { - offset = instancesUsage.Next.Offset - } else { - offset = nil - moreResults = false + if getResourceUsageOrgOptions.Start == nil { + break } } + fmt.Fprintf(GinkgoWriter, "Retrieved a total of %d item(s) with pagination.\n", len(allResults)) + }) + It(`GetResourceUsageOrg(getResourceUsageOrgOptions *GetResourceUsageOrgOptions) using GetResourceUsageOrgPager`, func(){ + getResourceUsageOrgOptions := &usagereportsv4.GetResourceUsageOrgOptions{ + AccountID: core.StringPtr("testString"), + OrganizationID: core.StringPtr("testString"), + Billingmonth: core.StringPtr("testString"), + Names: core.BoolPtr(true), + Tags: core.BoolPtr(true), + AcceptLanguage: core.StringPtr("testString"), + Limit: core.Int64Ptr(int64(30)), + ResourceInstanceID: core.StringPtr("testString"), + ResourceID: core.StringPtr("testString"), + PlanID: core.StringPtr("testString"), + Region: core.StringPtr("testString"), + } + + // Test GetNext(). + pager, err := usageReportsService.NewGetResourceUsageOrgPager(getResourceUsageOrgOptions) + Expect(err).To(BeNil()) + Expect(pager).ToNot(BeNil()) - fmt.Fprintf(GinkgoWriter, "\nGetResourceUsageResourceGroup response contained %d total resources.", len(results)) - Expect(results).ToNot(BeEmpty()) + var allResults []usagereportsv4.InstanceUsage + for pager.HasNext() { + nextPage, err := pager.GetNext() + Expect(err).To(BeNil()) + Expect(nextPage).ToNot(BeNil()) + allResults = append(allResults, nextPage...) + } + + // Test GetAll(). + pager, err = usageReportsService.NewGetResourceUsageOrgPager(getResourceUsageOrgOptions) + Expect(err).To(BeNil()) + Expect(pager).ToNot(BeNil()) + + allItems, err := pager.GetAll() + Expect(err).To(BeNil()) + Expect(allItems).ToNot(BeNil()) + + Expect(len(allItems)).To(Equal(len(allResults))) + fmt.Fprintf(GinkgoWriter, "GetResourceUsageOrg() returned a total of %d item(s) using GetResourceUsageOrgPager.\n", len(allResults)) }) }) - Describe(`GetResourceUsageOrg - Get resource instance usage in an organization`, func() { + Describe(`GetOrgUsage - Get organization usage`, func() { BeforeEach(func() { shouldSkipTest() }) - It(`GetResourceUsageOrg(getResourceUsageOrgOptions *GetResourceUsageOrgOptions)`, func() { + It(`GetOrgUsage(getOrgUsageOptions *GetOrgUsageOptions)`, func() { + getOrgUsageOptions := &usagereportsv4.GetOrgUsageOptions{ + AccountID: core.StringPtr("testString"), + OrganizationID: core.StringPtr("testString"), + Billingmonth: core.StringPtr("testString"), + Names: core.BoolPtr(true), + AcceptLanguage: core.StringPtr("testString"), + } - getResourceUsageOrgOptions := &usagereportsv4.GetResourceUsageOrgOptions{ - AccountID: &accountID, - OrganizationID: &orgID, - Billingmonth: &billingMonth, - Names: core.BoolPtr(true), - Limit: core.Int64Ptr(50), + orgUsage, response, err := usageReportsService.GetOrgUsage(getOrgUsageOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(orgUsage).ToNot(BeNil()) + }) + }) + + Describe(`CreateReportsSnapshotConfig - Setup the snapshot configuration`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`CreateReportsSnapshotConfig(createReportsSnapshotConfigOptions *CreateReportsSnapshotConfigOptions)`, func() { + createReportsSnapshotConfigOptions := &usagereportsv4.CreateReportsSnapshotConfigOptions{ + AccountID: core.StringPtr("abc"), + Interval: core.StringPtr("daily"), + CosBucket: core.StringPtr("bucket_name"), + CosLocation: core.StringPtr("us-south"), + CosReportsFolder: core.StringPtr("IBMCloud-Billing-Reports"), + ReportTypes: []string{"account_summary", "enterprise_summary", "account_resource_instance_usage"}, + Versioning: core.StringPtr("new"), } - var results []usagereportsv4.InstanceUsage = make([]usagereportsv4.InstanceUsage, 0) - var offset *string = nil - var moreResults bool = true + snapshotConfig, response, err := usageReportsService.CreateReportsSnapshotConfig(createReportsSnapshotConfigOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(201)) + Expect(snapshotConfig).ToNot(BeNil()) + }) + }) - for moreResults { - // Set "Start" parameter for next page of results. - getResourceUsageOrgOptions.Start = offset + Describe(`GetReportsSnapshotConfig - Fetch the snapshot configuration`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`GetReportsSnapshotConfig(getReportsSnapshotConfigOptions *GetReportsSnapshotConfigOptions)`, func() { + getReportsSnapshotConfigOptions := &usagereportsv4.GetReportsSnapshotConfigOptions{ + AccountID: core.StringPtr("abc"), + } - instancesUsage, response, err := usageReportsService.GetResourceUsageOrg(getResourceUsageOrgOptions) + snapshotConfig, response, err := usageReportsService.GetReportsSnapshotConfig(getReportsSnapshotConfigOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(snapshotConfig).ToNot(BeNil()) + }) + }) - Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(instancesUsage).ToNot(BeNil()) + Describe(`UpdateReportsSnapshotConfig - Update the snapshot configuration`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`UpdateReportsSnapshotConfig(updateReportsSnapshotConfigOptions *UpdateReportsSnapshotConfigOptions)`, func() { + updateReportsSnapshotConfigOptions := &usagereportsv4.UpdateReportsSnapshotConfigOptions{ + AccountID: core.StringPtr("abc"), + Interval: core.StringPtr("daily"), + CosBucket: core.StringPtr("bucket_name"), + CosLocation: core.StringPtr("us-south"), + CosReportsFolder: core.StringPtr("IBMCloud-Billing-Reports"), + ReportTypes: []string{"account_summary", "enterprise_summary", "account_resource_instance_usage"}, + Versioning: core.StringPtr("new"), + } - // Add the just-retrieved page to the results. - if len(instancesUsage.Resources) > 0 { - results = append(results, instancesUsage.Resources...) - } + snapshotConfig, response, err := usageReportsService.UpdateReportsSnapshotConfig(updateReportsSnapshotConfigOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(snapshotConfig).ToNot(BeNil()) + }) + }) - // Determine offset for next page of results. - if instancesUsage.Next != nil { - offset = instancesUsage.Next.Offset - } else { - offset = nil - moreResults = false - } + Describe(`GetReportsSnapshot - Fetch the current or past snapshots`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`GetReportsSnapshot(getReportsSnapshotOptions *GetReportsSnapshotOptions)`, func() { + getReportsSnapshotOptions := &usagereportsv4.GetReportsSnapshotOptions{ + AccountID: core.StringPtr("abc"), + Month: core.StringPtr("2023-02"), + DateFrom: core.Float64Ptr(float64(1675209600000)), + DateTo: core.Float64Ptr(float64(1675987200000)), + } + + snapshotList, response, err := usageReportsService.GetReportsSnapshot(getReportsSnapshotOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(snapshotList).ToNot(BeNil()) + }) + }) + + Describe(`DeleteReportsSnapshotConfig - Delete the snapshot configuration`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`DeleteReportsSnapshotConfig(deleteReportsSnapshotConfigOptions *DeleteReportsSnapshotConfigOptions)`, func() { + deleteReportsSnapshotConfigOptions := &usagereportsv4.DeleteReportsSnapshotConfigOptions{ + AccountID: core.StringPtr("abc"), } - fmt.Fprintf(GinkgoWriter, "\nGetResourceUsageOrg response contained %d total resources.", len(results)) - fmt.Fprintf(GinkgoWriter, "\nGetResourceUsageOrg response: %s\n", common.ToJSON(results)) - Expect(results).ToNot(BeEmpty()) + response, err := usageReportsService.DeleteReportsSnapshotConfig(deleteReportsSnapshotConfigOptions) + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(204)) }) }) }) + +// +// Utility functions are declared in the unit test file +// diff --git a/usagereportsv4/usage_reports_v4_test.go b/usagereportsv4/usage_reports_v4_test.go index 66e2e6c2..91d2b41a 100644 --- a/usagereportsv4/usage_reports_v4_test.go +++ b/usagereportsv4/usage_reports_v4_test.go @@ -870,7 +870,8 @@ var _ = Describe(`UsageReportsV4`, func() { Expect(req.Header["Accept-Language"]).ToNot(BeNil()) Expect(req.Header["Accept-Language"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) // TODO: Add check for _names query parameter - Expect(req.URL.Query()["_limit"]).To(Equal([]string{fmt.Sprint(int64(1))})) + // TODO: Add check for _tags query parameter + Expect(req.URL.Query()["_limit"]).To(Equal([]string{fmt.Sprint(int64(30))})) Expect(req.URL.Query()["_start"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["resource_group_id"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["organization_id"]).To(Equal([]string{"testString"})) @@ -896,8 +897,9 @@ var _ = Describe(`UsageReportsV4`, func() { getResourceUsageAccountOptionsModel.AccountID = core.StringPtr("testString") getResourceUsageAccountOptionsModel.Billingmonth = core.StringPtr("testString") getResourceUsageAccountOptionsModel.Names = core.BoolPtr(true) + getResourceUsageAccountOptionsModel.Tags = core.BoolPtr(true) getResourceUsageAccountOptionsModel.AcceptLanguage = core.StringPtr("testString") - getResourceUsageAccountOptionsModel.Limit = core.Int64Ptr(int64(1)) + getResourceUsageAccountOptionsModel.Limit = core.Int64Ptr(int64(30)) getResourceUsageAccountOptionsModel.Start = core.StringPtr("testString") getResourceUsageAccountOptionsModel.ResourceGroupID = core.StringPtr("testString") getResourceUsageAccountOptionsModel.OrganizationID = core.StringPtr("testString") @@ -938,7 +940,8 @@ var _ = Describe(`UsageReportsV4`, func() { Expect(req.Header["Accept-Language"]).ToNot(BeNil()) Expect(req.Header["Accept-Language"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) // TODO: Add check for _names query parameter - Expect(req.URL.Query()["_limit"]).To(Equal([]string{fmt.Sprint(int64(1))})) + // TODO: Add check for _tags query parameter + Expect(req.URL.Query()["_limit"]).To(Equal([]string{fmt.Sprint(int64(30))})) Expect(req.URL.Query()["_start"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["resource_group_id"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["organization_id"]).To(Equal([]string{"testString"})) @@ -952,7 +955,7 @@ var _ = Describe(`UsageReportsV4`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"limit": 5, "count": 5, "first": {"href": "Href"}, "next": {"href": "Href", "offset": "Offset"}, "resources": [{"account_id": "AccountID", "resource_instance_id": "ResourceInstanceID", "resource_instance_name": "ResourceInstanceName", "resource_id": "ResourceID", "resource_name": "ResourceName", "resource_group_id": "ResourceGroupID", "resource_group_name": "ResourceGroupName", "organization_id": "OrganizationID", "organization_name": "OrganizationName", "space_id": "SpaceID", "space_name": "SpaceName", "consumer_id": "ConsumerID", "region": "Region", "pricing_region": "PricingRegion", "pricing_country": "USA", "currency_code": "USD", "billable": true, "plan_id": "PlanID", "plan_name": "PlanName", "month": "2017-08", "usage": [{"metric": "UP-TIME", "metric_name": "UP-TIME", "quantity": 711.11, "rateable_quantity": 700, "cost": 123.45, "rated_cost": 130.0, "price": ["anyValue"], "unit": "HOURS", "unit_name": "HOURS", "non_chargeable": true, "discounts": [{"ref": "Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9", "name": "platform-discount", "display_name": "Platform Service Discount", "discount": 5}]}], "pending": true, "currency_rate": 10.8716}]}`) + fmt.Fprintf(res, "%s", `{"limit": 5, "count": 5, "first": {"href": "Href"}, "next": {"href": "Href", "offset": "Offset"}, "resources": [{"account_id": "AccountID", "resource_instance_id": "ResourceInstanceID", "resource_instance_name": "ResourceInstanceName", "resource_id": "ResourceID", "resource_name": "ResourceName", "resource_group_id": "ResourceGroupID", "resource_group_name": "ResourceGroupName", "organization_id": "OrganizationID", "organization_name": "OrganizationName", "space_id": "SpaceID", "space_name": "SpaceName", "consumer_id": "ConsumerID", "region": "Region", "pricing_region": "PricingRegion", "pricing_country": "USA", "currency_code": "USD", "billable": true, "plan_id": "PlanID", "plan_name": "PlanName", "pricing_plan_id": "PricingPlanID", "month": "2017-08", "usage": [{"metric": "UP-TIME", "metric_name": "UP-TIME", "quantity": 711.11, "rateable_quantity": 700, "cost": 123.45, "rated_cost": 130.0, "price": ["anyValue"], "unit": "HOURS", "unit_name": "HOURS", "non_chargeable": true, "discounts": [{"ref": "Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9", "name": "platform-discount", "display_name": "Platform Service Discount", "discount": 5}]}], "pending": true, "currency_rate": 10.8716, "tags": ["anyValue"]}]}`) })) }) It(`Invoke GetResourceUsageAccount successfully with retries`, func() { @@ -969,8 +972,9 @@ var _ = Describe(`UsageReportsV4`, func() { getResourceUsageAccountOptionsModel.AccountID = core.StringPtr("testString") getResourceUsageAccountOptionsModel.Billingmonth = core.StringPtr("testString") getResourceUsageAccountOptionsModel.Names = core.BoolPtr(true) + getResourceUsageAccountOptionsModel.Tags = core.BoolPtr(true) getResourceUsageAccountOptionsModel.AcceptLanguage = core.StringPtr("testString") - getResourceUsageAccountOptionsModel.Limit = core.Int64Ptr(int64(1)) + getResourceUsageAccountOptionsModel.Limit = core.Int64Ptr(int64(30)) getResourceUsageAccountOptionsModel.Start = core.StringPtr("testString") getResourceUsageAccountOptionsModel.ResourceGroupID = core.StringPtr("testString") getResourceUsageAccountOptionsModel.OrganizationID = core.StringPtr("testString") @@ -1017,7 +1021,8 @@ var _ = Describe(`UsageReportsV4`, func() { Expect(req.Header["Accept-Language"]).ToNot(BeNil()) Expect(req.Header["Accept-Language"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) // TODO: Add check for _names query parameter - Expect(req.URL.Query()["_limit"]).To(Equal([]string{fmt.Sprint(int64(1))})) + // TODO: Add check for _tags query parameter + Expect(req.URL.Query()["_limit"]).To(Equal([]string{fmt.Sprint(int64(30))})) Expect(req.URL.Query()["_start"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["resource_group_id"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["organization_id"]).To(Equal([]string{"testString"})) @@ -1028,7 +1033,7 @@ var _ = Describe(`UsageReportsV4`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"limit": 5, "count": 5, "first": {"href": "Href"}, "next": {"href": "Href", "offset": "Offset"}, "resources": [{"account_id": "AccountID", "resource_instance_id": "ResourceInstanceID", "resource_instance_name": "ResourceInstanceName", "resource_id": "ResourceID", "resource_name": "ResourceName", "resource_group_id": "ResourceGroupID", "resource_group_name": "ResourceGroupName", "organization_id": "OrganizationID", "organization_name": "OrganizationName", "space_id": "SpaceID", "space_name": "SpaceName", "consumer_id": "ConsumerID", "region": "Region", "pricing_region": "PricingRegion", "pricing_country": "USA", "currency_code": "USD", "billable": true, "plan_id": "PlanID", "plan_name": "PlanName", "month": "2017-08", "usage": [{"metric": "UP-TIME", "metric_name": "UP-TIME", "quantity": 711.11, "rateable_quantity": 700, "cost": 123.45, "rated_cost": 130.0, "price": ["anyValue"], "unit": "HOURS", "unit_name": "HOURS", "non_chargeable": true, "discounts": [{"ref": "Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9", "name": "platform-discount", "display_name": "Platform Service Discount", "discount": 5}]}], "pending": true, "currency_rate": 10.8716}]}`) + fmt.Fprintf(res, "%s", `{"limit": 5, "count": 5, "first": {"href": "Href"}, "next": {"href": "Href", "offset": "Offset"}, "resources": [{"account_id": "AccountID", "resource_instance_id": "ResourceInstanceID", "resource_instance_name": "ResourceInstanceName", "resource_id": "ResourceID", "resource_name": "ResourceName", "resource_group_id": "ResourceGroupID", "resource_group_name": "ResourceGroupName", "organization_id": "OrganizationID", "organization_name": "OrganizationName", "space_id": "SpaceID", "space_name": "SpaceName", "consumer_id": "ConsumerID", "region": "Region", "pricing_region": "PricingRegion", "pricing_country": "USA", "currency_code": "USD", "billable": true, "plan_id": "PlanID", "plan_name": "PlanName", "pricing_plan_id": "PricingPlanID", "month": "2017-08", "usage": [{"metric": "UP-TIME", "metric_name": "UP-TIME", "quantity": 711.11, "rateable_quantity": 700, "cost": 123.45, "rated_cost": 130.0, "price": ["anyValue"], "unit": "HOURS", "unit_name": "HOURS", "non_chargeable": true, "discounts": [{"ref": "Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9", "name": "platform-discount", "display_name": "Platform Service Discount", "discount": 5}]}], "pending": true, "currency_rate": 10.8716, "tags": ["anyValue"]}]}`) })) }) It(`Invoke GetResourceUsageAccount successfully`, func() { @@ -1050,8 +1055,9 @@ var _ = Describe(`UsageReportsV4`, func() { getResourceUsageAccountOptionsModel.AccountID = core.StringPtr("testString") getResourceUsageAccountOptionsModel.Billingmonth = core.StringPtr("testString") getResourceUsageAccountOptionsModel.Names = core.BoolPtr(true) + getResourceUsageAccountOptionsModel.Tags = core.BoolPtr(true) getResourceUsageAccountOptionsModel.AcceptLanguage = core.StringPtr("testString") - getResourceUsageAccountOptionsModel.Limit = core.Int64Ptr(int64(1)) + getResourceUsageAccountOptionsModel.Limit = core.Int64Ptr(int64(30)) getResourceUsageAccountOptionsModel.Start = core.StringPtr("testString") getResourceUsageAccountOptionsModel.ResourceGroupID = core.StringPtr("testString") getResourceUsageAccountOptionsModel.OrganizationID = core.StringPtr("testString") @@ -1081,8 +1087,9 @@ var _ = Describe(`UsageReportsV4`, func() { getResourceUsageAccountOptionsModel.AccountID = core.StringPtr("testString") getResourceUsageAccountOptionsModel.Billingmonth = core.StringPtr("testString") getResourceUsageAccountOptionsModel.Names = core.BoolPtr(true) + getResourceUsageAccountOptionsModel.Tags = core.BoolPtr(true) getResourceUsageAccountOptionsModel.AcceptLanguage = core.StringPtr("testString") - getResourceUsageAccountOptionsModel.Limit = core.Int64Ptr(int64(1)) + getResourceUsageAccountOptionsModel.Limit = core.Int64Ptr(int64(30)) getResourceUsageAccountOptionsModel.Start = core.StringPtr("testString") getResourceUsageAccountOptionsModel.ResourceGroupID = core.StringPtr("testString") getResourceUsageAccountOptionsModel.OrganizationID = core.StringPtr("testString") @@ -1133,8 +1140,9 @@ var _ = Describe(`UsageReportsV4`, func() { getResourceUsageAccountOptionsModel.AccountID = core.StringPtr("testString") getResourceUsageAccountOptionsModel.Billingmonth = core.StringPtr("testString") getResourceUsageAccountOptionsModel.Names = core.BoolPtr(true) + getResourceUsageAccountOptionsModel.Tags = core.BoolPtr(true) getResourceUsageAccountOptionsModel.AcceptLanguage = core.StringPtr("testString") - getResourceUsageAccountOptionsModel.Limit = core.Int64Ptr(int64(1)) + getResourceUsageAccountOptionsModel.Limit = core.Int64Ptr(int64(30)) getResourceUsageAccountOptionsModel.Start = core.StringPtr("testString") getResourceUsageAccountOptionsModel.ResourceGroupID = core.StringPtr("testString") getResourceUsageAccountOptionsModel.OrganizationID = core.StringPtr("testString") @@ -1200,9 +1208,9 @@ var _ = Describe(`UsageReportsV4`, func() { res.WriteHeader(200) requestNumber++ if requestNumber == 1 { - fmt.Fprintf(res, "%s", `{"next":{"href":"https://myhost.com/somePath?_start=1"},"total_count":2,"limit":1,"resources":[{"account_id":"AccountID","resource_instance_id":"ResourceInstanceID","resource_instance_name":"ResourceInstanceName","resource_id":"ResourceID","resource_name":"ResourceName","resource_group_id":"ResourceGroupID","resource_group_name":"ResourceGroupName","organization_id":"OrganizationID","organization_name":"OrganizationName","space_id":"SpaceID","space_name":"SpaceName","consumer_id":"ConsumerID","region":"Region","pricing_region":"PricingRegion","pricing_country":"USA","currency_code":"USD","billable":true,"plan_id":"PlanID","plan_name":"PlanName","month":"2017-08","usage":[{"metric":"UP-TIME","metric_name":"UP-TIME","quantity":711.11,"rateable_quantity":700,"cost":123.45,"rated_cost":130.0,"price":["anyValue"],"unit":"HOURS","unit_name":"HOURS","non_chargeable":true,"discounts":[{"ref":"Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9","name":"platform-discount","display_name":"Platform Service Discount","discount":5}]}],"pending":true,"currency_rate":10.8716}]}`) + fmt.Fprintf(res, "%s", `{"next":{"href":"https://myhost.com/somePath?_start=1"},"total_count":2,"limit":1,"resources":[{"account_id":"AccountID","resource_instance_id":"ResourceInstanceID","resource_instance_name":"ResourceInstanceName","resource_id":"ResourceID","resource_name":"ResourceName","resource_group_id":"ResourceGroupID","resource_group_name":"ResourceGroupName","organization_id":"OrganizationID","organization_name":"OrganizationName","space_id":"SpaceID","space_name":"SpaceName","consumer_id":"ConsumerID","region":"Region","pricing_region":"PricingRegion","pricing_country":"USA","currency_code":"USD","billable":true,"plan_id":"PlanID","plan_name":"PlanName","pricing_plan_id":"PricingPlanID","month":"2017-08","usage":[{"metric":"UP-TIME","metric_name":"UP-TIME","quantity":711.11,"rateable_quantity":700,"cost":123.45,"rated_cost":130.0,"price":["anyValue"],"unit":"HOURS","unit_name":"HOURS","non_chargeable":true,"discounts":[{"ref":"Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9","name":"platform-discount","display_name":"Platform Service Discount","discount":5}]}],"pending":true,"currency_rate":10.8716,"tags":["anyValue"]}]}`) } else if requestNumber == 2 { - fmt.Fprintf(res, "%s", `{"total_count":2,"limit":1,"resources":[{"account_id":"AccountID","resource_instance_id":"ResourceInstanceID","resource_instance_name":"ResourceInstanceName","resource_id":"ResourceID","resource_name":"ResourceName","resource_group_id":"ResourceGroupID","resource_group_name":"ResourceGroupName","organization_id":"OrganizationID","organization_name":"OrganizationName","space_id":"SpaceID","space_name":"SpaceName","consumer_id":"ConsumerID","region":"Region","pricing_region":"PricingRegion","pricing_country":"USA","currency_code":"USD","billable":true,"plan_id":"PlanID","plan_name":"PlanName","month":"2017-08","usage":[{"metric":"UP-TIME","metric_name":"UP-TIME","quantity":711.11,"rateable_quantity":700,"cost":123.45,"rated_cost":130.0,"price":["anyValue"],"unit":"HOURS","unit_name":"HOURS","non_chargeable":true,"discounts":[{"ref":"Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9","name":"platform-discount","display_name":"Platform Service Discount","discount":5}]}],"pending":true,"currency_rate":10.8716}]}`) + fmt.Fprintf(res, "%s", `{"total_count":2,"limit":1,"resources":[{"account_id":"AccountID","resource_instance_id":"ResourceInstanceID","resource_instance_name":"ResourceInstanceName","resource_id":"ResourceID","resource_name":"ResourceName","resource_group_id":"ResourceGroupID","resource_group_name":"ResourceGroupName","organization_id":"OrganizationID","organization_name":"OrganizationName","space_id":"SpaceID","space_name":"SpaceName","consumer_id":"ConsumerID","region":"Region","pricing_region":"PricingRegion","pricing_country":"USA","currency_code":"USD","billable":true,"plan_id":"PlanID","plan_name":"PlanName","pricing_plan_id":"PricingPlanID","month":"2017-08","usage":[{"metric":"UP-TIME","metric_name":"UP-TIME","quantity":711.11,"rateable_quantity":700,"cost":123.45,"rated_cost":130.0,"price":["anyValue"],"unit":"HOURS","unit_name":"HOURS","non_chargeable":true,"discounts":[{"ref":"Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9","name":"platform-discount","display_name":"Platform Service Discount","discount":5}]}],"pending":true,"currency_rate":10.8716,"tags":["anyValue"]}]}`) } else { res.WriteHeader(400) } @@ -1220,8 +1228,9 @@ var _ = Describe(`UsageReportsV4`, func() { AccountID: core.StringPtr("testString"), Billingmonth: core.StringPtr("testString"), Names: core.BoolPtr(true), + Tags: core.BoolPtr(true), AcceptLanguage: core.StringPtr("testString"), - Limit: core.Int64Ptr(int64(1)), + Limit: core.Int64Ptr(int64(30)), ResourceGroupID: core.StringPtr("testString"), OrganizationID: core.StringPtr("testString"), ResourceInstanceID: core.StringPtr("testString"), @@ -1255,8 +1264,9 @@ var _ = Describe(`UsageReportsV4`, func() { AccountID: core.StringPtr("testString"), Billingmonth: core.StringPtr("testString"), Names: core.BoolPtr(true), + Tags: core.BoolPtr(true), AcceptLanguage: core.StringPtr("testString"), - Limit: core.Int64Ptr(int64(1)), + Limit: core.Int64Ptr(int64(30)), ResourceGroupID: core.StringPtr("testString"), OrganizationID: core.StringPtr("testString"), ResourceInstanceID: core.StringPtr("testString"), @@ -1289,7 +1299,8 @@ var _ = Describe(`UsageReportsV4`, func() { Expect(req.Header["Accept-Language"]).ToNot(BeNil()) Expect(req.Header["Accept-Language"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) // TODO: Add check for _names query parameter - Expect(req.URL.Query()["_limit"]).To(Equal([]string{fmt.Sprint(int64(1))})) + // TODO: Add check for _tags query parameter + Expect(req.URL.Query()["_limit"]).To(Equal([]string{fmt.Sprint(int64(30))})) Expect(req.URL.Query()["_start"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["resource_instance_id"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["resource_id"]).To(Equal([]string{"testString"})) @@ -1314,8 +1325,9 @@ var _ = Describe(`UsageReportsV4`, func() { getResourceUsageResourceGroupOptionsModel.ResourceGroupID = core.StringPtr("testString") getResourceUsageResourceGroupOptionsModel.Billingmonth = core.StringPtr("testString") getResourceUsageResourceGroupOptionsModel.Names = core.BoolPtr(true) + getResourceUsageResourceGroupOptionsModel.Tags = core.BoolPtr(true) getResourceUsageResourceGroupOptionsModel.AcceptLanguage = core.StringPtr("testString") - getResourceUsageResourceGroupOptionsModel.Limit = core.Int64Ptr(int64(1)) + getResourceUsageResourceGroupOptionsModel.Limit = core.Int64Ptr(int64(30)) getResourceUsageResourceGroupOptionsModel.Start = core.StringPtr("testString") getResourceUsageResourceGroupOptionsModel.ResourceInstanceID = core.StringPtr("testString") getResourceUsageResourceGroupOptionsModel.ResourceID = core.StringPtr("testString") @@ -1354,7 +1366,8 @@ var _ = Describe(`UsageReportsV4`, func() { Expect(req.Header["Accept-Language"]).ToNot(BeNil()) Expect(req.Header["Accept-Language"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) // TODO: Add check for _names query parameter - Expect(req.URL.Query()["_limit"]).To(Equal([]string{fmt.Sprint(int64(1))})) + // TODO: Add check for _tags query parameter + Expect(req.URL.Query()["_limit"]).To(Equal([]string{fmt.Sprint(int64(30))})) Expect(req.URL.Query()["_start"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["resource_instance_id"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["resource_id"]).To(Equal([]string{"testString"})) @@ -1366,7 +1379,7 @@ var _ = Describe(`UsageReportsV4`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"limit": 5, "count": 5, "first": {"href": "Href"}, "next": {"href": "Href", "offset": "Offset"}, "resources": [{"account_id": "AccountID", "resource_instance_id": "ResourceInstanceID", "resource_instance_name": "ResourceInstanceName", "resource_id": "ResourceID", "resource_name": "ResourceName", "resource_group_id": "ResourceGroupID", "resource_group_name": "ResourceGroupName", "organization_id": "OrganizationID", "organization_name": "OrganizationName", "space_id": "SpaceID", "space_name": "SpaceName", "consumer_id": "ConsumerID", "region": "Region", "pricing_region": "PricingRegion", "pricing_country": "USA", "currency_code": "USD", "billable": true, "plan_id": "PlanID", "plan_name": "PlanName", "month": "2017-08", "usage": [{"metric": "UP-TIME", "metric_name": "UP-TIME", "quantity": 711.11, "rateable_quantity": 700, "cost": 123.45, "rated_cost": 130.0, "price": ["anyValue"], "unit": "HOURS", "unit_name": "HOURS", "non_chargeable": true, "discounts": [{"ref": "Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9", "name": "platform-discount", "display_name": "Platform Service Discount", "discount": 5}]}], "pending": true, "currency_rate": 10.8716}]}`) + fmt.Fprintf(res, "%s", `{"limit": 5, "count": 5, "first": {"href": "Href"}, "next": {"href": "Href", "offset": "Offset"}, "resources": [{"account_id": "AccountID", "resource_instance_id": "ResourceInstanceID", "resource_instance_name": "ResourceInstanceName", "resource_id": "ResourceID", "resource_name": "ResourceName", "resource_group_id": "ResourceGroupID", "resource_group_name": "ResourceGroupName", "organization_id": "OrganizationID", "organization_name": "OrganizationName", "space_id": "SpaceID", "space_name": "SpaceName", "consumer_id": "ConsumerID", "region": "Region", "pricing_region": "PricingRegion", "pricing_country": "USA", "currency_code": "USD", "billable": true, "plan_id": "PlanID", "plan_name": "PlanName", "pricing_plan_id": "PricingPlanID", "month": "2017-08", "usage": [{"metric": "UP-TIME", "metric_name": "UP-TIME", "quantity": 711.11, "rateable_quantity": 700, "cost": 123.45, "rated_cost": 130.0, "price": ["anyValue"], "unit": "HOURS", "unit_name": "HOURS", "non_chargeable": true, "discounts": [{"ref": "Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9", "name": "platform-discount", "display_name": "Platform Service Discount", "discount": 5}]}], "pending": true, "currency_rate": 10.8716, "tags": ["anyValue"]}]}`) })) }) It(`Invoke GetResourceUsageResourceGroup successfully with retries`, func() { @@ -1384,8 +1397,9 @@ var _ = Describe(`UsageReportsV4`, func() { getResourceUsageResourceGroupOptionsModel.ResourceGroupID = core.StringPtr("testString") getResourceUsageResourceGroupOptionsModel.Billingmonth = core.StringPtr("testString") getResourceUsageResourceGroupOptionsModel.Names = core.BoolPtr(true) + getResourceUsageResourceGroupOptionsModel.Tags = core.BoolPtr(true) getResourceUsageResourceGroupOptionsModel.AcceptLanguage = core.StringPtr("testString") - getResourceUsageResourceGroupOptionsModel.Limit = core.Int64Ptr(int64(1)) + getResourceUsageResourceGroupOptionsModel.Limit = core.Int64Ptr(int64(30)) getResourceUsageResourceGroupOptionsModel.Start = core.StringPtr("testString") getResourceUsageResourceGroupOptionsModel.ResourceInstanceID = core.StringPtr("testString") getResourceUsageResourceGroupOptionsModel.ResourceID = core.StringPtr("testString") @@ -1430,7 +1444,8 @@ var _ = Describe(`UsageReportsV4`, func() { Expect(req.Header["Accept-Language"]).ToNot(BeNil()) Expect(req.Header["Accept-Language"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) // TODO: Add check for _names query parameter - Expect(req.URL.Query()["_limit"]).To(Equal([]string{fmt.Sprint(int64(1))})) + // TODO: Add check for _tags query parameter + Expect(req.URL.Query()["_limit"]).To(Equal([]string{fmt.Sprint(int64(30))})) Expect(req.URL.Query()["_start"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["resource_instance_id"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["resource_id"]).To(Equal([]string{"testString"})) @@ -1439,7 +1454,7 @@ var _ = Describe(`UsageReportsV4`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"limit": 5, "count": 5, "first": {"href": "Href"}, "next": {"href": "Href", "offset": "Offset"}, "resources": [{"account_id": "AccountID", "resource_instance_id": "ResourceInstanceID", "resource_instance_name": "ResourceInstanceName", "resource_id": "ResourceID", "resource_name": "ResourceName", "resource_group_id": "ResourceGroupID", "resource_group_name": "ResourceGroupName", "organization_id": "OrganizationID", "organization_name": "OrganizationName", "space_id": "SpaceID", "space_name": "SpaceName", "consumer_id": "ConsumerID", "region": "Region", "pricing_region": "PricingRegion", "pricing_country": "USA", "currency_code": "USD", "billable": true, "plan_id": "PlanID", "plan_name": "PlanName", "month": "2017-08", "usage": [{"metric": "UP-TIME", "metric_name": "UP-TIME", "quantity": 711.11, "rateable_quantity": 700, "cost": 123.45, "rated_cost": 130.0, "price": ["anyValue"], "unit": "HOURS", "unit_name": "HOURS", "non_chargeable": true, "discounts": [{"ref": "Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9", "name": "platform-discount", "display_name": "Platform Service Discount", "discount": 5}]}], "pending": true, "currency_rate": 10.8716}]}`) + fmt.Fprintf(res, "%s", `{"limit": 5, "count": 5, "first": {"href": "Href"}, "next": {"href": "Href", "offset": "Offset"}, "resources": [{"account_id": "AccountID", "resource_instance_id": "ResourceInstanceID", "resource_instance_name": "ResourceInstanceName", "resource_id": "ResourceID", "resource_name": "ResourceName", "resource_group_id": "ResourceGroupID", "resource_group_name": "ResourceGroupName", "organization_id": "OrganizationID", "organization_name": "OrganizationName", "space_id": "SpaceID", "space_name": "SpaceName", "consumer_id": "ConsumerID", "region": "Region", "pricing_region": "PricingRegion", "pricing_country": "USA", "currency_code": "USD", "billable": true, "plan_id": "PlanID", "plan_name": "PlanName", "pricing_plan_id": "PricingPlanID", "month": "2017-08", "usage": [{"metric": "UP-TIME", "metric_name": "UP-TIME", "quantity": 711.11, "rateable_quantity": 700, "cost": 123.45, "rated_cost": 130.0, "price": ["anyValue"], "unit": "HOURS", "unit_name": "HOURS", "non_chargeable": true, "discounts": [{"ref": "Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9", "name": "platform-discount", "display_name": "Platform Service Discount", "discount": 5}]}], "pending": true, "currency_rate": 10.8716, "tags": ["anyValue"]}]}`) })) }) It(`Invoke GetResourceUsageResourceGroup successfully`, func() { @@ -1462,8 +1477,9 @@ var _ = Describe(`UsageReportsV4`, func() { getResourceUsageResourceGroupOptionsModel.ResourceGroupID = core.StringPtr("testString") getResourceUsageResourceGroupOptionsModel.Billingmonth = core.StringPtr("testString") getResourceUsageResourceGroupOptionsModel.Names = core.BoolPtr(true) + getResourceUsageResourceGroupOptionsModel.Tags = core.BoolPtr(true) getResourceUsageResourceGroupOptionsModel.AcceptLanguage = core.StringPtr("testString") - getResourceUsageResourceGroupOptionsModel.Limit = core.Int64Ptr(int64(1)) + getResourceUsageResourceGroupOptionsModel.Limit = core.Int64Ptr(int64(30)) getResourceUsageResourceGroupOptionsModel.Start = core.StringPtr("testString") getResourceUsageResourceGroupOptionsModel.ResourceInstanceID = core.StringPtr("testString") getResourceUsageResourceGroupOptionsModel.ResourceID = core.StringPtr("testString") @@ -1492,8 +1508,9 @@ var _ = Describe(`UsageReportsV4`, func() { getResourceUsageResourceGroupOptionsModel.ResourceGroupID = core.StringPtr("testString") getResourceUsageResourceGroupOptionsModel.Billingmonth = core.StringPtr("testString") getResourceUsageResourceGroupOptionsModel.Names = core.BoolPtr(true) + getResourceUsageResourceGroupOptionsModel.Tags = core.BoolPtr(true) getResourceUsageResourceGroupOptionsModel.AcceptLanguage = core.StringPtr("testString") - getResourceUsageResourceGroupOptionsModel.Limit = core.Int64Ptr(int64(1)) + getResourceUsageResourceGroupOptionsModel.Limit = core.Int64Ptr(int64(30)) getResourceUsageResourceGroupOptionsModel.Start = core.StringPtr("testString") getResourceUsageResourceGroupOptionsModel.ResourceInstanceID = core.StringPtr("testString") getResourceUsageResourceGroupOptionsModel.ResourceID = core.StringPtr("testString") @@ -1543,8 +1560,9 @@ var _ = Describe(`UsageReportsV4`, func() { getResourceUsageResourceGroupOptionsModel.ResourceGroupID = core.StringPtr("testString") getResourceUsageResourceGroupOptionsModel.Billingmonth = core.StringPtr("testString") getResourceUsageResourceGroupOptionsModel.Names = core.BoolPtr(true) + getResourceUsageResourceGroupOptionsModel.Tags = core.BoolPtr(true) getResourceUsageResourceGroupOptionsModel.AcceptLanguage = core.StringPtr("testString") - getResourceUsageResourceGroupOptionsModel.Limit = core.Int64Ptr(int64(1)) + getResourceUsageResourceGroupOptionsModel.Limit = core.Int64Ptr(int64(30)) getResourceUsageResourceGroupOptionsModel.Start = core.StringPtr("testString") getResourceUsageResourceGroupOptionsModel.ResourceInstanceID = core.StringPtr("testString") getResourceUsageResourceGroupOptionsModel.ResourceID = core.StringPtr("testString") @@ -1608,9 +1626,9 @@ var _ = Describe(`UsageReportsV4`, func() { res.WriteHeader(200) requestNumber++ if requestNumber == 1 { - fmt.Fprintf(res, "%s", `{"next":{"href":"https://myhost.com/somePath?_start=1"},"total_count":2,"limit":1,"resources":[{"account_id":"AccountID","resource_instance_id":"ResourceInstanceID","resource_instance_name":"ResourceInstanceName","resource_id":"ResourceID","resource_name":"ResourceName","resource_group_id":"ResourceGroupID","resource_group_name":"ResourceGroupName","organization_id":"OrganizationID","organization_name":"OrganizationName","space_id":"SpaceID","space_name":"SpaceName","consumer_id":"ConsumerID","region":"Region","pricing_region":"PricingRegion","pricing_country":"USA","currency_code":"USD","billable":true,"plan_id":"PlanID","plan_name":"PlanName","month":"2017-08","usage":[{"metric":"UP-TIME","metric_name":"UP-TIME","quantity":711.11,"rateable_quantity":700,"cost":123.45,"rated_cost":130.0,"price":["anyValue"],"unit":"HOURS","unit_name":"HOURS","non_chargeable":true,"discounts":[{"ref":"Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9","name":"platform-discount","display_name":"Platform Service Discount","discount":5}]}],"pending":true,"currency_rate":10.8716}]}`) + fmt.Fprintf(res, "%s", `{"next":{"href":"https://myhost.com/somePath?_start=1"},"total_count":2,"limit":1,"resources":[{"account_id":"AccountID","resource_instance_id":"ResourceInstanceID","resource_instance_name":"ResourceInstanceName","resource_id":"ResourceID","resource_name":"ResourceName","resource_group_id":"ResourceGroupID","resource_group_name":"ResourceGroupName","organization_id":"OrganizationID","organization_name":"OrganizationName","space_id":"SpaceID","space_name":"SpaceName","consumer_id":"ConsumerID","region":"Region","pricing_region":"PricingRegion","pricing_country":"USA","currency_code":"USD","billable":true,"plan_id":"PlanID","plan_name":"PlanName","pricing_plan_id":"PricingPlanID","month":"2017-08","usage":[{"metric":"UP-TIME","metric_name":"UP-TIME","quantity":711.11,"rateable_quantity":700,"cost":123.45,"rated_cost":130.0,"price":["anyValue"],"unit":"HOURS","unit_name":"HOURS","non_chargeable":true,"discounts":[{"ref":"Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9","name":"platform-discount","display_name":"Platform Service Discount","discount":5}]}],"pending":true,"currency_rate":10.8716,"tags":["anyValue"]}]}`) } else if requestNumber == 2 { - fmt.Fprintf(res, "%s", `{"total_count":2,"limit":1,"resources":[{"account_id":"AccountID","resource_instance_id":"ResourceInstanceID","resource_instance_name":"ResourceInstanceName","resource_id":"ResourceID","resource_name":"ResourceName","resource_group_id":"ResourceGroupID","resource_group_name":"ResourceGroupName","organization_id":"OrganizationID","organization_name":"OrganizationName","space_id":"SpaceID","space_name":"SpaceName","consumer_id":"ConsumerID","region":"Region","pricing_region":"PricingRegion","pricing_country":"USA","currency_code":"USD","billable":true,"plan_id":"PlanID","plan_name":"PlanName","month":"2017-08","usage":[{"metric":"UP-TIME","metric_name":"UP-TIME","quantity":711.11,"rateable_quantity":700,"cost":123.45,"rated_cost":130.0,"price":["anyValue"],"unit":"HOURS","unit_name":"HOURS","non_chargeable":true,"discounts":[{"ref":"Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9","name":"platform-discount","display_name":"Platform Service Discount","discount":5}]}],"pending":true,"currency_rate":10.8716}]}`) + fmt.Fprintf(res, "%s", `{"total_count":2,"limit":1,"resources":[{"account_id":"AccountID","resource_instance_id":"ResourceInstanceID","resource_instance_name":"ResourceInstanceName","resource_id":"ResourceID","resource_name":"ResourceName","resource_group_id":"ResourceGroupID","resource_group_name":"ResourceGroupName","organization_id":"OrganizationID","organization_name":"OrganizationName","space_id":"SpaceID","space_name":"SpaceName","consumer_id":"ConsumerID","region":"Region","pricing_region":"PricingRegion","pricing_country":"USA","currency_code":"USD","billable":true,"plan_id":"PlanID","plan_name":"PlanName","pricing_plan_id":"PricingPlanID","month":"2017-08","usage":[{"metric":"UP-TIME","metric_name":"UP-TIME","quantity":711.11,"rateable_quantity":700,"cost":123.45,"rated_cost":130.0,"price":["anyValue"],"unit":"HOURS","unit_name":"HOURS","non_chargeable":true,"discounts":[{"ref":"Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9","name":"platform-discount","display_name":"Platform Service Discount","discount":5}]}],"pending":true,"currency_rate":10.8716,"tags":["anyValue"]}]}`) } else { res.WriteHeader(400) } @@ -1629,8 +1647,9 @@ var _ = Describe(`UsageReportsV4`, func() { ResourceGroupID: core.StringPtr("testString"), Billingmonth: core.StringPtr("testString"), Names: core.BoolPtr(true), + Tags: core.BoolPtr(true), AcceptLanguage: core.StringPtr("testString"), - Limit: core.Int64Ptr(int64(1)), + Limit: core.Int64Ptr(int64(30)), ResourceInstanceID: core.StringPtr("testString"), ResourceID: core.StringPtr("testString"), PlanID: core.StringPtr("testString"), @@ -1663,8 +1682,9 @@ var _ = Describe(`UsageReportsV4`, func() { ResourceGroupID: core.StringPtr("testString"), Billingmonth: core.StringPtr("testString"), Names: core.BoolPtr(true), + Tags: core.BoolPtr(true), AcceptLanguage: core.StringPtr("testString"), - Limit: core.Int64Ptr(int64(1)), + Limit: core.Int64Ptr(int64(30)), ResourceInstanceID: core.StringPtr("testString"), ResourceID: core.StringPtr("testString"), PlanID: core.StringPtr("testString"), @@ -1695,7 +1715,8 @@ var _ = Describe(`UsageReportsV4`, func() { Expect(req.Header["Accept-Language"]).ToNot(BeNil()) Expect(req.Header["Accept-Language"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) // TODO: Add check for _names query parameter - Expect(req.URL.Query()["_limit"]).To(Equal([]string{fmt.Sprint(int64(1))})) + // TODO: Add check for _tags query parameter + Expect(req.URL.Query()["_limit"]).To(Equal([]string{fmt.Sprint(int64(30))})) Expect(req.URL.Query()["_start"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["resource_instance_id"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["resource_id"]).To(Equal([]string{"testString"})) @@ -1720,8 +1741,9 @@ var _ = Describe(`UsageReportsV4`, func() { getResourceUsageOrgOptionsModel.OrganizationID = core.StringPtr("testString") getResourceUsageOrgOptionsModel.Billingmonth = core.StringPtr("testString") getResourceUsageOrgOptionsModel.Names = core.BoolPtr(true) + getResourceUsageOrgOptionsModel.Tags = core.BoolPtr(true) getResourceUsageOrgOptionsModel.AcceptLanguage = core.StringPtr("testString") - getResourceUsageOrgOptionsModel.Limit = core.Int64Ptr(int64(1)) + getResourceUsageOrgOptionsModel.Limit = core.Int64Ptr(int64(30)) getResourceUsageOrgOptionsModel.Start = core.StringPtr("testString") getResourceUsageOrgOptionsModel.ResourceInstanceID = core.StringPtr("testString") getResourceUsageOrgOptionsModel.ResourceID = core.StringPtr("testString") @@ -1760,7 +1782,8 @@ var _ = Describe(`UsageReportsV4`, func() { Expect(req.Header["Accept-Language"]).ToNot(BeNil()) Expect(req.Header["Accept-Language"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) // TODO: Add check for _names query parameter - Expect(req.URL.Query()["_limit"]).To(Equal([]string{fmt.Sprint(int64(1))})) + // TODO: Add check for _tags query parameter + Expect(req.URL.Query()["_limit"]).To(Equal([]string{fmt.Sprint(int64(30))})) Expect(req.URL.Query()["_start"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["resource_instance_id"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["resource_id"]).To(Equal([]string{"testString"})) @@ -1772,7 +1795,7 @@ var _ = Describe(`UsageReportsV4`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"limit": 5, "count": 5, "first": {"href": "Href"}, "next": {"href": "Href", "offset": "Offset"}, "resources": [{"account_id": "AccountID", "resource_instance_id": "ResourceInstanceID", "resource_instance_name": "ResourceInstanceName", "resource_id": "ResourceID", "resource_name": "ResourceName", "resource_group_id": "ResourceGroupID", "resource_group_name": "ResourceGroupName", "organization_id": "OrganizationID", "organization_name": "OrganizationName", "space_id": "SpaceID", "space_name": "SpaceName", "consumer_id": "ConsumerID", "region": "Region", "pricing_region": "PricingRegion", "pricing_country": "USA", "currency_code": "USD", "billable": true, "plan_id": "PlanID", "plan_name": "PlanName", "month": "2017-08", "usage": [{"metric": "UP-TIME", "metric_name": "UP-TIME", "quantity": 711.11, "rateable_quantity": 700, "cost": 123.45, "rated_cost": 130.0, "price": ["anyValue"], "unit": "HOURS", "unit_name": "HOURS", "non_chargeable": true, "discounts": [{"ref": "Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9", "name": "platform-discount", "display_name": "Platform Service Discount", "discount": 5}]}], "pending": true, "currency_rate": 10.8716}]}`) + fmt.Fprintf(res, "%s", `{"limit": 5, "count": 5, "first": {"href": "Href"}, "next": {"href": "Href", "offset": "Offset"}, "resources": [{"account_id": "AccountID", "resource_instance_id": "ResourceInstanceID", "resource_instance_name": "ResourceInstanceName", "resource_id": "ResourceID", "resource_name": "ResourceName", "resource_group_id": "ResourceGroupID", "resource_group_name": "ResourceGroupName", "organization_id": "OrganizationID", "organization_name": "OrganizationName", "space_id": "SpaceID", "space_name": "SpaceName", "consumer_id": "ConsumerID", "region": "Region", "pricing_region": "PricingRegion", "pricing_country": "USA", "currency_code": "USD", "billable": true, "plan_id": "PlanID", "plan_name": "PlanName", "pricing_plan_id": "PricingPlanID", "month": "2017-08", "usage": [{"metric": "UP-TIME", "metric_name": "UP-TIME", "quantity": 711.11, "rateable_quantity": 700, "cost": 123.45, "rated_cost": 130.0, "price": ["anyValue"], "unit": "HOURS", "unit_name": "HOURS", "non_chargeable": true, "discounts": [{"ref": "Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9", "name": "platform-discount", "display_name": "Platform Service Discount", "discount": 5}]}], "pending": true, "currency_rate": 10.8716, "tags": ["anyValue"]}]}`) })) }) It(`Invoke GetResourceUsageOrg successfully with retries`, func() { @@ -1790,8 +1813,9 @@ var _ = Describe(`UsageReportsV4`, func() { getResourceUsageOrgOptionsModel.OrganizationID = core.StringPtr("testString") getResourceUsageOrgOptionsModel.Billingmonth = core.StringPtr("testString") getResourceUsageOrgOptionsModel.Names = core.BoolPtr(true) + getResourceUsageOrgOptionsModel.Tags = core.BoolPtr(true) getResourceUsageOrgOptionsModel.AcceptLanguage = core.StringPtr("testString") - getResourceUsageOrgOptionsModel.Limit = core.Int64Ptr(int64(1)) + getResourceUsageOrgOptionsModel.Limit = core.Int64Ptr(int64(30)) getResourceUsageOrgOptionsModel.Start = core.StringPtr("testString") getResourceUsageOrgOptionsModel.ResourceInstanceID = core.StringPtr("testString") getResourceUsageOrgOptionsModel.ResourceID = core.StringPtr("testString") @@ -1836,7 +1860,8 @@ var _ = Describe(`UsageReportsV4`, func() { Expect(req.Header["Accept-Language"]).ToNot(BeNil()) Expect(req.Header["Accept-Language"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) // TODO: Add check for _names query parameter - Expect(req.URL.Query()["_limit"]).To(Equal([]string{fmt.Sprint(int64(1))})) + // TODO: Add check for _tags query parameter + Expect(req.URL.Query()["_limit"]).To(Equal([]string{fmt.Sprint(int64(30))})) Expect(req.URL.Query()["_start"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["resource_instance_id"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["resource_id"]).To(Equal([]string{"testString"})) @@ -1845,7 +1870,7 @@ var _ = Describe(`UsageReportsV4`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"limit": 5, "count": 5, "first": {"href": "Href"}, "next": {"href": "Href", "offset": "Offset"}, "resources": [{"account_id": "AccountID", "resource_instance_id": "ResourceInstanceID", "resource_instance_name": "ResourceInstanceName", "resource_id": "ResourceID", "resource_name": "ResourceName", "resource_group_id": "ResourceGroupID", "resource_group_name": "ResourceGroupName", "organization_id": "OrganizationID", "organization_name": "OrganizationName", "space_id": "SpaceID", "space_name": "SpaceName", "consumer_id": "ConsumerID", "region": "Region", "pricing_region": "PricingRegion", "pricing_country": "USA", "currency_code": "USD", "billable": true, "plan_id": "PlanID", "plan_name": "PlanName", "month": "2017-08", "usage": [{"metric": "UP-TIME", "metric_name": "UP-TIME", "quantity": 711.11, "rateable_quantity": 700, "cost": 123.45, "rated_cost": 130.0, "price": ["anyValue"], "unit": "HOURS", "unit_name": "HOURS", "non_chargeable": true, "discounts": [{"ref": "Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9", "name": "platform-discount", "display_name": "Platform Service Discount", "discount": 5}]}], "pending": true, "currency_rate": 10.8716}]}`) + fmt.Fprintf(res, "%s", `{"limit": 5, "count": 5, "first": {"href": "Href"}, "next": {"href": "Href", "offset": "Offset"}, "resources": [{"account_id": "AccountID", "resource_instance_id": "ResourceInstanceID", "resource_instance_name": "ResourceInstanceName", "resource_id": "ResourceID", "resource_name": "ResourceName", "resource_group_id": "ResourceGroupID", "resource_group_name": "ResourceGroupName", "organization_id": "OrganizationID", "organization_name": "OrganizationName", "space_id": "SpaceID", "space_name": "SpaceName", "consumer_id": "ConsumerID", "region": "Region", "pricing_region": "PricingRegion", "pricing_country": "USA", "currency_code": "USD", "billable": true, "plan_id": "PlanID", "plan_name": "PlanName", "pricing_plan_id": "PricingPlanID", "month": "2017-08", "usage": [{"metric": "UP-TIME", "metric_name": "UP-TIME", "quantity": 711.11, "rateable_quantity": 700, "cost": 123.45, "rated_cost": 130.0, "price": ["anyValue"], "unit": "HOURS", "unit_name": "HOURS", "non_chargeable": true, "discounts": [{"ref": "Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9", "name": "platform-discount", "display_name": "Platform Service Discount", "discount": 5}]}], "pending": true, "currency_rate": 10.8716, "tags": ["anyValue"]}]}`) })) }) It(`Invoke GetResourceUsageOrg successfully`, func() { @@ -1868,8 +1893,9 @@ var _ = Describe(`UsageReportsV4`, func() { getResourceUsageOrgOptionsModel.OrganizationID = core.StringPtr("testString") getResourceUsageOrgOptionsModel.Billingmonth = core.StringPtr("testString") getResourceUsageOrgOptionsModel.Names = core.BoolPtr(true) + getResourceUsageOrgOptionsModel.Tags = core.BoolPtr(true) getResourceUsageOrgOptionsModel.AcceptLanguage = core.StringPtr("testString") - getResourceUsageOrgOptionsModel.Limit = core.Int64Ptr(int64(1)) + getResourceUsageOrgOptionsModel.Limit = core.Int64Ptr(int64(30)) getResourceUsageOrgOptionsModel.Start = core.StringPtr("testString") getResourceUsageOrgOptionsModel.ResourceInstanceID = core.StringPtr("testString") getResourceUsageOrgOptionsModel.ResourceID = core.StringPtr("testString") @@ -1898,8 +1924,9 @@ var _ = Describe(`UsageReportsV4`, func() { getResourceUsageOrgOptionsModel.OrganizationID = core.StringPtr("testString") getResourceUsageOrgOptionsModel.Billingmonth = core.StringPtr("testString") getResourceUsageOrgOptionsModel.Names = core.BoolPtr(true) + getResourceUsageOrgOptionsModel.Tags = core.BoolPtr(true) getResourceUsageOrgOptionsModel.AcceptLanguage = core.StringPtr("testString") - getResourceUsageOrgOptionsModel.Limit = core.Int64Ptr(int64(1)) + getResourceUsageOrgOptionsModel.Limit = core.Int64Ptr(int64(30)) getResourceUsageOrgOptionsModel.Start = core.StringPtr("testString") getResourceUsageOrgOptionsModel.ResourceInstanceID = core.StringPtr("testString") getResourceUsageOrgOptionsModel.ResourceID = core.StringPtr("testString") @@ -1949,8 +1976,9 @@ var _ = Describe(`UsageReportsV4`, func() { getResourceUsageOrgOptionsModel.OrganizationID = core.StringPtr("testString") getResourceUsageOrgOptionsModel.Billingmonth = core.StringPtr("testString") getResourceUsageOrgOptionsModel.Names = core.BoolPtr(true) + getResourceUsageOrgOptionsModel.Tags = core.BoolPtr(true) getResourceUsageOrgOptionsModel.AcceptLanguage = core.StringPtr("testString") - getResourceUsageOrgOptionsModel.Limit = core.Int64Ptr(int64(1)) + getResourceUsageOrgOptionsModel.Limit = core.Int64Ptr(int64(30)) getResourceUsageOrgOptionsModel.Start = core.StringPtr("testString") getResourceUsageOrgOptionsModel.ResourceInstanceID = core.StringPtr("testString") getResourceUsageOrgOptionsModel.ResourceID = core.StringPtr("testString") @@ -2014,9 +2042,9 @@ var _ = Describe(`UsageReportsV4`, func() { res.WriteHeader(200) requestNumber++ if requestNumber == 1 { - fmt.Fprintf(res, "%s", `{"next":{"href":"https://myhost.com/somePath?_start=1"},"total_count":2,"limit":1,"resources":[{"account_id":"AccountID","resource_instance_id":"ResourceInstanceID","resource_instance_name":"ResourceInstanceName","resource_id":"ResourceID","resource_name":"ResourceName","resource_group_id":"ResourceGroupID","resource_group_name":"ResourceGroupName","organization_id":"OrganizationID","organization_name":"OrganizationName","space_id":"SpaceID","space_name":"SpaceName","consumer_id":"ConsumerID","region":"Region","pricing_region":"PricingRegion","pricing_country":"USA","currency_code":"USD","billable":true,"plan_id":"PlanID","plan_name":"PlanName","month":"2017-08","usage":[{"metric":"UP-TIME","metric_name":"UP-TIME","quantity":711.11,"rateable_quantity":700,"cost":123.45,"rated_cost":130.0,"price":["anyValue"],"unit":"HOURS","unit_name":"HOURS","non_chargeable":true,"discounts":[{"ref":"Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9","name":"platform-discount","display_name":"Platform Service Discount","discount":5}]}],"pending":true,"currency_rate":10.8716}]}`) + fmt.Fprintf(res, "%s", `{"next":{"href":"https://myhost.com/somePath?_start=1"},"total_count":2,"limit":1,"resources":[{"account_id":"AccountID","resource_instance_id":"ResourceInstanceID","resource_instance_name":"ResourceInstanceName","resource_id":"ResourceID","resource_name":"ResourceName","resource_group_id":"ResourceGroupID","resource_group_name":"ResourceGroupName","organization_id":"OrganizationID","organization_name":"OrganizationName","space_id":"SpaceID","space_name":"SpaceName","consumer_id":"ConsumerID","region":"Region","pricing_region":"PricingRegion","pricing_country":"USA","currency_code":"USD","billable":true,"plan_id":"PlanID","plan_name":"PlanName","pricing_plan_id":"PricingPlanID","month":"2017-08","usage":[{"metric":"UP-TIME","metric_name":"UP-TIME","quantity":711.11,"rateable_quantity":700,"cost":123.45,"rated_cost":130.0,"price":["anyValue"],"unit":"HOURS","unit_name":"HOURS","non_chargeable":true,"discounts":[{"ref":"Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9","name":"platform-discount","display_name":"Platform Service Discount","discount":5}]}],"pending":true,"currency_rate":10.8716,"tags":["anyValue"]}]}`) } else if requestNumber == 2 { - fmt.Fprintf(res, "%s", `{"total_count":2,"limit":1,"resources":[{"account_id":"AccountID","resource_instance_id":"ResourceInstanceID","resource_instance_name":"ResourceInstanceName","resource_id":"ResourceID","resource_name":"ResourceName","resource_group_id":"ResourceGroupID","resource_group_name":"ResourceGroupName","organization_id":"OrganizationID","organization_name":"OrganizationName","space_id":"SpaceID","space_name":"SpaceName","consumer_id":"ConsumerID","region":"Region","pricing_region":"PricingRegion","pricing_country":"USA","currency_code":"USD","billable":true,"plan_id":"PlanID","plan_name":"PlanName","month":"2017-08","usage":[{"metric":"UP-TIME","metric_name":"UP-TIME","quantity":711.11,"rateable_quantity":700,"cost":123.45,"rated_cost":130.0,"price":["anyValue"],"unit":"HOURS","unit_name":"HOURS","non_chargeable":true,"discounts":[{"ref":"Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9","name":"platform-discount","display_name":"Platform Service Discount","discount":5}]}],"pending":true,"currency_rate":10.8716}]}`) + fmt.Fprintf(res, "%s", `{"total_count":2,"limit":1,"resources":[{"account_id":"AccountID","resource_instance_id":"ResourceInstanceID","resource_instance_name":"ResourceInstanceName","resource_id":"ResourceID","resource_name":"ResourceName","resource_group_id":"ResourceGroupID","resource_group_name":"ResourceGroupName","organization_id":"OrganizationID","organization_name":"OrganizationName","space_id":"SpaceID","space_name":"SpaceName","consumer_id":"ConsumerID","region":"Region","pricing_region":"PricingRegion","pricing_country":"USA","currency_code":"USD","billable":true,"plan_id":"PlanID","plan_name":"PlanName","pricing_plan_id":"PricingPlanID","month":"2017-08","usage":[{"metric":"UP-TIME","metric_name":"UP-TIME","quantity":711.11,"rateable_quantity":700,"cost":123.45,"rated_cost":130.0,"price":["anyValue"],"unit":"HOURS","unit_name":"HOURS","non_chargeable":true,"discounts":[{"ref":"Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9","name":"platform-discount","display_name":"Platform Service Discount","discount":5}]}],"pending":true,"currency_rate":10.8716,"tags":["anyValue"]}]}`) } else { res.WriteHeader(400) } @@ -2035,8 +2063,9 @@ var _ = Describe(`UsageReportsV4`, func() { OrganizationID: core.StringPtr("testString"), Billingmonth: core.StringPtr("testString"), Names: core.BoolPtr(true), + Tags: core.BoolPtr(true), AcceptLanguage: core.StringPtr("testString"), - Limit: core.Int64Ptr(int64(1)), + Limit: core.Int64Ptr(int64(30)), ResourceInstanceID: core.StringPtr("testString"), ResourceID: core.StringPtr("testString"), PlanID: core.StringPtr("testString"), @@ -2069,8 +2098,9 @@ var _ = Describe(`UsageReportsV4`, func() { OrganizationID: core.StringPtr("testString"), Billingmonth: core.StringPtr("testString"), Names: core.BoolPtr(true), + Tags: core.BoolPtr(true), AcceptLanguage: core.StringPtr("testString"), - Limit: core.Int64Ptr(int64(1)), + Limit: core.Int64Ptr(int64(30)), ResourceInstanceID: core.StringPtr("testString"), ResourceID: core.StringPtr("testString"), PlanID: core.StringPtr("testString"), @@ -2329,12 +2359,1118 @@ var _ = Describe(`UsageReportsV4`, func() { }) }) }) + Describe(`CreateReportsSnapshotConfig(createReportsSnapshotConfigOptions *CreateReportsSnapshotConfigOptions) - Operation response error`, func() { + createReportsSnapshotConfigPath := "/v1/billing-reports-snapshot-config" + Context(`Using mock server endpoint with invalid JSON response`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(createReportsSnapshotConfigPath)) + Expect(req.Method).To(Equal("POST")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(201) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke CreateReportsSnapshotConfig with error: Operation response processing error`, func() { + usageReportsService, serviceErr := usagereportsv4.NewUsageReportsV4(&usagereportsv4.UsageReportsV4Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(usageReportsService).ToNot(BeNil()) + + // Construct an instance of the CreateReportsSnapshotConfigOptions model + createReportsSnapshotConfigOptionsModel := new(usagereportsv4.CreateReportsSnapshotConfigOptions) + createReportsSnapshotConfigOptionsModel.AccountID = core.StringPtr("abc") + createReportsSnapshotConfigOptionsModel.Interval = core.StringPtr("daily") + createReportsSnapshotConfigOptionsModel.CosBucket = core.StringPtr("bucket_name") + createReportsSnapshotConfigOptionsModel.CosLocation = core.StringPtr("us-south") + createReportsSnapshotConfigOptionsModel.CosReportsFolder = core.StringPtr("IBMCloud-Billing-Reports") + createReportsSnapshotConfigOptionsModel.ReportTypes = []string{"account_summary", "enterprise_summary", "account_resource_instance_usage"} + createReportsSnapshotConfigOptionsModel.Versioning = core.StringPtr("new") + createReportsSnapshotConfigOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Expect response parsing to fail since we are receiving a text/plain response + result, response, operationErr := usageReportsService.CreateReportsSnapshotConfig(createReportsSnapshotConfigOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + usageReportsService.EnableRetries(0, 0) + result, response, operationErr = usageReportsService.CreateReportsSnapshotConfig(createReportsSnapshotConfigOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`CreateReportsSnapshotConfig(createReportsSnapshotConfigOptions *CreateReportsSnapshotConfigOptions)`, func() { + createReportsSnapshotConfigPath := "/v1/billing-reports-snapshot-config" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(createReportsSnapshotConfigPath)) + Expect(req.Method).To(Equal("POST")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(201) + fmt.Fprintf(res, "%s", `{"account_id": "abc", "state": "enabled", "account_type": "account", "interval": "daily", "versioning": "new", "report_types": ["account_summary"], "compression": "GZIP", "content_type": "text/csv", "cos_reports_folder": "IBMCloud-Billing-Reports", "cos_bucket": "bucket_name", "cos_location": "us-south", "cos_endpoint": "https://s3.us-west.cloud-object-storage.test.appdomain.cloud", "created_at": 1687469854342, "last_updated_at": 1687469989326, "history": [{"start_time": 1687469854342, "end_time": 1687469989326, "updated_by": "IBMid-506PR16K14", "account_id": "abc", "state": "enabled", "account_type": "account", "interval": "daily", "versioning": "new", "report_types": ["account_summary"], "compression": "GZIP", "content_type": "text/csv", "cos_reports_folder": "IBMCloud-Billing-Reports", "cos_bucket": "bucket_name", "cos_location": "us-south", "cos_endpoint": "https://s3.us-west.cloud-object-storage.test.appdomain.cloud"}]}`) + })) + }) + It(`Invoke CreateReportsSnapshotConfig successfully with retries`, func() { + usageReportsService, serviceErr := usagereportsv4.NewUsageReportsV4(&usagereportsv4.UsageReportsV4Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(usageReportsService).ToNot(BeNil()) + usageReportsService.EnableRetries(0, 0) + + // Construct an instance of the CreateReportsSnapshotConfigOptions model + createReportsSnapshotConfigOptionsModel := new(usagereportsv4.CreateReportsSnapshotConfigOptions) + createReportsSnapshotConfigOptionsModel.AccountID = core.StringPtr("abc") + createReportsSnapshotConfigOptionsModel.Interval = core.StringPtr("daily") + createReportsSnapshotConfigOptionsModel.CosBucket = core.StringPtr("bucket_name") + createReportsSnapshotConfigOptionsModel.CosLocation = core.StringPtr("us-south") + createReportsSnapshotConfigOptionsModel.CosReportsFolder = core.StringPtr("IBMCloud-Billing-Reports") + createReportsSnapshotConfigOptionsModel.ReportTypes = []string{"account_summary", "enterprise_summary", "account_resource_instance_usage"} + createReportsSnapshotConfigOptionsModel.Versioning = core.StringPtr("new") + createReportsSnapshotConfigOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := usageReportsService.CreateReportsSnapshotConfigWithContext(ctx, createReportsSnapshotConfigOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + usageReportsService.DisableRetries() + result, response, operationErr := usageReportsService.CreateReportsSnapshotConfig(createReportsSnapshotConfigOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = usageReportsService.CreateReportsSnapshotConfigWithContext(ctx, createReportsSnapshotConfigOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(createReportsSnapshotConfigPath)) + Expect(req.Method).To(Equal("POST")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(201) + fmt.Fprintf(res, "%s", `{"account_id": "abc", "state": "enabled", "account_type": "account", "interval": "daily", "versioning": "new", "report_types": ["account_summary"], "compression": "GZIP", "content_type": "text/csv", "cos_reports_folder": "IBMCloud-Billing-Reports", "cos_bucket": "bucket_name", "cos_location": "us-south", "cos_endpoint": "https://s3.us-west.cloud-object-storage.test.appdomain.cloud", "created_at": 1687469854342, "last_updated_at": 1687469989326, "history": [{"start_time": 1687469854342, "end_time": 1687469989326, "updated_by": "IBMid-506PR16K14", "account_id": "abc", "state": "enabled", "account_type": "account", "interval": "daily", "versioning": "new", "report_types": ["account_summary"], "compression": "GZIP", "content_type": "text/csv", "cos_reports_folder": "IBMCloud-Billing-Reports", "cos_bucket": "bucket_name", "cos_location": "us-south", "cos_endpoint": "https://s3.us-west.cloud-object-storage.test.appdomain.cloud"}]}`) + })) + }) + It(`Invoke CreateReportsSnapshotConfig successfully`, func() { + usageReportsService, serviceErr := usagereportsv4.NewUsageReportsV4(&usagereportsv4.UsageReportsV4Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(usageReportsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := usageReportsService.CreateReportsSnapshotConfig(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the CreateReportsSnapshotConfigOptions model + createReportsSnapshotConfigOptionsModel := new(usagereportsv4.CreateReportsSnapshotConfigOptions) + createReportsSnapshotConfigOptionsModel.AccountID = core.StringPtr("abc") + createReportsSnapshotConfigOptionsModel.Interval = core.StringPtr("daily") + createReportsSnapshotConfigOptionsModel.CosBucket = core.StringPtr("bucket_name") + createReportsSnapshotConfigOptionsModel.CosLocation = core.StringPtr("us-south") + createReportsSnapshotConfigOptionsModel.CosReportsFolder = core.StringPtr("IBMCloud-Billing-Reports") + createReportsSnapshotConfigOptionsModel.ReportTypes = []string{"account_summary", "enterprise_summary", "account_resource_instance_usage"} + createReportsSnapshotConfigOptionsModel.Versioning = core.StringPtr("new") + createReportsSnapshotConfigOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = usageReportsService.CreateReportsSnapshotConfig(createReportsSnapshotConfigOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke CreateReportsSnapshotConfig with error: Operation validation and request error`, func() { + usageReportsService, serviceErr := usagereportsv4.NewUsageReportsV4(&usagereportsv4.UsageReportsV4Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(usageReportsService).ToNot(BeNil()) + + // Construct an instance of the CreateReportsSnapshotConfigOptions model + createReportsSnapshotConfigOptionsModel := new(usagereportsv4.CreateReportsSnapshotConfigOptions) + createReportsSnapshotConfigOptionsModel.AccountID = core.StringPtr("abc") + createReportsSnapshotConfigOptionsModel.Interval = core.StringPtr("daily") + createReportsSnapshotConfigOptionsModel.CosBucket = core.StringPtr("bucket_name") + createReportsSnapshotConfigOptionsModel.CosLocation = core.StringPtr("us-south") + createReportsSnapshotConfigOptionsModel.CosReportsFolder = core.StringPtr("IBMCloud-Billing-Reports") + createReportsSnapshotConfigOptionsModel.ReportTypes = []string{"account_summary", "enterprise_summary", "account_resource_instance_usage"} + createReportsSnapshotConfigOptionsModel.Versioning = core.StringPtr("new") + createReportsSnapshotConfigOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := usageReportsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := usageReportsService.CreateReportsSnapshotConfig(createReportsSnapshotConfigOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + // Construct a second instance of the CreateReportsSnapshotConfigOptions model with no property values + createReportsSnapshotConfigOptionsModelNew := new(usagereportsv4.CreateReportsSnapshotConfigOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = usageReportsService.CreateReportsSnapshotConfig(createReportsSnapshotConfigOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(201) + })) + }) + It(`Invoke CreateReportsSnapshotConfig successfully`, func() { + usageReportsService, serviceErr := usagereportsv4.NewUsageReportsV4(&usagereportsv4.UsageReportsV4Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(usageReportsService).ToNot(BeNil()) + + // Construct an instance of the CreateReportsSnapshotConfigOptions model + createReportsSnapshotConfigOptionsModel := new(usagereportsv4.CreateReportsSnapshotConfigOptions) + createReportsSnapshotConfigOptionsModel.AccountID = core.StringPtr("abc") + createReportsSnapshotConfigOptionsModel.Interval = core.StringPtr("daily") + createReportsSnapshotConfigOptionsModel.CosBucket = core.StringPtr("bucket_name") + createReportsSnapshotConfigOptionsModel.CosLocation = core.StringPtr("us-south") + createReportsSnapshotConfigOptionsModel.CosReportsFolder = core.StringPtr("IBMCloud-Billing-Reports") + createReportsSnapshotConfigOptionsModel.ReportTypes = []string{"account_summary", "enterprise_summary", "account_resource_instance_usage"} + createReportsSnapshotConfigOptionsModel.Versioning = core.StringPtr("new") + createReportsSnapshotConfigOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := usageReportsService.CreateReportsSnapshotConfig(createReportsSnapshotConfigOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`GetReportsSnapshotConfig(getReportsSnapshotConfigOptions *GetReportsSnapshotConfigOptions) - Operation response error`, func() { + getReportsSnapshotConfigPath := "/v1/billing-reports-snapshot-config" + Context(`Using mock server endpoint with invalid JSON response`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getReportsSnapshotConfigPath)) + Expect(req.Method).To(Equal("GET")) + Expect(req.URL.Query()["account_id"]).To(Equal([]string{"abc"})) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke GetReportsSnapshotConfig with error: Operation response processing error`, func() { + usageReportsService, serviceErr := usagereportsv4.NewUsageReportsV4(&usagereportsv4.UsageReportsV4Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(usageReportsService).ToNot(BeNil()) + + // Construct an instance of the GetReportsSnapshotConfigOptions model + getReportsSnapshotConfigOptionsModel := new(usagereportsv4.GetReportsSnapshotConfigOptions) + getReportsSnapshotConfigOptionsModel.AccountID = core.StringPtr("abc") + getReportsSnapshotConfigOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Expect response parsing to fail since we are receiving a text/plain response + result, response, operationErr := usageReportsService.GetReportsSnapshotConfig(getReportsSnapshotConfigOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + usageReportsService.EnableRetries(0, 0) + result, response, operationErr = usageReportsService.GetReportsSnapshotConfig(getReportsSnapshotConfigOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`GetReportsSnapshotConfig(getReportsSnapshotConfigOptions *GetReportsSnapshotConfigOptions)`, func() { + getReportsSnapshotConfigPath := "/v1/billing-reports-snapshot-config" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getReportsSnapshotConfigPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.URL.Query()["account_id"]).To(Equal([]string{"abc"})) + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"account_id": "abc", "state": "enabled", "account_type": "account", "interval": "daily", "versioning": "new", "report_types": ["account_summary"], "compression": "GZIP", "content_type": "text/csv", "cos_reports_folder": "IBMCloud-Billing-Reports", "cos_bucket": "bucket_name", "cos_location": "us-south", "cos_endpoint": "https://s3.us-west.cloud-object-storage.test.appdomain.cloud", "created_at": 1687469854342, "last_updated_at": 1687469989326, "history": [{"start_time": 1687469854342, "end_time": 1687469989326, "updated_by": "IBMid-506PR16K14", "account_id": "abc", "state": "enabled", "account_type": "account", "interval": "daily", "versioning": "new", "report_types": ["account_summary"], "compression": "GZIP", "content_type": "text/csv", "cos_reports_folder": "IBMCloud-Billing-Reports", "cos_bucket": "bucket_name", "cos_location": "us-south", "cos_endpoint": "https://s3.us-west.cloud-object-storage.test.appdomain.cloud"}]}`) + })) + }) + It(`Invoke GetReportsSnapshotConfig successfully with retries`, func() { + usageReportsService, serviceErr := usagereportsv4.NewUsageReportsV4(&usagereportsv4.UsageReportsV4Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(usageReportsService).ToNot(BeNil()) + usageReportsService.EnableRetries(0, 0) + + // Construct an instance of the GetReportsSnapshotConfigOptions model + getReportsSnapshotConfigOptionsModel := new(usagereportsv4.GetReportsSnapshotConfigOptions) + getReportsSnapshotConfigOptionsModel.AccountID = core.StringPtr("abc") + getReportsSnapshotConfigOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := usageReportsService.GetReportsSnapshotConfigWithContext(ctx, getReportsSnapshotConfigOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + usageReportsService.DisableRetries() + result, response, operationErr := usageReportsService.GetReportsSnapshotConfig(getReportsSnapshotConfigOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = usageReportsService.GetReportsSnapshotConfigWithContext(ctx, getReportsSnapshotConfigOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getReportsSnapshotConfigPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.URL.Query()["account_id"]).To(Equal([]string{"abc"})) + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"account_id": "abc", "state": "enabled", "account_type": "account", "interval": "daily", "versioning": "new", "report_types": ["account_summary"], "compression": "GZIP", "content_type": "text/csv", "cos_reports_folder": "IBMCloud-Billing-Reports", "cos_bucket": "bucket_name", "cos_location": "us-south", "cos_endpoint": "https://s3.us-west.cloud-object-storage.test.appdomain.cloud", "created_at": 1687469854342, "last_updated_at": 1687469989326, "history": [{"start_time": 1687469854342, "end_time": 1687469989326, "updated_by": "IBMid-506PR16K14", "account_id": "abc", "state": "enabled", "account_type": "account", "interval": "daily", "versioning": "new", "report_types": ["account_summary"], "compression": "GZIP", "content_type": "text/csv", "cos_reports_folder": "IBMCloud-Billing-Reports", "cos_bucket": "bucket_name", "cos_location": "us-south", "cos_endpoint": "https://s3.us-west.cloud-object-storage.test.appdomain.cloud"}]}`) + })) + }) + It(`Invoke GetReportsSnapshotConfig successfully`, func() { + usageReportsService, serviceErr := usagereportsv4.NewUsageReportsV4(&usagereportsv4.UsageReportsV4Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(usageReportsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := usageReportsService.GetReportsSnapshotConfig(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the GetReportsSnapshotConfigOptions model + getReportsSnapshotConfigOptionsModel := new(usagereportsv4.GetReportsSnapshotConfigOptions) + getReportsSnapshotConfigOptionsModel.AccountID = core.StringPtr("abc") + getReportsSnapshotConfigOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = usageReportsService.GetReportsSnapshotConfig(getReportsSnapshotConfigOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke GetReportsSnapshotConfig with error: Operation validation and request error`, func() { + usageReportsService, serviceErr := usagereportsv4.NewUsageReportsV4(&usagereportsv4.UsageReportsV4Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(usageReportsService).ToNot(BeNil()) + + // Construct an instance of the GetReportsSnapshotConfigOptions model + getReportsSnapshotConfigOptionsModel := new(usagereportsv4.GetReportsSnapshotConfigOptions) + getReportsSnapshotConfigOptionsModel.AccountID = core.StringPtr("abc") + getReportsSnapshotConfigOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := usageReportsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := usageReportsService.GetReportsSnapshotConfig(getReportsSnapshotConfigOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + // Construct a second instance of the GetReportsSnapshotConfigOptions model with no property values + getReportsSnapshotConfigOptionsModelNew := new(usagereportsv4.GetReportsSnapshotConfigOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = usageReportsService.GetReportsSnapshotConfig(getReportsSnapshotConfigOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke GetReportsSnapshotConfig successfully`, func() { + usageReportsService, serviceErr := usagereportsv4.NewUsageReportsV4(&usagereportsv4.UsageReportsV4Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(usageReportsService).ToNot(BeNil()) + + // Construct an instance of the GetReportsSnapshotConfigOptions model + getReportsSnapshotConfigOptionsModel := new(usagereportsv4.GetReportsSnapshotConfigOptions) + getReportsSnapshotConfigOptionsModel.AccountID = core.StringPtr("abc") + getReportsSnapshotConfigOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := usageReportsService.GetReportsSnapshotConfig(getReportsSnapshotConfigOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`UpdateReportsSnapshotConfig(updateReportsSnapshotConfigOptions *UpdateReportsSnapshotConfigOptions) - Operation response error`, func() { + updateReportsSnapshotConfigPath := "/v1/billing-reports-snapshot-config" + Context(`Using mock server endpoint with invalid JSON response`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(updateReportsSnapshotConfigPath)) + Expect(req.Method).To(Equal("PATCH")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke UpdateReportsSnapshotConfig with error: Operation response processing error`, func() { + usageReportsService, serviceErr := usagereportsv4.NewUsageReportsV4(&usagereportsv4.UsageReportsV4Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(usageReportsService).ToNot(BeNil()) + + // Construct an instance of the UpdateReportsSnapshotConfigOptions model + updateReportsSnapshotConfigOptionsModel := new(usagereportsv4.UpdateReportsSnapshotConfigOptions) + updateReportsSnapshotConfigOptionsModel.AccountID = core.StringPtr("abc") + updateReportsSnapshotConfigOptionsModel.Interval = core.StringPtr("daily") + updateReportsSnapshotConfigOptionsModel.CosBucket = core.StringPtr("bucket_name") + updateReportsSnapshotConfigOptionsModel.CosLocation = core.StringPtr("us-south") + updateReportsSnapshotConfigOptionsModel.CosReportsFolder = core.StringPtr("IBMCloud-Billing-Reports") + updateReportsSnapshotConfigOptionsModel.ReportTypes = []string{"account_summary", "enterprise_summary", "account_resource_instance_usage"} + updateReportsSnapshotConfigOptionsModel.Versioning = core.StringPtr("new") + updateReportsSnapshotConfigOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Expect response parsing to fail since we are receiving a text/plain response + result, response, operationErr := usageReportsService.UpdateReportsSnapshotConfig(updateReportsSnapshotConfigOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + usageReportsService.EnableRetries(0, 0) + result, response, operationErr = usageReportsService.UpdateReportsSnapshotConfig(updateReportsSnapshotConfigOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`UpdateReportsSnapshotConfig(updateReportsSnapshotConfigOptions *UpdateReportsSnapshotConfigOptions)`, func() { + updateReportsSnapshotConfigPath := "/v1/billing-reports-snapshot-config" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(updateReportsSnapshotConfigPath)) + Expect(req.Method).To(Equal("PATCH")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"account_id": "abc", "state": "enabled", "account_type": "account", "interval": "daily", "versioning": "new", "report_types": ["account_summary"], "compression": "GZIP", "content_type": "text/csv", "cos_reports_folder": "IBMCloud-Billing-Reports", "cos_bucket": "bucket_name", "cos_location": "us-south", "cos_endpoint": "https://s3.us-west.cloud-object-storage.test.appdomain.cloud", "created_at": 1687469854342, "last_updated_at": 1687469989326, "history": [{"start_time": 1687469854342, "end_time": 1687469989326, "updated_by": "IBMid-506PR16K14", "account_id": "abc", "state": "enabled", "account_type": "account", "interval": "daily", "versioning": "new", "report_types": ["account_summary"], "compression": "GZIP", "content_type": "text/csv", "cos_reports_folder": "IBMCloud-Billing-Reports", "cos_bucket": "bucket_name", "cos_location": "us-south", "cos_endpoint": "https://s3.us-west.cloud-object-storage.test.appdomain.cloud"}]}`) + })) + }) + It(`Invoke UpdateReportsSnapshotConfig successfully with retries`, func() { + usageReportsService, serviceErr := usagereportsv4.NewUsageReportsV4(&usagereportsv4.UsageReportsV4Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(usageReportsService).ToNot(BeNil()) + usageReportsService.EnableRetries(0, 0) + + // Construct an instance of the UpdateReportsSnapshotConfigOptions model + updateReportsSnapshotConfigOptionsModel := new(usagereportsv4.UpdateReportsSnapshotConfigOptions) + updateReportsSnapshotConfigOptionsModel.AccountID = core.StringPtr("abc") + updateReportsSnapshotConfigOptionsModel.Interval = core.StringPtr("daily") + updateReportsSnapshotConfigOptionsModel.CosBucket = core.StringPtr("bucket_name") + updateReportsSnapshotConfigOptionsModel.CosLocation = core.StringPtr("us-south") + updateReportsSnapshotConfigOptionsModel.CosReportsFolder = core.StringPtr("IBMCloud-Billing-Reports") + updateReportsSnapshotConfigOptionsModel.ReportTypes = []string{"account_summary", "enterprise_summary", "account_resource_instance_usage"} + updateReportsSnapshotConfigOptionsModel.Versioning = core.StringPtr("new") + updateReportsSnapshotConfigOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := usageReportsService.UpdateReportsSnapshotConfigWithContext(ctx, updateReportsSnapshotConfigOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + usageReportsService.DisableRetries() + result, response, operationErr := usageReportsService.UpdateReportsSnapshotConfig(updateReportsSnapshotConfigOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = usageReportsService.UpdateReportsSnapshotConfigWithContext(ctx, updateReportsSnapshotConfigOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(updateReportsSnapshotConfigPath)) + Expect(req.Method).To(Equal("PATCH")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"account_id": "abc", "state": "enabled", "account_type": "account", "interval": "daily", "versioning": "new", "report_types": ["account_summary"], "compression": "GZIP", "content_type": "text/csv", "cos_reports_folder": "IBMCloud-Billing-Reports", "cos_bucket": "bucket_name", "cos_location": "us-south", "cos_endpoint": "https://s3.us-west.cloud-object-storage.test.appdomain.cloud", "created_at": 1687469854342, "last_updated_at": 1687469989326, "history": [{"start_time": 1687469854342, "end_time": 1687469989326, "updated_by": "IBMid-506PR16K14", "account_id": "abc", "state": "enabled", "account_type": "account", "interval": "daily", "versioning": "new", "report_types": ["account_summary"], "compression": "GZIP", "content_type": "text/csv", "cos_reports_folder": "IBMCloud-Billing-Reports", "cos_bucket": "bucket_name", "cos_location": "us-south", "cos_endpoint": "https://s3.us-west.cloud-object-storage.test.appdomain.cloud"}]}`) + })) + }) + It(`Invoke UpdateReportsSnapshotConfig successfully`, func() { + usageReportsService, serviceErr := usagereportsv4.NewUsageReportsV4(&usagereportsv4.UsageReportsV4Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(usageReportsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := usageReportsService.UpdateReportsSnapshotConfig(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the UpdateReportsSnapshotConfigOptions model + updateReportsSnapshotConfigOptionsModel := new(usagereportsv4.UpdateReportsSnapshotConfigOptions) + updateReportsSnapshotConfigOptionsModel.AccountID = core.StringPtr("abc") + updateReportsSnapshotConfigOptionsModel.Interval = core.StringPtr("daily") + updateReportsSnapshotConfigOptionsModel.CosBucket = core.StringPtr("bucket_name") + updateReportsSnapshotConfigOptionsModel.CosLocation = core.StringPtr("us-south") + updateReportsSnapshotConfigOptionsModel.CosReportsFolder = core.StringPtr("IBMCloud-Billing-Reports") + updateReportsSnapshotConfigOptionsModel.ReportTypes = []string{"account_summary", "enterprise_summary", "account_resource_instance_usage"} + updateReportsSnapshotConfigOptionsModel.Versioning = core.StringPtr("new") + updateReportsSnapshotConfigOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = usageReportsService.UpdateReportsSnapshotConfig(updateReportsSnapshotConfigOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke UpdateReportsSnapshotConfig with error: Operation validation and request error`, func() { + usageReportsService, serviceErr := usagereportsv4.NewUsageReportsV4(&usagereportsv4.UsageReportsV4Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(usageReportsService).ToNot(BeNil()) + + // Construct an instance of the UpdateReportsSnapshotConfigOptions model + updateReportsSnapshotConfigOptionsModel := new(usagereportsv4.UpdateReportsSnapshotConfigOptions) + updateReportsSnapshotConfigOptionsModel.AccountID = core.StringPtr("abc") + updateReportsSnapshotConfigOptionsModel.Interval = core.StringPtr("daily") + updateReportsSnapshotConfigOptionsModel.CosBucket = core.StringPtr("bucket_name") + updateReportsSnapshotConfigOptionsModel.CosLocation = core.StringPtr("us-south") + updateReportsSnapshotConfigOptionsModel.CosReportsFolder = core.StringPtr("IBMCloud-Billing-Reports") + updateReportsSnapshotConfigOptionsModel.ReportTypes = []string{"account_summary", "enterprise_summary", "account_resource_instance_usage"} + updateReportsSnapshotConfigOptionsModel.Versioning = core.StringPtr("new") + updateReportsSnapshotConfigOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := usageReportsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := usageReportsService.UpdateReportsSnapshotConfig(updateReportsSnapshotConfigOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + // Construct a second instance of the UpdateReportsSnapshotConfigOptions model with no property values + updateReportsSnapshotConfigOptionsModelNew := new(usagereportsv4.UpdateReportsSnapshotConfigOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = usageReportsService.UpdateReportsSnapshotConfig(updateReportsSnapshotConfigOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke UpdateReportsSnapshotConfig successfully`, func() { + usageReportsService, serviceErr := usagereportsv4.NewUsageReportsV4(&usagereportsv4.UsageReportsV4Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(usageReportsService).ToNot(BeNil()) + + // Construct an instance of the UpdateReportsSnapshotConfigOptions model + updateReportsSnapshotConfigOptionsModel := new(usagereportsv4.UpdateReportsSnapshotConfigOptions) + updateReportsSnapshotConfigOptionsModel.AccountID = core.StringPtr("abc") + updateReportsSnapshotConfigOptionsModel.Interval = core.StringPtr("daily") + updateReportsSnapshotConfigOptionsModel.CosBucket = core.StringPtr("bucket_name") + updateReportsSnapshotConfigOptionsModel.CosLocation = core.StringPtr("us-south") + updateReportsSnapshotConfigOptionsModel.CosReportsFolder = core.StringPtr("IBMCloud-Billing-Reports") + updateReportsSnapshotConfigOptionsModel.ReportTypes = []string{"account_summary", "enterprise_summary", "account_resource_instance_usage"} + updateReportsSnapshotConfigOptionsModel.Versioning = core.StringPtr("new") + updateReportsSnapshotConfigOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := usageReportsService.UpdateReportsSnapshotConfig(updateReportsSnapshotConfigOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`DeleteReportsSnapshotConfig(deleteReportsSnapshotConfigOptions *DeleteReportsSnapshotConfigOptions)`, func() { + deleteReportsSnapshotConfigPath := "/v1/billing-reports-snapshot-config" + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(deleteReportsSnapshotConfigPath)) + Expect(req.Method).To(Equal("DELETE")) + + Expect(req.URL.Query()["account_id"]).To(Equal([]string{"abc"})) + res.WriteHeader(204) + })) + }) + It(`Invoke DeleteReportsSnapshotConfig successfully`, func() { + usageReportsService, serviceErr := usagereportsv4.NewUsageReportsV4(&usagereportsv4.UsageReportsV4Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(usageReportsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + response, operationErr := usageReportsService.DeleteReportsSnapshotConfig(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + + // Construct an instance of the DeleteReportsSnapshotConfigOptions model + deleteReportsSnapshotConfigOptionsModel := new(usagereportsv4.DeleteReportsSnapshotConfigOptions) + deleteReportsSnapshotConfigOptionsModel.AccountID = core.StringPtr("abc") + deleteReportsSnapshotConfigOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + response, operationErr = usageReportsService.DeleteReportsSnapshotConfig(deleteReportsSnapshotConfigOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + }) + It(`Invoke DeleteReportsSnapshotConfig with error: Operation validation and request error`, func() { + usageReportsService, serviceErr := usagereportsv4.NewUsageReportsV4(&usagereportsv4.UsageReportsV4Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(usageReportsService).ToNot(BeNil()) + + // Construct an instance of the DeleteReportsSnapshotConfigOptions model + deleteReportsSnapshotConfigOptionsModel := new(usagereportsv4.DeleteReportsSnapshotConfigOptions) + deleteReportsSnapshotConfigOptionsModel.AccountID = core.StringPtr("abc") + deleteReportsSnapshotConfigOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := usageReportsService.SetServiceURL("") + Expect(err).To(BeNil()) + response, operationErr := usageReportsService.DeleteReportsSnapshotConfig(deleteReportsSnapshotConfigOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + // Construct a second instance of the DeleteReportsSnapshotConfigOptions model with no property values + deleteReportsSnapshotConfigOptionsModelNew := new(usagereportsv4.DeleteReportsSnapshotConfigOptions) + // Invoke operation with invalid model (negative test) + response, operationErr = usageReportsService.DeleteReportsSnapshotConfig(deleteReportsSnapshotConfigOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`GetReportsSnapshot(getReportsSnapshotOptions *GetReportsSnapshotOptions) - Operation response error`, func() { + getReportsSnapshotPath := "/v1/billing-reports-snapshots" + Context(`Using mock server endpoint with invalid JSON response`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getReportsSnapshotPath)) + Expect(req.Method).To(Equal("GET")) + Expect(req.URL.Query()["account_id"]).To(Equal([]string{"abc"})) + Expect(req.URL.Query()["month"]).To(Equal([]string{"2023-02"})) + // TODO: Add check for date_from query parameter + // TODO: Add check for date_to query parameter + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprint(res, `} this is not valid json {`) + })) + }) + It(`Invoke GetReportsSnapshot with error: Operation response processing error`, func() { + usageReportsService, serviceErr := usagereportsv4.NewUsageReportsV4(&usagereportsv4.UsageReportsV4Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(usageReportsService).ToNot(BeNil()) + + // Construct an instance of the GetReportsSnapshotOptions model + getReportsSnapshotOptionsModel := new(usagereportsv4.GetReportsSnapshotOptions) + getReportsSnapshotOptionsModel.AccountID = core.StringPtr("abc") + getReportsSnapshotOptionsModel.Month = core.StringPtr("2023-02") + getReportsSnapshotOptionsModel.DateFrom = core.Float64Ptr(float64(1675209600000)) + getReportsSnapshotOptionsModel.DateTo = core.Float64Ptr(float64(1675987200000)) + getReportsSnapshotOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Expect response parsing to fail since we are receiving a text/plain response + result, response, operationErr := usageReportsService.GetReportsSnapshot(getReportsSnapshotOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + usageReportsService.EnableRetries(0, 0) + result, response, operationErr = usageReportsService.GetReportsSnapshot(getReportsSnapshotOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`GetReportsSnapshot(getReportsSnapshotOptions *GetReportsSnapshotOptions)`, func() { + getReportsSnapshotPath := "/v1/billing-reports-snapshots" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getReportsSnapshotPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.URL.Query()["account_id"]).To(Equal([]string{"abc"})) + Expect(req.URL.Query()["month"]).To(Equal([]string{"2023-02"})) + // TODO: Add check for date_from query parameter + // TODO: Add check for date_to query parameter + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"count": 3, "first": {"href": "/v1/billing-reports-snapshots?_limit=10&account_id=272b9a4f73e11030d0ba037daee47a35&date_from=-Infinity&date_to=Infinity&month=2023-06"}, "next": {"href": "/v1/billing-reports-snapshots?_limit=10&account_id=272b9a4f73e11030d0ba037daee47a35&date_from=-Infinity&date_to=Infinity&month=2023-06"}, "snapshots": [{"account_id": "abc", "month": "2023-06", "account_type": "account", "expected_processed_at": 1687470383610, "state": "enabled", "billing_period": {"start": "2023-06-01T00:00:00.000Z", "end": "2023-06-30T23:59:59.999Z"}, "snapshot_id": "1685577600000", "charset": "UTF-8", "compression": "GZIP", "content_type": "text/csv", "bucket": "bucket_name", "version": "1.0", "created_on": "2023-06-22T21:47:28.297Z", "report_types": [{"type": "account_summary", "version": "1.0"}], "files": [{"report_types": "account_summary", "location": "june/2023-06/1685577600000/2023-06-account-summary-272b9a4f73e11030d0ba037daee47a35.csv.gz", "account_id": "abc"}], "processed_at": 1687470448297}]}`) + })) + }) + It(`Invoke GetReportsSnapshot successfully with retries`, func() { + usageReportsService, serviceErr := usagereportsv4.NewUsageReportsV4(&usagereportsv4.UsageReportsV4Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(usageReportsService).ToNot(BeNil()) + usageReportsService.EnableRetries(0, 0) + + // Construct an instance of the GetReportsSnapshotOptions model + getReportsSnapshotOptionsModel := new(usagereportsv4.GetReportsSnapshotOptions) + getReportsSnapshotOptionsModel.AccountID = core.StringPtr("abc") + getReportsSnapshotOptionsModel.Month = core.StringPtr("2023-02") + getReportsSnapshotOptionsModel.DateFrom = core.Float64Ptr(float64(1675209600000)) + getReportsSnapshotOptionsModel.DateTo = core.Float64Ptr(float64(1675987200000)) + getReportsSnapshotOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := usageReportsService.GetReportsSnapshotWithContext(ctx, getReportsSnapshotOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + usageReportsService.DisableRetries() + result, response, operationErr := usageReportsService.GetReportsSnapshot(getReportsSnapshotOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = usageReportsService.GetReportsSnapshotWithContext(ctx, getReportsSnapshotOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getReportsSnapshotPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.URL.Query()["account_id"]).To(Equal([]string{"abc"})) + Expect(req.URL.Query()["month"]).To(Equal([]string{"2023-02"})) + // TODO: Add check for date_from query parameter + // TODO: Add check for date_to query parameter + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"count": 3, "first": {"href": "/v1/billing-reports-snapshots?_limit=10&account_id=272b9a4f73e11030d0ba037daee47a35&date_from=-Infinity&date_to=Infinity&month=2023-06"}, "next": {"href": "/v1/billing-reports-snapshots?_limit=10&account_id=272b9a4f73e11030d0ba037daee47a35&date_from=-Infinity&date_to=Infinity&month=2023-06"}, "snapshots": [{"account_id": "abc", "month": "2023-06", "account_type": "account", "expected_processed_at": 1687470383610, "state": "enabled", "billing_period": {"start": "2023-06-01T00:00:00.000Z", "end": "2023-06-30T23:59:59.999Z"}, "snapshot_id": "1685577600000", "charset": "UTF-8", "compression": "GZIP", "content_type": "text/csv", "bucket": "bucket_name", "version": "1.0", "created_on": "2023-06-22T21:47:28.297Z", "report_types": [{"type": "account_summary", "version": "1.0"}], "files": [{"report_types": "account_summary", "location": "june/2023-06/1685577600000/2023-06-account-summary-272b9a4f73e11030d0ba037daee47a35.csv.gz", "account_id": "abc"}], "processed_at": 1687470448297}]}`) + })) + }) + It(`Invoke GetReportsSnapshot successfully`, func() { + usageReportsService, serviceErr := usagereportsv4.NewUsageReportsV4(&usagereportsv4.UsageReportsV4Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(usageReportsService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := usageReportsService.GetReportsSnapshot(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the GetReportsSnapshotOptions model + getReportsSnapshotOptionsModel := new(usagereportsv4.GetReportsSnapshotOptions) + getReportsSnapshotOptionsModel.AccountID = core.StringPtr("abc") + getReportsSnapshotOptionsModel.Month = core.StringPtr("2023-02") + getReportsSnapshotOptionsModel.DateFrom = core.Float64Ptr(float64(1675209600000)) + getReportsSnapshotOptionsModel.DateTo = core.Float64Ptr(float64(1675987200000)) + getReportsSnapshotOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = usageReportsService.GetReportsSnapshot(getReportsSnapshotOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke GetReportsSnapshot with error: Operation validation and request error`, func() { + usageReportsService, serviceErr := usagereportsv4.NewUsageReportsV4(&usagereportsv4.UsageReportsV4Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(usageReportsService).ToNot(BeNil()) + + // Construct an instance of the GetReportsSnapshotOptions model + getReportsSnapshotOptionsModel := new(usagereportsv4.GetReportsSnapshotOptions) + getReportsSnapshotOptionsModel.AccountID = core.StringPtr("abc") + getReportsSnapshotOptionsModel.Month = core.StringPtr("2023-02") + getReportsSnapshotOptionsModel.DateFrom = core.Float64Ptr(float64(1675209600000)) + getReportsSnapshotOptionsModel.DateTo = core.Float64Ptr(float64(1675987200000)) + getReportsSnapshotOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := usageReportsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := usageReportsService.GetReportsSnapshot(getReportsSnapshotOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + // Construct a second instance of the GetReportsSnapshotOptions model with no property values + getReportsSnapshotOptionsModelNew := new(usagereportsv4.GetReportsSnapshotOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = usageReportsService.GetReportsSnapshot(getReportsSnapshotOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke GetReportsSnapshot successfully`, func() { + usageReportsService, serviceErr := usagereportsv4.NewUsageReportsV4(&usagereportsv4.UsageReportsV4Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(usageReportsService).ToNot(BeNil()) + + // Construct an instance of the GetReportsSnapshotOptions model + getReportsSnapshotOptionsModel := new(usagereportsv4.GetReportsSnapshotOptions) + getReportsSnapshotOptionsModel.AccountID = core.StringPtr("abc") + getReportsSnapshotOptionsModel.Month = core.StringPtr("2023-02") + getReportsSnapshotOptionsModel.DateFrom = core.Float64Ptr(float64(1675209600000)) + getReportsSnapshotOptionsModel.DateTo = core.Float64Ptr(float64(1675987200000)) + getReportsSnapshotOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := usageReportsService.GetReportsSnapshot(getReportsSnapshotOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) Describe(`Model constructor tests`, func() { Context(`Using a service client instance`, func() { usageReportsService, _ := usagereportsv4.NewUsageReportsV4(&usagereportsv4.UsageReportsV4Options{ URL: "http://usagereportsv4modelgenerator.com", Authenticator: &core.NoAuthAuthenticator{}, }) + It(`Invoke NewCreateReportsSnapshotConfigOptions successfully`, func() { + // Construct an instance of the CreateReportsSnapshotConfigOptions model + createReportsSnapshotConfigOptionsAccountID := "abc" + createReportsSnapshotConfigOptionsInterval := "daily" + createReportsSnapshotConfigOptionsCosBucket := "bucket_name" + createReportsSnapshotConfigOptionsCosLocation := "us-south" + createReportsSnapshotConfigOptionsModel := usageReportsService.NewCreateReportsSnapshotConfigOptions(createReportsSnapshotConfigOptionsAccountID, createReportsSnapshotConfigOptionsInterval, createReportsSnapshotConfigOptionsCosBucket, createReportsSnapshotConfigOptionsCosLocation) + createReportsSnapshotConfigOptionsModel.SetAccountID("abc") + createReportsSnapshotConfigOptionsModel.SetInterval("daily") + createReportsSnapshotConfigOptionsModel.SetCosBucket("bucket_name") + createReportsSnapshotConfigOptionsModel.SetCosLocation("us-south") + createReportsSnapshotConfigOptionsModel.SetCosReportsFolder("IBMCloud-Billing-Reports") + createReportsSnapshotConfigOptionsModel.SetReportTypes([]string{"account_summary", "enterprise_summary", "account_resource_instance_usage"}) + createReportsSnapshotConfigOptionsModel.SetVersioning("new") + createReportsSnapshotConfigOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(createReportsSnapshotConfigOptionsModel).ToNot(BeNil()) + Expect(createReportsSnapshotConfigOptionsModel.AccountID).To(Equal(core.StringPtr("abc"))) + Expect(createReportsSnapshotConfigOptionsModel.Interval).To(Equal(core.StringPtr("daily"))) + Expect(createReportsSnapshotConfigOptionsModel.CosBucket).To(Equal(core.StringPtr("bucket_name"))) + Expect(createReportsSnapshotConfigOptionsModel.CosLocation).To(Equal(core.StringPtr("us-south"))) + Expect(createReportsSnapshotConfigOptionsModel.CosReportsFolder).To(Equal(core.StringPtr("IBMCloud-Billing-Reports"))) + Expect(createReportsSnapshotConfigOptionsModel.ReportTypes).To(Equal([]string{"account_summary", "enterprise_summary", "account_resource_instance_usage"})) + Expect(createReportsSnapshotConfigOptionsModel.Versioning).To(Equal(core.StringPtr("new"))) + Expect(createReportsSnapshotConfigOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewDeleteReportsSnapshotConfigOptions successfully`, func() { + // Construct an instance of the DeleteReportsSnapshotConfigOptions model + accountID := "abc" + deleteReportsSnapshotConfigOptionsModel := usageReportsService.NewDeleteReportsSnapshotConfigOptions(accountID) + deleteReportsSnapshotConfigOptionsModel.SetAccountID("abc") + deleteReportsSnapshotConfigOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(deleteReportsSnapshotConfigOptionsModel).ToNot(BeNil()) + Expect(deleteReportsSnapshotConfigOptionsModel.AccountID).To(Equal(core.StringPtr("abc"))) + Expect(deleteReportsSnapshotConfigOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) It(`Invoke NewGetAccountSummaryOptions successfully`, func() { // Construct an instance of the GetAccountSummaryOptions model accountID := "testString" @@ -2385,6 +3521,33 @@ var _ = Describe(`UsageReportsV4`, func() { Expect(getOrgUsageOptionsModel.AcceptLanguage).To(Equal(core.StringPtr("testString"))) Expect(getOrgUsageOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) + It(`Invoke NewGetReportsSnapshotConfigOptions successfully`, func() { + // Construct an instance of the GetReportsSnapshotConfigOptions model + accountID := "abc" + getReportsSnapshotConfigOptionsModel := usageReportsService.NewGetReportsSnapshotConfigOptions(accountID) + getReportsSnapshotConfigOptionsModel.SetAccountID("abc") + getReportsSnapshotConfigOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(getReportsSnapshotConfigOptionsModel).ToNot(BeNil()) + Expect(getReportsSnapshotConfigOptionsModel.AccountID).To(Equal(core.StringPtr("abc"))) + Expect(getReportsSnapshotConfigOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewGetReportsSnapshotOptions successfully`, func() { + // Construct an instance of the GetReportsSnapshotOptions model + accountID := "abc" + month := "2023-02" + getReportsSnapshotOptionsModel := usageReportsService.NewGetReportsSnapshotOptions(accountID, month) + getReportsSnapshotOptionsModel.SetAccountID("abc") + getReportsSnapshotOptionsModel.SetMonth("2023-02") + getReportsSnapshotOptionsModel.SetDateFrom(float64(1675209600000)) + getReportsSnapshotOptionsModel.SetDateTo(float64(1675987200000)) + getReportsSnapshotOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(getReportsSnapshotOptionsModel).ToNot(BeNil()) + Expect(getReportsSnapshotOptionsModel.AccountID).To(Equal(core.StringPtr("abc"))) + Expect(getReportsSnapshotOptionsModel.Month).To(Equal(core.StringPtr("2023-02"))) + Expect(getReportsSnapshotOptionsModel.DateFrom).To(Equal(core.Float64Ptr(float64(1675209600000)))) + Expect(getReportsSnapshotOptionsModel.DateTo).To(Equal(core.Float64Ptr(float64(1675987200000)))) + Expect(getReportsSnapshotOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) It(`Invoke NewGetResourceGroupUsageOptions successfully`, func() { // Construct an instance of the GetResourceGroupUsageOptions model accountID := "testString" @@ -2413,8 +3576,9 @@ var _ = Describe(`UsageReportsV4`, func() { getResourceUsageAccountOptionsModel.SetAccountID("testString") getResourceUsageAccountOptionsModel.SetBillingmonth("testString") getResourceUsageAccountOptionsModel.SetNames(true) + getResourceUsageAccountOptionsModel.SetTags(true) getResourceUsageAccountOptionsModel.SetAcceptLanguage("testString") - getResourceUsageAccountOptionsModel.SetLimit(int64(1)) + getResourceUsageAccountOptionsModel.SetLimit(int64(30)) getResourceUsageAccountOptionsModel.SetStart("testString") getResourceUsageAccountOptionsModel.SetResourceGroupID("testString") getResourceUsageAccountOptionsModel.SetOrganizationID("testString") @@ -2427,8 +3591,9 @@ var _ = Describe(`UsageReportsV4`, func() { Expect(getResourceUsageAccountOptionsModel.AccountID).To(Equal(core.StringPtr("testString"))) Expect(getResourceUsageAccountOptionsModel.Billingmonth).To(Equal(core.StringPtr("testString"))) Expect(getResourceUsageAccountOptionsModel.Names).To(Equal(core.BoolPtr(true))) + Expect(getResourceUsageAccountOptionsModel.Tags).To(Equal(core.BoolPtr(true))) Expect(getResourceUsageAccountOptionsModel.AcceptLanguage).To(Equal(core.StringPtr("testString"))) - Expect(getResourceUsageAccountOptionsModel.Limit).To(Equal(core.Int64Ptr(int64(1)))) + Expect(getResourceUsageAccountOptionsModel.Limit).To(Equal(core.Int64Ptr(int64(30)))) Expect(getResourceUsageAccountOptionsModel.Start).To(Equal(core.StringPtr("testString"))) Expect(getResourceUsageAccountOptionsModel.ResourceGroupID).To(Equal(core.StringPtr("testString"))) Expect(getResourceUsageAccountOptionsModel.OrganizationID).To(Equal(core.StringPtr("testString"))) @@ -2448,8 +3613,9 @@ var _ = Describe(`UsageReportsV4`, func() { getResourceUsageOrgOptionsModel.SetOrganizationID("testString") getResourceUsageOrgOptionsModel.SetBillingmonth("testString") getResourceUsageOrgOptionsModel.SetNames(true) + getResourceUsageOrgOptionsModel.SetTags(true) getResourceUsageOrgOptionsModel.SetAcceptLanguage("testString") - getResourceUsageOrgOptionsModel.SetLimit(int64(1)) + getResourceUsageOrgOptionsModel.SetLimit(int64(30)) getResourceUsageOrgOptionsModel.SetStart("testString") getResourceUsageOrgOptionsModel.SetResourceInstanceID("testString") getResourceUsageOrgOptionsModel.SetResourceID("testString") @@ -2461,8 +3627,9 @@ var _ = Describe(`UsageReportsV4`, func() { Expect(getResourceUsageOrgOptionsModel.OrganizationID).To(Equal(core.StringPtr("testString"))) Expect(getResourceUsageOrgOptionsModel.Billingmonth).To(Equal(core.StringPtr("testString"))) Expect(getResourceUsageOrgOptionsModel.Names).To(Equal(core.BoolPtr(true))) + Expect(getResourceUsageOrgOptionsModel.Tags).To(Equal(core.BoolPtr(true))) Expect(getResourceUsageOrgOptionsModel.AcceptLanguage).To(Equal(core.StringPtr("testString"))) - Expect(getResourceUsageOrgOptionsModel.Limit).To(Equal(core.Int64Ptr(int64(1)))) + Expect(getResourceUsageOrgOptionsModel.Limit).To(Equal(core.Int64Ptr(int64(30)))) Expect(getResourceUsageOrgOptionsModel.Start).To(Equal(core.StringPtr("testString"))) Expect(getResourceUsageOrgOptionsModel.ResourceInstanceID).To(Equal(core.StringPtr("testString"))) Expect(getResourceUsageOrgOptionsModel.ResourceID).To(Equal(core.StringPtr("testString"))) @@ -2480,8 +3647,9 @@ var _ = Describe(`UsageReportsV4`, func() { getResourceUsageResourceGroupOptionsModel.SetResourceGroupID("testString") getResourceUsageResourceGroupOptionsModel.SetBillingmonth("testString") getResourceUsageResourceGroupOptionsModel.SetNames(true) + getResourceUsageResourceGroupOptionsModel.SetTags(true) getResourceUsageResourceGroupOptionsModel.SetAcceptLanguage("testString") - getResourceUsageResourceGroupOptionsModel.SetLimit(int64(1)) + getResourceUsageResourceGroupOptionsModel.SetLimit(int64(30)) getResourceUsageResourceGroupOptionsModel.SetStart("testString") getResourceUsageResourceGroupOptionsModel.SetResourceInstanceID("testString") getResourceUsageResourceGroupOptionsModel.SetResourceID("testString") @@ -2493,8 +3661,9 @@ var _ = Describe(`UsageReportsV4`, func() { Expect(getResourceUsageResourceGroupOptionsModel.ResourceGroupID).To(Equal(core.StringPtr("testString"))) Expect(getResourceUsageResourceGroupOptionsModel.Billingmonth).To(Equal(core.StringPtr("testString"))) Expect(getResourceUsageResourceGroupOptionsModel.Names).To(Equal(core.BoolPtr(true))) + Expect(getResourceUsageResourceGroupOptionsModel.Tags).To(Equal(core.BoolPtr(true))) Expect(getResourceUsageResourceGroupOptionsModel.AcceptLanguage).To(Equal(core.StringPtr("testString"))) - Expect(getResourceUsageResourceGroupOptionsModel.Limit).To(Equal(core.Int64Ptr(int64(1)))) + Expect(getResourceUsageResourceGroupOptionsModel.Limit).To(Equal(core.Int64Ptr(int64(30)))) Expect(getResourceUsageResourceGroupOptionsModel.Start).To(Equal(core.StringPtr("testString"))) Expect(getResourceUsageResourceGroupOptionsModel.ResourceInstanceID).To(Equal(core.StringPtr("testString"))) Expect(getResourceUsageResourceGroupOptionsModel.ResourceID).To(Equal(core.StringPtr("testString"))) @@ -2502,6 +3671,28 @@ var _ = Describe(`UsageReportsV4`, func() { Expect(getResourceUsageResourceGroupOptionsModel.Region).To(Equal(core.StringPtr("testString"))) Expect(getResourceUsageResourceGroupOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) + It(`Invoke NewUpdateReportsSnapshotConfigOptions successfully`, func() { + // Construct an instance of the UpdateReportsSnapshotConfigOptions model + updateReportsSnapshotConfigOptionsAccountID := "abc" + updateReportsSnapshotConfigOptionsModel := usageReportsService.NewUpdateReportsSnapshotConfigOptions(updateReportsSnapshotConfigOptionsAccountID) + updateReportsSnapshotConfigOptionsModel.SetAccountID("abc") + updateReportsSnapshotConfigOptionsModel.SetInterval("daily") + updateReportsSnapshotConfigOptionsModel.SetCosBucket("bucket_name") + updateReportsSnapshotConfigOptionsModel.SetCosLocation("us-south") + updateReportsSnapshotConfigOptionsModel.SetCosReportsFolder("IBMCloud-Billing-Reports") + updateReportsSnapshotConfigOptionsModel.SetReportTypes([]string{"account_summary", "enterprise_summary", "account_resource_instance_usage"}) + updateReportsSnapshotConfigOptionsModel.SetVersioning("new") + updateReportsSnapshotConfigOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(updateReportsSnapshotConfigOptionsModel).ToNot(BeNil()) + Expect(updateReportsSnapshotConfigOptionsModel.AccountID).To(Equal(core.StringPtr("abc"))) + Expect(updateReportsSnapshotConfigOptionsModel.Interval).To(Equal(core.StringPtr("daily"))) + Expect(updateReportsSnapshotConfigOptionsModel.CosBucket).To(Equal(core.StringPtr("bucket_name"))) + Expect(updateReportsSnapshotConfigOptionsModel.CosLocation).To(Equal(core.StringPtr("us-south"))) + Expect(updateReportsSnapshotConfigOptionsModel.CosReportsFolder).To(Equal(core.StringPtr("IBMCloud-Billing-Reports"))) + Expect(updateReportsSnapshotConfigOptionsModel.ReportTypes).To(Equal([]string{"account_summary", "enterprise_summary", "account_resource_instance_usage"})) + Expect(updateReportsSnapshotConfigOptionsModel.Versioning).To(Equal(core.StringPtr("new"))) + Expect(updateReportsSnapshotConfigOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) }) }) Describe(`Utility function tests`, func() {