Skip to content

Commit a6f05d6

Browse files
allmightyspiffGitHub Enterprise
authored andcommitted
Merge pull request #858 from SoftLayer/isssues856
Fixed a data parsing issue with invoice detail.
2 parents b54f7d0 + 35cc965 commit a6f05d6

File tree

4 files changed

+280
-10
lines changed

4 files changed

+280
-10
lines changed

plugin/commands/account/invoice-detail.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,18 @@ func PrintInvoiceDetail(invoiceID int, invoice []datatypes.Billing_Invoice_Item,
8282
if fqdn != "." {
8383
Description = fmt.Sprintf("%s (%s)", Description, fqdn)
8484
}
85+
location := "None"
86+
if invoiceDetail.Location != nil {
87+
location = utils.FormatStringPointer(invoiceDetail.Location.Name)
88+
}
8589
table.Add(
8690
utils.FormatIntPointer(invoiceDetail.Id),
8791
Category,
8892
utils.ShortenString(Description),
8993
fmt.Sprintf("%.2f", *invoiceDetail.OneTimeAfterTaxAmount),
9094
fmt.Sprintf("%.2f", *invoiceDetail.RecurringAfterTaxAmount),
9195
utils.FormatSLTimePointer(invoiceDetail.CreateDate),
92-
utils.FormatStringPointer(invoiceDetail.Location.Name),
96+
location,
9397
)
9498
if details {
9599
for _, child := range invoiceDetail.Children {

plugin/commands/account/invoice-detail_test.go

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,24 @@ import (
1313

1414
var _ = Describe("Account list InvoiceDetail", func() {
1515
var (
16-
fakeUI *terminal.FakeUI
17-
cliCommand *account.InvoiceDetailCommand
18-
fakeSession *session.Session
19-
slCommand *metadata.SoftlayerCommand
16+
fakeUI *terminal.FakeUI
17+
cliCommand *account.InvoiceDetailCommand
18+
fakeSession *session.Session
19+
slCommand *metadata.SoftlayerCommand
20+
fakeHandler *testhelpers.FakeTransportHandler
2021
)
2122
BeforeEach(func() {
2223
fakeUI = terminal.NewFakeUI()
23-
fakeSession = testhelpers.NewFakeSoftlayerSession([]string{})
24+
fakeSession = testhelpers.NewFakeSoftlayerSession(nil)
25+
fakeHandler = testhelpers.GetSessionHandler(fakeSession)
2426
slCommand = metadata.NewSoftlayerCommand(fakeUI, fakeSession)
2527
cliCommand = account.NewInvoiceDetailCommand(slCommand)
2628
cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.")
2729
})
30+
AfterEach(func() {
31+
fakeHandler.ClearApiCallLogs()
32+
fakeHandler.ClearErrors()
33+
})
2834

2935
Describe("Account invoice detail", func() {
3036
Context("Account invoice detail, Invalid Usage", func() {
@@ -73,10 +79,21 @@ var _ = Describe("Account list InvoiceDetail", func() {
7379
Expect(fakeUI.Outputs()).To(ContainSubstring(`"Single": "10.23",`))
7480
Expect(fakeUI.Outputs()).To(ContainSubstring(`"Monthly": "20.34",`))
7581
Expect(fakeUI.Outputs()).To(ContainSubstring(`"Location": "mex01"`))
76-
Expect(fakeUI.Outputs()).To(ContainSubstring(`[`))
77-
Expect(fakeUI.Outputs()).To(ContainSubstring(`{`))
78-
Expect(fakeUI.Outputs()).To(ContainSubstring(`}`))
79-
Expect(fakeUI.Outputs()).To(ContainSubstring(`]`))
82+
})
83+
})
84+
Context("issues856", func() {
85+
It("Handle large int invoices", func() {
86+
err := testhelpers.RunCobraCommand(cliCommand.Command, "999")
87+
Expect(err).NotTo(HaveOccurred())
88+
output := fakeUI.Outputs()
89+
Expect(output).To(ContainSubstring("testlb-307608-dal13.lb.bluemix.net"))
90+
})
91+
It("Missing properties dont break", func() {
92+
err := testhelpers.RunCobraCommand(cliCommand.Command, "888")
93+
Expect(err).NotTo(HaveOccurred())
94+
output := fakeUI.Outputs()
95+
Expect(output).To(ContainSubstring("2020-05-04T05:11:25Z None"))
96+
Expect(output).To(ContainSubstring("2020-05-04T05:11:25Z tok02"))
8097
})
8198
})
8299
})
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
[
2+
{
3+
"category": {
4+
"name": "Network Vlan"
5+
},
6+
"categoryCode": "network_vlan",
7+
"children": [],
8+
"createDate": "2020-05-03T23:11:25-06:00",
9+
"description": "Private Network Vlan",
10+
"id": 1531470222,
11+
"location": {
12+
"name": "tok02"
13+
},
14+
"oneTimeAfterTaxAmount": "0",
15+
"recurringAfterTaxAmount": "0"
16+
},
17+
{
18+
"category": {
19+
"name": "Network Vlan"
20+
},
21+
"categoryCode": "network_vlan",
22+
"children": [],
23+
"createDate": "2020-05-03T23:11:25-06:00",
24+
"description": "Public Network Vlan",
25+
"id": 1531470240,
26+
"oneTimeAfterTaxAmount": "0",
27+
"recurringAfterTaxAmount": "0"
28+
},
29+
{
30+
"category": {
31+
"name": "Endurance"
32+
},
33+
"categoryCode": "storage_service_enterprise",
34+
"children": [
35+
{
36+
"category": {
37+
"name": "Block Storage"
38+
},
39+
"description": "Block Storage",
40+
"id": 1531470258,
41+
"oneTimeAfterTaxAmount": "0",
42+
"recurringAfterTaxAmount": "0"
43+
},
44+
{
45+
"category": {
46+
"name": "Storage Tier Level"
47+
},
48+
"description": "0.25 IOPS per GB",
49+
"id": 1531470268,
50+
"oneTimeAfterTaxAmount": "0",
51+
"recurringAfterTaxAmount": "0"
52+
},
53+
{
54+
"category": {
55+
"name": "Storage Space"
56+
},
57+
"description": "20 GB Storage Space",
58+
"id": 1531470274,
59+
"oneTimeAfterTaxAmount": "0",
60+
"recurringAfterTaxAmount": "0"
61+
},
62+
{
63+
"category": {
64+
"name": "Storage Snapshot Space"
65+
},
66+
"description": "10 GB Storage Space (Snapshot Space)",
67+
"id": 1531470282,
68+
"oneTimeAfterTaxAmount": "0",
69+
"recurringAfterTaxAmount": "0"
70+
}
71+
],
72+
"createDate": "2020-05-03T23:11:25-06:00",
73+
"description": "Endurance Storage",
74+
"id": 1531470246,
75+
"location": {
76+
"name": "ams01"
77+
},
78+
"oneTimeAfterTaxAmount": "0",
79+
"recurringAfterTaxAmount": "0"
80+
}
81+
]
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
[
2+
{
3+
"category": {
4+
"name": "Server"
5+
},
6+
"categoryCode": "server",
7+
"children": [
8+
{
9+
"category": {
10+
"name": "Public Network Port"
11+
},
12+
"description": "10 Gbps Dual Public Uplinks (Unbonded)",
13+
"id": 21957603637,
14+
"oneTimeAfterTaxAmount": "0",
15+
"recurringAfterTaxAmount": "0"
16+
},
17+
{
18+
"category": {
19+
"name": "Operating System"
20+
},
21+
"description": "Ubuntu Linux 16.04 LTS Xenial Xerus (64 bit)",
22+
"id": 29157601113641,
23+
"oneTimeAfterTaxAmount": "0",
24+
"recurringAfterTaxAmount": "0"
25+
},
26+
{
27+
"category": {
28+
"name": "RAM"
29+
},
30+
"description": "32 GB RAM",
31+
"id": 29576013645,
32+
"oneTimeAfterTaxAmount": "0",
33+
"recurringAfterTaxAmount": "0"
34+
},
35+
{
36+
"category": {
37+
"name": "Disk Controller"
38+
},
39+
"description": "Non-RAID",
40+
"id": 2957603647,
41+
"oneTimeAfterTaxAmount": "0",
42+
"recurringAfterTaxAmount": "0"
43+
},
44+
{
45+
"category": {
46+
"name": "First Hard Drive"
47+
},
48+
"description": "960 GB SSD (3 DWPD)",
49+
"id": 2957603651,
50+
"oneTimeAfterTaxAmount": "0",
51+
"recurringAfterTaxAmount": "0"
52+
},
53+
{
54+
"category": {
55+
"name": "Second Hard Drive"
56+
},
57+
"description": "960 GB SSD (3 DWPD)",
58+
"id": 2957603655,
59+
"oneTimeAfterTaxAmount": "0",
60+
"recurringAfterTaxAmount": "0"
61+
},
62+
{
63+
"category": {
64+
"name": "Public Bandwidth"
65+
},
66+
"description": "0 GB Bandwidth",
67+
"id": 2957603657,
68+
"oneTimeAfterTaxAmount": "0",
69+
"recurringAfterTaxAmount": "0"
70+
},
71+
{
72+
"category": {
73+
"name": "Uplink Port Speeds"
74+
},
75+
"description": "10 Gbps Dual Public & Private Network Uplinks (Unbonded)",
76+
"id": 2957603661,
77+
"oneTimeAfterTaxAmount": "0",
78+
"recurringAfterTaxAmount": "0"
79+
},
80+
{
81+
"category": {
82+
"name": "Primary IP Addresses"
83+
},
84+
"description": "1 IP Address",
85+
"id": 2957603665,
86+
"oneTimeAfterTaxAmount": "0",
87+
"recurringAfterTaxAmount": "0"
88+
}
89+
],
90+
"createDate": "2024-06-03T23:08:08-06:00",
91+
"description": "Single Intel Xeon E3-1270 v3 (4 Cores, 3.50 GHz)",
92+
"domainName": "hans.chechu.com",
93+
"hostName": "ceph1",
94+
"id": 2957601113633,
95+
"location": {
96+
"name": "par01"
97+
},
98+
"oneTimeAfterTaxAmount": "0",
99+
"recurringAfterTaxAmount": "0"
100+
},
101+
{
102+
"category": {
103+
"name": "Network Vlan"
104+
},
105+
"categoryCode": "network_vlan",
106+
"children": [],
107+
"createDate": "2024-06-03T23:08:19-06:00",
108+
"description": "Public Network Vlan",
109+
"id": 2957614027,
110+
"location": {
111+
"name": "dal10"
112+
},
113+
"oneTimeAfterTaxAmount": "0",
114+
"recurringAfterTaxAmount": "0"
115+
},
116+
{
117+
"category": {
118+
"name": "Load Balancer As A Service"
119+
},
120+
"categoryCode": "load_balancer_as_a_service",
121+
"children": [
122+
{
123+
"category": {
124+
"name": "Load Balancer Data Processed Usage"
125+
},
126+
"description": " ($0.008/ GIGABYTE ) - Total 0.00000 GIGABYTE used",
127+
"id": 2957614035,
128+
"oneTimeAfterTaxAmount": "0",
129+
"recurringAfterTaxAmount": "0"
130+
},
131+
{
132+
"category": {
133+
"name": "Load Balancer Bandwidth"
134+
},
135+
"description": "Load Balancer Bandwidth",
136+
"id": 2957614039,
137+
"oneTimeAfterTaxAmount": "0",
138+
"recurringAfterTaxAmount": "0"
139+
},
140+
{
141+
"category": {
142+
"name": "Load Balancer Uptime"
143+
},
144+
"description": "Load Balancer Uptime",
145+
"id": 2957614043,
146+
"oneTimeAfterTaxAmount": "0",
147+
"recurringAfterTaxAmount": "0"
148+
},
149+
{
150+
"category": {
151+
"name": "Load Balancer Data Processed"
152+
},
153+
"description": "Load Balancer Data Processed ",
154+
"id": 2957614047,
155+
"oneTimeAfterTaxAmount": "0",
156+
"recurringAfterTaxAmount": "0"
157+
}
158+
],
159+
"createDate": "2024-06-03T23:08:19-06:00",
160+
"description": "testlb-307608-dal13.lb.bluemix.net",
161+
"id": 2957614031,
162+
"location": {
163+
"name": "dal13"
164+
},
165+
"oneTimeAfterTaxAmount": "0",
166+
"recurringAfterTaxAmount": "0"
167+
}
168+
]

0 commit comments

Comments
 (0)