Skip to content

Commit

Permalink
Merge pull request #858 from SoftLayer/isssues856
Browse files Browse the repository at this point in the history
Fixed a data parsing issue with invoice detail.
  • Loading branch information
CHRISTOPHER GALLO authored and GitHub Enterprise committed Jul 3, 2024
2 parents b54f7d0 + 35cc965 commit a6f05d6
Show file tree
Hide file tree
Showing 4 changed files with 280 additions and 10 deletions.
6 changes: 5 additions & 1 deletion plugin/commands/account/invoice-detail.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,18 @@ func PrintInvoiceDetail(invoiceID int, invoice []datatypes.Billing_Invoice_Item,
if fqdn != "." {
Description = fmt.Sprintf("%s (%s)", Description, fqdn)
}
location := "None"
if invoiceDetail.Location != nil {
location = utils.FormatStringPointer(invoiceDetail.Location.Name)
}
table.Add(
utils.FormatIntPointer(invoiceDetail.Id),
Category,
utils.ShortenString(Description),
fmt.Sprintf("%.2f", *invoiceDetail.OneTimeAfterTaxAmount),
fmt.Sprintf("%.2f", *invoiceDetail.RecurringAfterTaxAmount),
utils.FormatSLTimePointer(invoiceDetail.CreateDate),
utils.FormatStringPointer(invoiceDetail.Location.Name),
location,
)
if details {
for _, child := range invoiceDetail.Children {
Expand Down
35 changes: 26 additions & 9 deletions plugin/commands/account/invoice-detail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,24 @@ import (

var _ = Describe("Account list InvoiceDetail", func() {
var (
fakeUI *terminal.FakeUI
cliCommand *account.InvoiceDetailCommand
fakeSession *session.Session
slCommand *metadata.SoftlayerCommand
fakeUI *terminal.FakeUI
cliCommand *account.InvoiceDetailCommand
fakeSession *session.Session
slCommand *metadata.SoftlayerCommand
fakeHandler *testhelpers.FakeTransportHandler
)
BeforeEach(func() {
fakeUI = terminal.NewFakeUI()
fakeSession = testhelpers.NewFakeSoftlayerSession([]string{})
fakeSession = testhelpers.NewFakeSoftlayerSession(nil)
fakeHandler = testhelpers.GetSessionHandler(fakeSession)
slCommand = metadata.NewSoftlayerCommand(fakeUI, fakeSession)
cliCommand = account.NewInvoiceDetailCommand(slCommand)
cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.")
})
AfterEach(func() {
fakeHandler.ClearApiCallLogs()
fakeHandler.ClearErrors()
})

Describe("Account invoice detail", func() {
Context("Account invoice detail, Invalid Usage", func() {
Expand Down Expand Up @@ -73,10 +79,21 @@ var _ = Describe("Account list InvoiceDetail", func() {
Expect(fakeUI.Outputs()).To(ContainSubstring(`"Single": "10.23",`))
Expect(fakeUI.Outputs()).To(ContainSubstring(`"Monthly": "20.34",`))
Expect(fakeUI.Outputs()).To(ContainSubstring(`"Location": "mex01"`))
Expect(fakeUI.Outputs()).To(ContainSubstring(`[`))
Expect(fakeUI.Outputs()).To(ContainSubstring(`{`))
Expect(fakeUI.Outputs()).To(ContainSubstring(`}`))
Expect(fakeUI.Outputs()).To(ContainSubstring(`]`))
})
})
Context("issues856", func() {
It("Handle large int invoices", func() {
err := testhelpers.RunCobraCommand(cliCommand.Command, "999")
Expect(err).NotTo(HaveOccurred())
output := fakeUI.Outputs()
Expect(output).To(ContainSubstring("testlb-307608-dal13.lb.bluemix.net"))
})
It("Missing properties dont break", func() {
err := testhelpers.RunCobraCommand(cliCommand.Command, "888")
Expect(err).NotTo(HaveOccurred())
output := fakeUI.Outputs()
Expect(output).To(ContainSubstring("2020-05-04T05:11:25Z None"))
Expect(output).To(ContainSubstring("2020-05-04T05:11:25Z tok02"))
})
})
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
[
{
"category": {
"name": "Network Vlan"
},
"categoryCode": "network_vlan",
"children": [],
"createDate": "2020-05-03T23:11:25-06:00",
"description": "Private Network Vlan",
"id": 1531470222,
"location": {
"name": "tok02"
},
"oneTimeAfterTaxAmount": "0",
"recurringAfterTaxAmount": "0"
},
{
"category": {
"name": "Network Vlan"
},
"categoryCode": "network_vlan",
"children": [],
"createDate": "2020-05-03T23:11:25-06:00",
"description": "Public Network Vlan",
"id": 1531470240,
"oneTimeAfterTaxAmount": "0",
"recurringAfterTaxAmount": "0"
},
{
"category": {
"name": "Endurance"
},
"categoryCode": "storage_service_enterprise",
"children": [
{
"category": {
"name": "Block Storage"
},
"description": "Block Storage",
"id": 1531470258,
"oneTimeAfterTaxAmount": "0",
"recurringAfterTaxAmount": "0"
},
{
"category": {
"name": "Storage Tier Level"
},
"description": "0.25 IOPS per GB",
"id": 1531470268,
"oneTimeAfterTaxAmount": "0",
"recurringAfterTaxAmount": "0"
},
{
"category": {
"name": "Storage Space"
},
"description": "20 GB Storage Space",
"id": 1531470274,
"oneTimeAfterTaxAmount": "0",
"recurringAfterTaxAmount": "0"
},
{
"category": {
"name": "Storage Snapshot Space"
},
"description": "10 GB Storage Space (Snapshot Space)",
"id": 1531470282,
"oneTimeAfterTaxAmount": "0",
"recurringAfterTaxAmount": "0"
}
],
"createDate": "2020-05-03T23:11:25-06:00",
"description": "Endurance Storage",
"id": 1531470246,
"location": {
"name": "ams01"
},
"oneTimeAfterTaxAmount": "0",
"recurringAfterTaxAmount": "0"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
[
{
"category": {
"name": "Server"
},
"categoryCode": "server",
"children": [
{
"category": {
"name": "Public Network Port"
},
"description": "10 Gbps Dual Public Uplinks (Unbonded)",
"id": 21957603637,
"oneTimeAfterTaxAmount": "0",
"recurringAfterTaxAmount": "0"
},
{
"category": {
"name": "Operating System"
},
"description": "Ubuntu Linux 16.04 LTS Xenial Xerus (64 bit)",
"id": 29157601113641,
"oneTimeAfterTaxAmount": "0",
"recurringAfterTaxAmount": "0"
},
{
"category": {
"name": "RAM"
},
"description": "32 GB RAM",
"id": 29576013645,
"oneTimeAfterTaxAmount": "0",
"recurringAfterTaxAmount": "0"
},
{
"category": {
"name": "Disk Controller"
},
"description": "Non-RAID",
"id": 2957603647,
"oneTimeAfterTaxAmount": "0",
"recurringAfterTaxAmount": "0"
},
{
"category": {
"name": "First Hard Drive"
},
"description": "960 GB SSD (3 DWPD)",
"id": 2957603651,
"oneTimeAfterTaxAmount": "0",
"recurringAfterTaxAmount": "0"
},
{
"category": {
"name": "Second Hard Drive"
},
"description": "960 GB SSD (3 DWPD)",
"id": 2957603655,
"oneTimeAfterTaxAmount": "0",
"recurringAfterTaxAmount": "0"
},
{
"category": {
"name": "Public Bandwidth"
},
"description": "0 GB Bandwidth",
"id": 2957603657,
"oneTimeAfterTaxAmount": "0",
"recurringAfterTaxAmount": "0"
},
{
"category": {
"name": "Uplink Port Speeds"
},
"description": "10 Gbps Dual Public & Private Network Uplinks (Unbonded)",
"id": 2957603661,
"oneTimeAfterTaxAmount": "0",
"recurringAfterTaxAmount": "0"
},
{
"category": {
"name": "Primary IP Addresses"
},
"description": "1 IP Address",
"id": 2957603665,
"oneTimeAfterTaxAmount": "0",
"recurringAfterTaxAmount": "0"
}
],
"createDate": "2024-06-03T23:08:08-06:00",
"description": "Single Intel Xeon E3-1270 v3 (4 Cores, 3.50 GHz)",
"domainName": "hans.chechu.com",
"hostName": "ceph1",
"id": 2957601113633,
"location": {
"name": "par01"
},
"oneTimeAfterTaxAmount": "0",
"recurringAfterTaxAmount": "0"
},
{
"category": {
"name": "Network Vlan"
},
"categoryCode": "network_vlan",
"children": [],
"createDate": "2024-06-03T23:08:19-06:00",
"description": "Public Network Vlan",
"id": 2957614027,
"location": {
"name": "dal10"
},
"oneTimeAfterTaxAmount": "0",
"recurringAfterTaxAmount": "0"
},
{
"category": {
"name": "Load Balancer As A Service"
},
"categoryCode": "load_balancer_as_a_service",
"children": [
{
"category": {
"name": "Load Balancer Data Processed Usage"
},
"description": " ($0.008/ GIGABYTE ) - Total 0.00000 GIGABYTE used",
"id": 2957614035,
"oneTimeAfterTaxAmount": "0",
"recurringAfterTaxAmount": "0"
},
{
"category": {
"name": "Load Balancer Bandwidth"
},
"description": "Load Balancer Bandwidth",
"id": 2957614039,
"oneTimeAfterTaxAmount": "0",
"recurringAfterTaxAmount": "0"
},
{
"category": {
"name": "Load Balancer Uptime"
},
"description": "Load Balancer Uptime",
"id": 2957614043,
"oneTimeAfterTaxAmount": "0",
"recurringAfterTaxAmount": "0"
},
{
"category": {
"name": "Load Balancer Data Processed"
},
"description": "Load Balancer Data Processed ",
"id": 2957614047,
"oneTimeAfterTaxAmount": "0",
"recurringAfterTaxAmount": "0"
}
],
"createDate": "2024-06-03T23:08:19-06:00",
"description": "testlb-307608-dal13.lb.bluemix.net",
"id": 2957614031,
"location": {
"name": "dal13"
},
"oneTimeAfterTaxAmount": "0",
"recurringAfterTaxAmount": "0"
}
]

0 comments on commit a6f05d6

Please sign in to comment.