From 1c437e27bf11e3763223be725543648bb7b6833a Mon Sep 17 00:00:00 2001 From: "manu.k.m" Date: Thu, 24 Aug 2023 22:06:57 +0530 Subject: [PATCH] feat(Usage Reports): add billing snapshot config service to usage reports --- usagereportsv4/usage_reports_v4.go | 1509 +++++++++++++++++++++-- usagereportsv4/usage_reports_v4_test.go | 1216 ++++++++++++++++-- 2 files changed, 2526 insertions(+), 199 deletions(-) diff --git a/usagereportsv4/usage_reports_v4.go b/usagereportsv4/usage_reports_v4.go index 18af7f7e..cbf496a7 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 @@ -178,7 +178,7 @@ func (usageReports *UsageReportsV4) GetAccountSummaryWithContext(ctx context.Con } pathParamsMap := map[string]string{ - "account_id": *getAccountSummaryOptions.AccountID, + "account_id": *getAccountSummaryOptions.AccountID, "billingmonth": *getAccountSummaryOptions.Billingmonth, } @@ -240,7 +240,7 @@ func (usageReports *UsageReportsV4) GetAccountUsageWithContext(ctx context.Conte } pathParamsMap := map[string]string{ - "account_id": *getAccountUsageOptions.AccountID, + "account_id": *getAccountUsageOptions.AccountID, "billingmonth": *getAccountUsageOptions.Billingmonth, } @@ -309,9 +309,9 @@ func (usageReports *UsageReportsV4) GetResourceGroupUsageWithContext(ctx context } pathParamsMap := map[string]string{ - "account_id": *getResourceGroupUsageOptions.AccountID, + "account_id": *getResourceGroupUsageOptions.AccountID, "resource_group_id": *getResourceGroupUsageOptions.ResourceGroupID, - "billingmonth": *getResourceGroupUsageOptions.Billingmonth, + "billingmonth": *getResourceGroupUsageOptions.Billingmonth, } builder := core.NewRequestBuilder(core.GET) @@ -379,7 +379,7 @@ func (usageReports *UsageReportsV4) GetResourceUsageAccountWithContext(ctx conte } pathParamsMap := map[string]string{ - "account_id": *getResourceUsageAccountOptions.AccountID, + "account_id": *getResourceUsageAccountOptions.AccountID, "billingmonth": *getResourceUsageAccountOptions.Billingmonth, } @@ -472,9 +472,9 @@ func (usageReports *UsageReportsV4) GetResourceUsageResourceGroupWithContext(ctx } pathParamsMap := map[string]string{ - "account_id": *getResourceUsageResourceGroupOptions.AccountID, + "account_id": *getResourceUsageResourceGroupOptions.AccountID, "resource_group_id": *getResourceUsageResourceGroupOptions.ResourceGroupID, - "billingmonth": *getResourceUsageResourceGroupOptions.Billingmonth, + "billingmonth": *getResourceUsageResourceGroupOptions.Billingmonth, } builder := core.NewRequestBuilder(core.GET) @@ -560,9 +560,9 @@ func (usageReports *UsageReportsV4) GetResourceUsageOrgWithContext(ctx context.C } pathParamsMap := map[string]string{ - "account_id": *getResourceUsageOrgOptions.AccountID, + "account_id": *getResourceUsageOrgOptions.AccountID, "organization_id": *getResourceUsageOrgOptions.OrganizationID, - "billingmonth": *getResourceUsageOrgOptions.Billingmonth, + "billingmonth": *getResourceUsageOrgOptions.Billingmonth, } builder := core.NewRequestBuilder(core.GET) @@ -648,9 +648,9 @@ func (usageReports *UsageReportsV4) GetOrgUsageWithContext(ctx context.Context, } pathParamsMap := map[string]string{ - "account_id": *getOrgUsageOptions.AccountID, + "account_id": *getOrgUsageOptions.AccountID, "organization_id": *getOrgUsageOptions.OrganizationID, - "billingmonth": *getOrgUsageOptions.Billingmonth, + "billingmonth": *getOrgUsageOptions.Billingmonth, } builder := core.NewRequestBuilder(core.GET) @@ -699,79 +699,1120 @@ 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. AccountID *string `json:"account_id" validate:"required"` - // The list of account resources for the month. - AccountResources []Resource `json:"account_resources,omitempty"` + // The list of account resources for the month. + AccountResources []Resource `json:"account_resources,omitempty"` + + // The month in which usages were incurred. Represented in yyyy-mm format. + Month *string `json:"month" validate:"required"` + + // Country. + BillingCountryCode *string `json:"billing_country_code" validate:"required"` + + // The currency in which the account is billed. + BillingCurrencyCode *string `json:"billing_currency_code" validate:"required"` + + // Charges related to cloud resources. + Resources *ResourcesSummary `json:"resources" validate:"required"` + + // The list of offers applicable for the account for the month. + Offers []Offer `json:"offers" validate:"required"` + + // Support-related charges. + Support []SupportSummary `json:"support" validate:"required"` + + // The list of support resources for the month. + SupportResources []interface{} `json:"support_resources,omitempty"` + + // A summary of charges and credits related to a subscription. + Subscription *SubscriptionSummary `json:"subscription" validate:"required"` +} + +// UnmarshalAccountSummary unmarshals an instance of AccountSummary from the specified map of raw messages. +func UnmarshalAccountSummary(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(AccountSummary) + err = core.UnmarshalPrimitive(m, "account_id", &obj.AccountID) + if err != nil { + return + } + err = core.UnmarshalModel(m, "account_resources", &obj.AccountResources, UnmarshalResource) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "month", &obj.Month) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "billing_country_code", &obj.BillingCountryCode) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "billing_currency_code", &obj.BillingCurrencyCode) + if err != nil { + return + } + err = core.UnmarshalModel(m, "resources", &obj.Resources, UnmarshalResourcesSummary) + if err != nil { + return + } + err = core.UnmarshalModel(m, "offers", &obj.Offers, UnmarshalOffer) + if err != nil { + return + } + err = core.UnmarshalModel(m, "support", &obj.Support, UnmarshalSupportSummary) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "support_resources", &obj.SupportResources) + if err != nil { + return + } + err = core.UnmarshalModel(m, "subscription", &obj.Subscription, UnmarshalSubscriptionSummary) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// AccountUsage : The aggregated usage and charges for all the plans in the account. +type AccountUsage struct { + // The ID of the account. + AccountID *string `json:"account_id" validate:"required"` + + // The target country pricing that should be used. + PricingCountry *string `json:"pricing_country" validate:"required"` + + // The currency for the cost fields in the resources, plans and metrics. + CurrencyCode *string `json:"currency_code" validate:"required"` + + // The month. + Month *string `json:"month" validate:"required"` + + // All the resource used in the account. + Resources []Resource `json:"resources" validate:"required"` + + // The value of the account's currency in USD. + CurrencyRate *float64 `json:"currency_rate,omitempty"` +} + +// UnmarshalAccountUsage unmarshals an instance of AccountUsage from the specified map of raw messages. +func UnmarshalAccountUsage(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(AccountUsage) + err = core.UnmarshalPrimitive(m, "account_id", &obj.AccountID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "pricing_country", &obj.PricingCountry) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "currency_code", &obj.CurrencyCode) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "month", &obj.Month) + if err != nil { + return + } + err = core.UnmarshalModel(m, "resources", &obj.Resources, UnmarshalResource) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "currency_rate", &obj.CurrencyRate) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// CreateReportsSnapshotConfigOptions : The CreateReportsSnapshotConfig options. +type CreateReportsSnapshotConfigOptions 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" validate:"required"` + + // The name of the COS bucket to store the snapshot of the billing reports. + CosBucket *string `json:"cos_bucket" 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 +} + +// 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 + } + err = core.UnmarshalPrimitive(m, "name", &obj.Name) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "display_name", &obj.DisplayName) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "discount", &obj.Discount) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// GetAccountSummaryOptions : The GetAccountSummary options. +type GetAccountSummaryOptions struct { + // Account ID for which the usage report is requested. + AccountID *string `json:"account_id" validate:"required,ne="` + + // The billing month for which the usage report is requested. Format is yyyy-mm. + Billingmonth *string `json:"billingmonth" validate:"required,ne="` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewGetAccountSummaryOptions : Instantiate GetAccountSummaryOptions +func (*UsageReportsV4) NewGetAccountSummaryOptions(accountID string, billingmonth string) *GetAccountSummaryOptions { + return &GetAccountSummaryOptions{ + AccountID: core.StringPtr(accountID), + Billingmonth: core.StringPtr(billingmonth), + } +} + +// SetAccountID : Allow user to set AccountID +func (_options *GetAccountSummaryOptions) SetAccountID(accountID string) *GetAccountSummaryOptions { + _options.AccountID = core.StringPtr(accountID) + return _options +} + +// SetBillingmonth : Allow user to set Billingmonth +func (_options *GetAccountSummaryOptions) SetBillingmonth(billingmonth string) *GetAccountSummaryOptions { + _options.Billingmonth = core.StringPtr(billingmonth) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *GetAccountSummaryOptions) SetHeaders(param map[string]string) *GetAccountSummaryOptions { + options.Headers = param + 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 *int64 `json:"date_from,omitempty"` + + // Timestamp in milliseconds for which billing report snapshot is requested. + DateTo *int64 `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 int64) *GetReportsSnapshotOptions { + _options.DateFrom = core.Int64Ptr(dateFrom) + return _options +} + +// SetDateTo : Allow user to set DateTo +func (_options *GetReportsSnapshotOptions) SetDateTo(dateTo int64) *GetReportsSnapshotOptions { + _options.DateTo = core.Int64Ptr(dateTo) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *GetReportsSnapshotOptions) SetHeaders(param map[string]string) *GetReportsSnapshotOptions { + options.Headers = param + return options +} + +// SnapshotConfigHistoryItem : SnapshotConfigHistoryItem struct +type SnapshotConfigHistoryItem struct { + // Timestamp in milliseconds when the snapshot configuration was created. + StartTime *int64 `json:"start_time,omitempty"` + + // Timestamp in milliseconds when the snapshot configuration ends. + EndTime *int64 `json:"end_time,omitempty"` + + // Account that updated the billing snapshot configuration. + UpdatedBy *string `json:"updated_by,omitempty"` + + // 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 [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"` +} + +// 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, "end_time", &obj.EndTime) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "updated_by", &obj.UpdatedBy) + if err != nil { + return + } + 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 + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// SnapshotList : List of billing reports snapshots. +type SnapshotList struct { + // Number of total snapshots. + Count *int64 `json:"count,omitempty"` + + // Reference to the first page of the search query. + First *SnapshotListFirst `json:"first,omitempty"` + + // Reference to the next page of the search query if any. + Next *SnapshotListNext `json:"next,omitempty"` + + Snapshots []SnapshotListSnapshotsItem `json:"snapshots,omitempty"` +} + +// 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.UnmarshalModel(m, "first", &obj.First, UnmarshalSnapshotListFirst) + if err != nil { + return + } + err = core.UnmarshalModel(m, "next", &obj.Next, UnmarshalSnapshotListNext) + if err != nil { + return + } + err = core.UnmarshalModel(m, "snapshots", &obj.Snapshots, UnmarshalSnapshotListSnapshotsItem) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// 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"` +} - // The month in which usages were incurred. Represented in yyyy-mm format. - Month *string `json:"month" validate:"required"` +// 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 +} - // Country. - BillingCountryCode *string `json:"billing_country_code" validate:"required"` +// SnapshotListSnapshotsItem : Snapshot Schema. +type SnapshotListSnapshotsItem struct { + // Account ID for which billing report snapshot is configured. + AccountID *string `json:"account_id,omitempty"` - // The currency in which the account is billed. - BillingCurrencyCode *string `json:"billing_currency_code" validate:"required"` + // Month of captured snapshot. + Month *string `json:"month,omitempty"` - // Charges related to cloud resources. - Resources *ResourcesSummary `json:"resources" validate:"required"` + // Type of account. Possible values are [enterprise, account]. + AccountType *string `json:"account_type,omitempty"` - // The list of offers applicable for the account for the month. - Offers []Offer `json:"offers" validate:"required"` + // Timestamp of snapshot processed. + ExpectedProcessedAt *int64 `json:"expected_processed_at,omitempty"` - // Support-related charges. - Support []SupportSummary `json:"support" validate:"required"` + // Status of the billing snapshot configuration. Possible values are [enabled, disabled]. + State *string `json:"state,omitempty"` - // The list of support resources for the month. - SupportResources []interface{} `json:"support_resources,omitempty"` + // Period of billing in snapshot. + BillingPeriod *SnapshotListSnapshotsItemBillingPeriod `json:"billing_period,omitempty"` - // A summary of charges and credits related to a subscription. - Subscription *SubscriptionSummary `json:"subscription" validate:"required"` + // 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 *int64 `json:"processed_at,omitempty"` } -// UnmarshalAccountSummary unmarshals an instance of AccountSummary from the specified map of raw messages. -func UnmarshalAccountSummary(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(AccountSummary) +// 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.UnmarshalModel(m, "account_resources", &obj.AccountResources, UnmarshalResource) + err = core.UnmarshalPrimitive(m, "month", &obj.Month) if err != nil { return } - err = core.UnmarshalPrimitive(m, "month", &obj.Month) + err = core.UnmarshalPrimitive(m, "account_type", &obj.AccountType) if err != nil { return } - err = core.UnmarshalPrimitive(m, "billing_country_code", &obj.BillingCountryCode) + err = core.UnmarshalPrimitive(m, "expected_processed_at", &obj.ExpectedProcessedAt) if err != nil { return } - err = core.UnmarshalPrimitive(m, "billing_currency_code", &obj.BillingCurrencyCode) + err = core.UnmarshalPrimitive(m, "state", &obj.State) if err != nil { return } - err = core.UnmarshalModel(m, "resources", &obj.Resources, UnmarshalResourcesSummary) + err = core.UnmarshalModel(m, "billing_period", &obj.BillingPeriod, UnmarshalSnapshotListSnapshotsItemBillingPeriod) if err != nil { return } - err = core.UnmarshalModel(m, "offers", &obj.Offers, UnmarshalOffer) + err = core.UnmarshalPrimitive(m, "snapshot_id", &obj.SnapshotID) if err != nil { return } - err = core.UnmarshalModel(m, "support", &obj.Support, UnmarshalSupportSummary) + err = core.UnmarshalPrimitive(m, "charset", &obj.Charset) if err != nil { return } - err = core.UnmarshalPrimitive(m, "support_resources", &obj.SupportResources) + err = core.UnmarshalPrimitive(m, "compression", &obj.Compression) if err != nil { return } - err = core.UnmarshalModel(m, "subscription", &obj.Subscription, UnmarshalSubscriptionSummary) + 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 } @@ -779,51 +1820,98 @@ func UnmarshalAccountSummary(m map[string]json.RawMessage, result interface{}) ( return } -// AccountUsage : The aggregated usage and charges for all the plans in the account. -type AccountUsage struct { - // The ID of the account. - AccountID *string `json:"account_id" validate:"required"` +// 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"` - // The target country pricing that should be used. - PricingCountry *string `json:"pricing_country" validate:"required"` + // Date and time of end of billing in the respective snapshot. + End *string `json:"end,omitempty"` +} - // The currency for the cost fields in the resources, plans and metrics. - CurrencyCode *string `json:"currency_code" validate:"required"` +// 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 +} - // The month. - Month *string `json:"month" validate:"required"` +// 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"` - // All the resource used in the account. - Resources []Resource `json:"resources" validate:"required"` + // Absolute path of the billing report in the COS instance. + Location *string `json:"location,omitempty"` - // The value of the account's currency in USD. - CurrencyRate *float64 `json:"currency_rate,omitempty"` + // Account ID for which billing report is captured. + AccountID *string `json:"account_id,omitempty"` } -// UnmarshalAccountUsage unmarshals an instance of AccountUsage from the specified map of raw messages. -func UnmarshalAccountUsage(m map[string]json.RawMessage, result interface{}) (err error) { - obj := new(AccountUsage) - err = core.UnmarshalPrimitive(m, "account_id", &obj.AccountID) - if err != nil { - return - } - err = core.UnmarshalPrimitive(m, "pricing_country", &obj.PricingCountry) +// 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, "currency_code", &obj.CurrencyCode) + err = core.UnmarshalPrimitive(m, "location", &obj.Location) if err != nil { return } - err = core.UnmarshalPrimitive(m, "month", &obj.Month) + err = core.UnmarshalPrimitive(m, "account_id", &obj.AccountID) if err != nil { return } - err = core.UnmarshalModel(m, "resources", &obj.Resources, UnmarshalResource) + 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, "currency_rate", &obj.CurrencyRate) + err = core.UnmarshalPrimitive(m, "version", &obj.Version) if err != nil { return } @@ -831,37 +1919,149 @@ 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"` +// SnapshotConfig : Billing reports snapshot configuration. +type SnapshotConfig struct { + // Account ID for which billing report snapshot is configured. + AccountID *string `json:"account_id,omitempty"` - // The name of the discount indicating category. - Name *string `json:"name,omitempty"` + // Status of the billing snapshot configuration. Possible values are [enabled, disabled]. + State *string `json:"state,omitempty"` - // The name of the discount. - DisplayName *string `json:"display_name,omitempty"` + // Type of account. Possible values are [enterprise, account]. + AccountType *string `json:"account_type,omitempty"` - // The discount percentage. - Discount *float64 `json:"discount" validate:"required"` + // 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 *int64 `json:"created_at,omitempty"` + + // Timestamp in milliseconds when the snapshot configuration was last updated. + LastUpdatedAt *int64 `json:"last_updated_at,omitempty"` + + // List of previous versions of the snapshot configurations. + History []SnapshotConfigHistoryItem `json:"history,omitempty"` } -// 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 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, "name", &obj.Name) + err = core.UnmarshalPrimitive(m, "state", &obj.State) if err != nil { return } - err = core.UnmarshalPrimitive(m, "display_name", &obj.DisplayName) + err = core.UnmarshalPrimitive(m, "account_type", &obj.AccountType) if err != nil { return } - err = core.UnmarshalPrimitive(m, "discount", &obj.Discount) + 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 } @@ -869,40 +2069,105 @@ func UnmarshalDiscount(m map[string]json.RawMessage, result interface{}) (err er return } -// GetAccountSummaryOptions : The GetAccountSummary options. -type GetAccountSummaryOptions struct { - // Account ID for which the usage report is requested. - AccountID *string `json:"account_id" validate:"required,ne="` +// UpdateReportsSnapshotConfigOptions : The UpdateReportsSnapshotConfig options. +type UpdateReportsSnapshotConfigOptions struct { + // Account ID for which billing report snapshot is configured. + AccountID *string `json:"account_id" validate:"required"` - // The billing month for which the usage report is requested. Format is yyyy-mm. - Billingmonth *string `json:"billingmonth" validate:"required,ne="` + // 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 } -// NewGetAccountSummaryOptions : Instantiate GetAccountSummaryOptions -func (*UsageReportsV4) NewGetAccountSummaryOptions(accountID string, billingmonth string) *GetAccountSummaryOptions { - return &GetAccountSummaryOptions{ +// 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), - Billingmonth: core.StringPtr(billingmonth), } } // SetAccountID : Allow user to set AccountID -func (_options *GetAccountSummaryOptions) SetAccountID(accountID string) *GetAccountSummaryOptions { +func (_options *UpdateReportsSnapshotConfigOptions) SetAccountID(accountID string) *UpdateReportsSnapshotConfigOptions { _options.AccountID = core.StringPtr(accountID) return _options } -// SetBillingmonth : Allow user to set Billingmonth -func (_options *GetAccountSummaryOptions) SetBillingmonth(billingmonth string) *GetAccountSummaryOptions { - _options.Billingmonth = core.StringPtr(billingmonth) +// 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 *GetAccountSummaryOptions) SetHeaders(param map[string]string) *GetAccountSummaryOptions { +func (options *UpdateReportsSnapshotConfigOptions) SetHeaders(param map[string]string) *UpdateReportsSnapshotConfigOptions { options.Headers = param return options } @@ -928,7 +2193,7 @@ type GetAccountUsageOptions struct { // NewGetAccountUsageOptions : Instantiate GetAccountUsageOptions func (*UsageReportsV4) NewGetAccountUsageOptions(accountID string, billingmonth string) *GetAccountUsageOptions { return &GetAccountUsageOptions{ - AccountID: core.StringPtr(accountID), + AccountID: core.StringPtr(accountID), Billingmonth: core.StringPtr(billingmonth), } } @@ -987,9 +2252,9 @@ type GetOrgUsageOptions struct { // NewGetOrgUsageOptions : Instantiate GetOrgUsageOptions func (*UsageReportsV4) NewGetOrgUsageOptions(accountID string, organizationID string, billingmonth string) *GetOrgUsageOptions { return &GetOrgUsageOptions{ - AccountID: core.StringPtr(accountID), + AccountID: core.StringPtr(accountID), OrganizationID: core.StringPtr(organizationID), - Billingmonth: core.StringPtr(billingmonth), + Billingmonth: core.StringPtr(billingmonth), } } @@ -1053,9 +2318,9 @@ type GetResourceGroupUsageOptions struct { // NewGetResourceGroupUsageOptions : Instantiate GetResourceGroupUsageOptions func (*UsageReportsV4) NewGetResourceGroupUsageOptions(accountID string, resourceGroupID string, billingmonth string) *GetResourceGroupUsageOptions { return &GetResourceGroupUsageOptions{ - AccountID: core.StringPtr(accountID), + AccountID: core.StringPtr(accountID), ResourceGroupID: core.StringPtr(resourceGroupID), - Billingmonth: core.StringPtr(billingmonth), + Billingmonth: core.StringPtr(billingmonth), } } @@ -1140,7 +2405,7 @@ type GetResourceUsageAccountOptions struct { // NewGetResourceUsageAccountOptions : Instantiate GetResourceUsageAccountOptions func (*UsageReportsV4) NewGetResourceUsageAccountOptions(accountID string, billingmonth string) *GetResourceUsageAccountOptions { return &GetResourceUsageAccountOptions{ - AccountID: core.StringPtr(accountID), + AccountID: core.StringPtr(accountID), Billingmonth: core.StringPtr(billingmonth), } } @@ -1265,9 +2530,9 @@ type GetResourceUsageOrgOptions struct { // NewGetResourceUsageOrgOptions : Instantiate GetResourceUsageOrgOptions func (*UsageReportsV4) NewGetResourceUsageOrgOptions(accountID string, organizationID string, billingmonth string) *GetResourceUsageOrgOptions { return &GetResourceUsageOrgOptions{ - AccountID: core.StringPtr(accountID), + AccountID: core.StringPtr(accountID), OrganizationID: core.StringPtr(organizationID), - Billingmonth: core.StringPtr(billingmonth), + Billingmonth: core.StringPtr(billingmonth), } } @@ -1385,9 +2650,9 @@ type GetResourceUsageResourceGroupOptions struct { // NewGetResourceUsageResourceGroupOptions : Instantiate GetResourceUsageResourceGroupOptions func (*UsageReportsV4) NewGetResourceUsageResourceGroupOptions(accountID string, resourceGroupID string, billingmonth string) *GetResourceUsageResourceGroupOptions { return &GetResourceUsageResourceGroupOptions{ - AccountID: core.StringPtr(accountID), + AccountID: core.StringPtr(accountID), ResourceGroupID: core.StringPtr(resourceGroupID), - Billingmonth: core.StringPtr(billingmonth), + Billingmonth: core.StringPtr(billingmonth), } } @@ -2393,13 +3658,11 @@ func UnmarshalSupportSummary(m map[string]json.RawMessage, result interface{}) ( return } -// // GetResourceUsageAccountPager can be used to simplify the use of the "GetResourceUsageAccount" method. -// type GetResourceUsageAccountPager struct { - hasNext bool - options *GetResourceUsageAccountOptions - client *UsageReportsV4 + hasNext bool + options *GetResourceUsageAccountOptions + client *UsageReportsV4 pageContext struct { next *string } @@ -2480,13 +3743,11 @@ func (pager *GetResourceUsageAccountPager) GetAll() (allItems []InstanceUsage, e return pager.GetAllWithContext(context.Background()) } -// // GetResourceUsageResourceGroupPager can be used to simplify the use of the "GetResourceUsageResourceGroup" method. -// type GetResourceUsageResourceGroupPager struct { - hasNext bool - options *GetResourceUsageResourceGroupOptions - client *UsageReportsV4 + hasNext bool + options *GetResourceUsageResourceGroupOptions + client *UsageReportsV4 pageContext struct { next *string } @@ -2567,13 +3828,11 @@ func (pager *GetResourceUsageResourceGroupPager) GetAll() (allItems []InstanceUs return pager.GetAllWithContext(context.Background()) } -// // GetResourceUsageOrgPager can be used to simplify the use of the "GetResourceUsageOrg" method. -// type GetResourceUsageOrgPager struct { - hasNext bool - options *GetResourceUsageOrgOptions - client *UsageReportsV4 + hasNext bool + options *GetResourceUsageOrgOptions + client *UsageReportsV4 pageContext struct { next *string } diff --git a/usagereportsv4/usage_reports_v4_test.go b/usagereportsv4/usage_reports_v4_test.go index 66e2e6c2..f929f6fd 100644 --- a/usagereportsv4/usage_reports_v4_test.go +++ b/usagereportsv4/usage_reports_v4_test.go @@ -66,14 +66,13 @@ var _ = Describe(`UsageReportsV4`, func() { Context(`Using external config, construct service client instances`, func() { // Map containing environment variables used in testing. var testEnvironment = map[string]string{ - "USAGE_REPORTS_URL": "https://usagereportsv4/api", + "USAGE_REPORTS_URL": "https://usagereportsv4/api", "USAGE_REPORTS_AUTH_TYPE": "noauth", } It(`Create service client using external config successfully`, func() { SetTestEnvironment(testEnvironment) - usageReportsService, serviceErr := usagereportsv4.NewUsageReportsV4UsingExternalConfig(&usagereportsv4.UsageReportsV4Options{ - }) + usageReportsService, serviceErr := usagereportsv4.NewUsageReportsV4UsingExternalConfig(&usagereportsv4.UsageReportsV4Options{}) Expect(usageReportsService).ToNot(BeNil()) Expect(serviceErr).To(BeNil()) ClearTestEnvironment(testEnvironment) @@ -102,8 +101,7 @@ var _ = Describe(`UsageReportsV4`, func() { }) It(`Create service client using external config and set url programatically successfully`, func() { SetTestEnvironment(testEnvironment) - usageReportsService, serviceErr := usagereportsv4.NewUsageReportsV4UsingExternalConfig(&usagereportsv4.UsageReportsV4Options{ - }) + usageReportsService, serviceErr := usagereportsv4.NewUsageReportsV4UsingExternalConfig(&usagereportsv4.UsageReportsV4Options{}) err := usageReportsService.SetServiceURL("https://testService/api") Expect(err).To(BeNil()) Expect(usageReportsService).ToNot(BeNil()) @@ -121,13 +119,12 @@ var _ = Describe(`UsageReportsV4`, func() { Context(`Using external config, construct service client instances with error: Invalid Auth`, func() { // Map containing environment variables used in testing. var testEnvironment = map[string]string{ - "USAGE_REPORTS_URL": "https://usagereportsv4/api", + "USAGE_REPORTS_URL": "https://usagereportsv4/api", "USAGE_REPORTS_AUTH_TYPE": "someOtherAuth", } SetTestEnvironment(testEnvironment) - usageReportsService, serviceErr := usagereportsv4.NewUsageReportsV4UsingExternalConfig(&usagereportsv4.UsageReportsV4Options{ - }) + usageReportsService, serviceErr := usagereportsv4.NewUsageReportsV4UsingExternalConfig(&usagereportsv4.UsageReportsV4Options{}) It(`Instantiate service client with error`, func() { Expect(usageReportsService).To(BeNil()) @@ -138,7 +135,7 @@ var _ = Describe(`UsageReportsV4`, func() { Context(`Using external config, construct service client instances with error: Invalid URL`, func() { // Map containing environment variables used in testing. var testEnvironment = map[string]string{ - "USAGE_REPORTS_AUTH_TYPE": "NOAuth", + "USAGE_REPORTS_AUTH_TYPE": "NOAuth", } SetTestEnvironment(testEnvironment) @@ -1162,14 +1159,14 @@ var _ = Describe(`UsageReportsV4`, func() { nextObject := new(usagereportsv4.InstancesUsageNext) nextObject.Href = core.StringPtr("ibm.com?_start=abc-123") responseObject.Next = nextObject - + value, err := responseObject.GetNextStart() Expect(err).To(BeNil()) Expect(value).To(Equal(core.StringPtr("abc-123"))) }) It(`Invoke GetNextStart without a "Next" property in the response`, func() { responseObject := new(usagereportsv4.InstancesUsage) - + value, err := responseObject.GetNextStart() Expect(err).To(BeNil()) Expect(value).To(BeNil()) @@ -1179,7 +1176,7 @@ var _ = Describe(`UsageReportsV4`, func() { nextObject := new(usagereportsv4.InstancesUsageNext) nextObject.Href = core.StringPtr("ibm.com") responseObject.Next = nextObject - + value, err := responseObject.GetNextStart() Expect(err).To(BeNil()) Expect(value).To(BeNil()) @@ -1217,17 +1214,17 @@ var _ = Describe(`UsageReportsV4`, func() { Expect(usageReportsService).ToNot(BeNil()) getResourceUsageAccountOptionsModel := &usagereportsv4.GetResourceUsageAccountOptions{ - AccountID: core.StringPtr("testString"), - Billingmonth: core.StringPtr("testString"), - Names: core.BoolPtr(true), - AcceptLanguage: core.StringPtr("testString"), - Limit: core.Int64Ptr(int64(1)), - ResourceGroupID: core.StringPtr("testString"), - OrganizationID: core.StringPtr("testString"), + AccountID: core.StringPtr("testString"), + Billingmonth: core.StringPtr("testString"), + Names: core.BoolPtr(true), + AcceptLanguage: core.StringPtr("testString"), + Limit: core.Int64Ptr(int64(1)), + ResourceGroupID: core.StringPtr("testString"), + OrganizationID: core.StringPtr("testString"), ResourceInstanceID: core.StringPtr("testString"), - ResourceID: core.StringPtr("testString"), - PlanID: core.StringPtr("testString"), - Region: core.StringPtr("testString"), + ResourceID: core.StringPtr("testString"), + PlanID: core.StringPtr("testString"), + Region: core.StringPtr("testString"), } pager, err := usageReportsService.NewGetResourceUsageAccountPager(getResourceUsageAccountOptionsModel) @@ -1252,17 +1249,17 @@ var _ = Describe(`UsageReportsV4`, func() { Expect(usageReportsService).ToNot(BeNil()) getResourceUsageAccountOptionsModel := &usagereportsv4.GetResourceUsageAccountOptions{ - AccountID: core.StringPtr("testString"), - Billingmonth: core.StringPtr("testString"), - Names: core.BoolPtr(true), - AcceptLanguage: core.StringPtr("testString"), - Limit: core.Int64Ptr(int64(1)), - ResourceGroupID: core.StringPtr("testString"), - OrganizationID: core.StringPtr("testString"), + AccountID: core.StringPtr("testString"), + Billingmonth: core.StringPtr("testString"), + Names: core.BoolPtr(true), + AcceptLanguage: core.StringPtr("testString"), + Limit: core.Int64Ptr(int64(1)), + ResourceGroupID: core.StringPtr("testString"), + OrganizationID: core.StringPtr("testString"), ResourceInstanceID: core.StringPtr("testString"), - ResourceID: core.StringPtr("testString"), - PlanID: core.StringPtr("testString"), - Region: core.StringPtr("testString"), + ResourceID: core.StringPtr("testString"), + PlanID: core.StringPtr("testString"), + Region: core.StringPtr("testString"), } pager, err := usageReportsService.NewGetResourceUsageAccountPager(getResourceUsageAccountOptionsModel) @@ -1570,14 +1567,14 @@ var _ = Describe(`UsageReportsV4`, func() { nextObject := new(usagereportsv4.InstancesUsageNext) nextObject.Href = core.StringPtr("ibm.com?_start=abc-123") responseObject.Next = nextObject - + value, err := responseObject.GetNextStart() Expect(err).To(BeNil()) Expect(value).To(Equal(core.StringPtr("abc-123"))) }) It(`Invoke GetNextStart without a "Next" property in the response`, func() { responseObject := new(usagereportsv4.InstancesUsage) - + value, err := responseObject.GetNextStart() Expect(err).To(BeNil()) Expect(value).To(BeNil()) @@ -1587,7 +1584,7 @@ var _ = Describe(`UsageReportsV4`, func() { nextObject := new(usagereportsv4.InstancesUsageNext) nextObject.Href = core.StringPtr("ibm.com") responseObject.Next = nextObject - + value, err := responseObject.GetNextStart() Expect(err).To(BeNil()) Expect(value).To(BeNil()) @@ -1625,16 +1622,16 @@ var _ = Describe(`UsageReportsV4`, func() { Expect(usageReportsService).ToNot(BeNil()) getResourceUsageResourceGroupOptionsModel := &usagereportsv4.GetResourceUsageResourceGroupOptions{ - AccountID: core.StringPtr("testString"), - ResourceGroupID: core.StringPtr("testString"), - Billingmonth: core.StringPtr("testString"), - Names: core.BoolPtr(true), - AcceptLanguage: core.StringPtr("testString"), - Limit: core.Int64Ptr(int64(1)), + AccountID: core.StringPtr("testString"), + ResourceGroupID: core.StringPtr("testString"), + Billingmonth: core.StringPtr("testString"), + Names: core.BoolPtr(true), + AcceptLanguage: core.StringPtr("testString"), + Limit: core.Int64Ptr(int64(1)), ResourceInstanceID: core.StringPtr("testString"), - ResourceID: core.StringPtr("testString"), - PlanID: core.StringPtr("testString"), - Region: core.StringPtr("testString"), + ResourceID: core.StringPtr("testString"), + PlanID: core.StringPtr("testString"), + Region: core.StringPtr("testString"), } pager, err := usageReportsService.NewGetResourceUsageResourceGroupPager(getResourceUsageResourceGroupOptionsModel) @@ -1659,16 +1656,16 @@ var _ = Describe(`UsageReportsV4`, func() { Expect(usageReportsService).ToNot(BeNil()) getResourceUsageResourceGroupOptionsModel := &usagereportsv4.GetResourceUsageResourceGroupOptions{ - AccountID: core.StringPtr("testString"), - ResourceGroupID: core.StringPtr("testString"), - Billingmonth: core.StringPtr("testString"), - Names: core.BoolPtr(true), - AcceptLanguage: core.StringPtr("testString"), - Limit: core.Int64Ptr(int64(1)), + AccountID: core.StringPtr("testString"), + ResourceGroupID: core.StringPtr("testString"), + Billingmonth: core.StringPtr("testString"), + Names: core.BoolPtr(true), + AcceptLanguage: core.StringPtr("testString"), + Limit: core.Int64Ptr(int64(1)), ResourceInstanceID: core.StringPtr("testString"), - ResourceID: core.StringPtr("testString"), - PlanID: core.StringPtr("testString"), - Region: core.StringPtr("testString"), + ResourceID: core.StringPtr("testString"), + PlanID: core.StringPtr("testString"), + Region: core.StringPtr("testString"), } pager, err := usageReportsService.NewGetResourceUsageResourceGroupPager(getResourceUsageResourceGroupOptionsModel) @@ -1976,14 +1973,14 @@ var _ = Describe(`UsageReportsV4`, func() { nextObject := new(usagereportsv4.InstancesUsageNext) nextObject.Href = core.StringPtr("ibm.com?_start=abc-123") responseObject.Next = nextObject - + value, err := responseObject.GetNextStart() Expect(err).To(BeNil()) Expect(value).To(Equal(core.StringPtr("abc-123"))) }) It(`Invoke GetNextStart without a "Next" property in the response`, func() { responseObject := new(usagereportsv4.InstancesUsage) - + value, err := responseObject.GetNextStart() Expect(err).To(BeNil()) Expect(value).To(BeNil()) @@ -1993,7 +1990,7 @@ var _ = Describe(`UsageReportsV4`, func() { nextObject := new(usagereportsv4.InstancesUsageNext) nextObject.Href = core.StringPtr("ibm.com") responseObject.Next = nextObject - + value, err := responseObject.GetNextStart() Expect(err).To(BeNil()) Expect(value).To(BeNil()) @@ -2031,16 +2028,16 @@ var _ = Describe(`UsageReportsV4`, func() { Expect(usageReportsService).ToNot(BeNil()) getResourceUsageOrgOptionsModel := &usagereportsv4.GetResourceUsageOrgOptions{ - AccountID: core.StringPtr("testString"), - OrganizationID: core.StringPtr("testString"), - Billingmonth: core.StringPtr("testString"), - Names: core.BoolPtr(true), - AcceptLanguage: core.StringPtr("testString"), - Limit: core.Int64Ptr(int64(1)), + AccountID: core.StringPtr("testString"), + OrganizationID: core.StringPtr("testString"), + Billingmonth: core.StringPtr("testString"), + Names: core.BoolPtr(true), + AcceptLanguage: core.StringPtr("testString"), + Limit: core.Int64Ptr(int64(1)), ResourceInstanceID: core.StringPtr("testString"), - ResourceID: core.StringPtr("testString"), - PlanID: core.StringPtr("testString"), - Region: core.StringPtr("testString"), + ResourceID: core.StringPtr("testString"), + PlanID: core.StringPtr("testString"), + Region: core.StringPtr("testString"), } pager, err := usageReportsService.NewGetResourceUsageOrgPager(getResourceUsageOrgOptionsModel) @@ -2065,16 +2062,16 @@ var _ = Describe(`UsageReportsV4`, func() { Expect(usageReportsService).ToNot(BeNil()) getResourceUsageOrgOptionsModel := &usagereportsv4.GetResourceUsageOrgOptions{ - AccountID: core.StringPtr("testString"), - OrganizationID: core.StringPtr("testString"), - Billingmonth: core.StringPtr("testString"), - Names: core.BoolPtr(true), - AcceptLanguage: core.StringPtr("testString"), - Limit: core.Int64Ptr(int64(1)), + AccountID: core.StringPtr("testString"), + OrganizationID: core.StringPtr("testString"), + Billingmonth: core.StringPtr("testString"), + Names: core.BoolPtr(true), + AcceptLanguage: core.StringPtr("testString"), + Limit: core.Int64Ptr(int64(1)), ResourceInstanceID: core.StringPtr("testString"), - ResourceID: core.StringPtr("testString"), - PlanID: core.StringPtr("testString"), - Region: core.StringPtr("testString"), + ResourceID: core.StringPtr("testString"), + PlanID: core.StringPtr("testString"), + Region: core.StringPtr("testString"), } pager, err := usageReportsService.NewGetResourceUsageOrgPager(getResourceUsageOrgOptionsModel) @@ -2329,6 +2326,1077 @@ 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"})) + Expect(req.URL.Query()["date_from"]).To(Equal([]string{fmt.Sprint(int64(1675209600000))})) + Expect(req.URL.Query()["date_to"]).To(Equal([]string{fmt.Sprint(int64(1675987200000))})) + 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.Int64Ptr(int64(1675209600000)) + getReportsSnapshotOptionsModel.DateTo = core.Int64Ptr(int64(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"})) + Expect(req.URL.Query()["date_from"]).To(Equal([]string{fmt.Sprint(int64(1675209600000))})) + Expect(req.URL.Query()["date_to"]).To(Equal([]string{fmt.Sprint(int64(1675987200000))})) + // 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.Int64Ptr(int64(1675209600000)) + getReportsSnapshotOptionsModel.DateTo = core.Int64Ptr(int64(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"})) + Expect(req.URL.Query()["date_from"]).To(Equal([]string{fmt.Sprint(int64(1675209600000))})) + Expect(req.URL.Query()["date_to"]).To(Equal([]string{fmt.Sprint(int64(1675987200000))})) + // 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.Int64Ptr(int64(1675209600000)) + getReportsSnapshotOptionsModel.DateTo = core.Int64Ptr(int64(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.Int64Ptr(int64(1675209600000)) + getReportsSnapshotOptionsModel.DateTo = core.Int64Ptr(int64(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.Int64Ptr(int64(1675209600000)) + getReportsSnapshotOptionsModel.DateTo = core.Int64Ptr(int64(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{