Skip to content

Commit

Permalink
feat(Usage Reports): re-gen service to pickup changes to Instance Rep…
Browse files Browse the repository at this point in the history
…orts (#331)

* add VolumeDiscount and VolumeCost

Signed-off-by: Jonathan Date-chong <jtdatechong@gmail.com>
  • Loading branch information
Jdatechong authored Jun 18, 2024
1 parent d03e330 commit 3d034e7
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 53 deletions.
16 changes: 16 additions & 0 deletions usagereportsv4/usage_reports_v4.go
Original file line number Diff line number Diff line change
Expand Up @@ -2698,6 +2698,12 @@ type Metric struct {

// All the discounts applicable to the metric.
Discounts []Discount `json:"discounts" validate:"required"`

// This percentage reflects the reduction to the original cost that you receive under a volume based pricing structure.
VolumeDiscount *float64 `json:"volume_discount,omitempty"`

// The original cost adjusted for volume based discounts that are applied at the account level.
VolumeCost *float64 `json:"volume_cost,omitempty"`
}

// UnmarshalMetric unmarshals an instance of Metric from the specified map of raw messages.
Expand Down Expand Up @@ -2758,6 +2764,16 @@ func UnmarshalMetric(m map[string]json.RawMessage, result interface{}) (err erro
err = core.SDKErrorf(err, "", "discounts-error", common.GetComponentInfo())
return
}
err = core.UnmarshalPrimitive(m, "volume_discount", &obj.VolumeDiscount)
if err != nil {
err = core.SDKErrorf(err, "", "volume_discount-error", common.GetComponentInfo())
return
}
err = core.UnmarshalPrimitive(m, "volume_cost", &obj.VolumeCost)
if err != nil {
err = core.SDKErrorf(err, "", "volume_cost-error", common.GetComponentInfo())
return
}
reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj))
return
}
Expand Down
1 change: 1 addition & 0 deletions usagereportsv4/usage_reports_v4_examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import (
// export IBM_CREDENTIALS_FILE=<name of configuration file>
//
var _ = Describe(`UsageReportsV4 Examples Tests`, func() {

const externalConfigFile = "../usage_reports.env"

var (
Expand Down
63 changes: 30 additions & 33 deletions usagereportsv4/usage_reports_v4_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ var _ = Describe(`UsageReportsV4 Integration Tests`, func() {
const externalConfigFile = "../usage_reports.env"

var (
err error
err error
usageReportsService *usagereportsv4.UsageReportsV4
serviceURL string
config map[string]string
serviceURL string
config map[string]string

accountID string
resourceGroupID string
Expand Down Expand Up @@ -81,7 +81,7 @@ var _ = Describe(`UsageReportsV4 Integration Tests`, func() {
Skip("Unable to load service URL configuration property, skipping tests")
}

fmt.Fprintf(GinkgoWriter, "Service URL: %s\n", serviceURL)
fmt.Fprintf(GinkgoWriter, "Service URL: %v\n", serviceURL)

accountID = config["ACCOUNT_ID"]
Expect(accountID).ToNot(BeEmpty())
Expand Down Expand Up @@ -139,7 +139,6 @@ var _ = Describe(`UsageReportsV4 Integration Tests`, func() {
}

accountSummary, response, err := usageReportsService.GetAccountSummary(getAccountSummaryOptions)

Expect(err).To(BeNil())
Expect(response.StatusCode).To(Equal(200))
Expect(accountSummary).ToNot(BeNil())
Expand Down Expand Up @@ -199,32 +198,6 @@ var _ = Describe(`UsageReportsV4 Integration Tests`, func() {
})
})

Describe(`GetOrgUsage - Get organization usage`, func() {
BeforeEach(func() {
shouldSkipTest()
})
It(`GetOrgUsage(getOrgUsageOptions *GetOrgUsageOptions)`, func() {

getOrgUsageOptions := &usagereportsv4.GetOrgUsageOptions{
AccountID: &accountID,
OrganizationID: &orgID,
Billingmonth: &billingMonth,
Names: core.BoolPtr(true),
}

orgUsage, response, err := usageReportsService.GetOrgUsage(getOrgUsageOptions)

Expect(err).To(BeNil())
Expect(response.StatusCode).To(Equal(200))
Expect(orgUsage).ToNot(BeNil())
fmt.Fprintf(GinkgoWriter, "\nGetOrgUsage response:\n%s", common.ToJSON(orgUsage))

Expect(*orgUsage.AccountID).To(Equal(accountID))
Expect(*orgUsage.Month).To(Equal(billingMonth))
Expect(orgUsage.Resources).ToNot(BeEmpty())
})
})

Describe(`GetResourceUsageAccount - Get resource instance usage in an account`, func() {
BeforeEach(func() {
shouldSkipTest()
Expand Down Expand Up @@ -553,6 +526,30 @@ var _ = Describe(`UsageReportsV4 Integration Tests`, func() {
})
})

Describe(`GetOrgUsage - Get organization usage`, func() {
BeforeEach(func() {
shouldSkipTest()
})
It(`GetOrgUsage(getOrgUsageOptions *GetOrgUsageOptions)`, func() {
getOrgUsageOptions := &usagereportsv4.GetOrgUsageOptions{
AccountID: &accountID,
OrganizationID: &orgID,
Billingmonth: &billingMonth,
Names: core.BoolPtr(true),
}

orgUsage, response, err := usageReportsService.GetOrgUsage(getOrgUsageOptions)
Expect(err).To(BeNil())
Expect(response.StatusCode).To(Equal(200))
Expect(orgUsage).ToNot(BeNil())
fmt.Fprintf(GinkgoWriter, "\nGetOrgUsage response:\n%s", common.ToJSON(orgUsage))

Expect(*orgUsage.AccountID).To(Equal(accountID))
Expect(*orgUsage.Month).To(Equal(billingMonth))
// Expect(orgUsage.Resources).ToNot(BeEmpty())
})
})

Describe(`CreateReportsSnapshotConfig - Setup the snapshot configuration`, func() {
BeforeEach(func() {
shouldSkipTest()
Expand Down Expand Up @@ -602,7 +599,7 @@ var _ = Describe(`UsageReportsV4 Integration Tests`, func() {
CosBucket: core.StringPtr(cosBucket),
CosLocation: core.StringPtr(cosLocation),
CosReportsFolder: core.StringPtr("IBMCloud-Billing-Reports"),
ReportTypes: []string{"account_summary"},
ReportTypes: []string{"account_summary", "enterprise_summary", "account_resource_instance_usage"},
Versioning: core.StringPtr("new"),
}

Expand All @@ -624,7 +621,7 @@ var _ = Describe(`UsageReportsV4 Integration Tests`, func() {
CosBucket: core.StringPtr(cosBucket),
CosLocation: core.StringPtr(cosLocation),
CosReportsFolder: core.StringPtr("IBMCloud-Billing-Reports"),
ReportTypes: []string{"account_summary"},
ReportTypes: []string{"account_summary", "enterprise_summary", "account_resource_instance_usage"},
Versioning: core.StringPtr("new"),
}

Expand Down
Loading

0 comments on commit 3d034e7

Please sign in to comment.