Skip to content

Commit df9b766

Browse files
allmightyspiffGitHub Enterprise
authored andcommitted
Merge pull request #704 from Edson-Rios/issue702
Group bandwidth commands
2 parents 37b6c2b + 64678b6 commit df9b766

15 files changed

Lines changed: 391 additions & 43 deletions

File tree

plugin/commands/account/account.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ func SetupCobraCommands(sl *metadata.SoftlayerCommand) *cobra.Command {
1515
Short: T("Classic infrastructure Account commands"),
1616
RunE: nil,
1717
}
18-
cobraCmd.AddCommand(NewBandwidthPoolsCommand(sl).Command)
19-
cobraCmd.AddCommand(NewBandwidthPoolsDetailCommand(sl).Command)
2018
cobraCmd.AddCommand(NewBillingItemsCommand(sl).Command)
2119
cobraCmd.AddCommand(NewCancelItemCommand(sl).Command)
2220
cobraCmd.AddCommand(NewInvoiceDetailCommand(sl).Command)

plugin/commands/account/account_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ func TestManagers(t *testing.T) {
1818
}
1919

2020
var availableCommands = []string{
21-
"bandwidth-pools",
22-
"bandwidth-pools-detail",
2321
"billing-items",
2422
"cancel-item",
2523
"event-detail",
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package bandwidth
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
6+
"github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin"
7+
8+
. "github.ibm.com/SoftLayer/softlayer-cli/plugin/i18n"
9+
"github.ibm.com/SoftLayer/softlayer-cli/plugin/metadata"
10+
)
11+
12+
func SetupCobraCommands(sl *metadata.SoftlayerCommand) *cobra.Command {
13+
cobraCmd := &cobra.Command{
14+
Use: "bandwidth",
15+
Short: T("Classic infrastructure Bandwidth commands"),
16+
RunE: nil,
17+
}
18+
cobraCmd.AddCommand(NewPoolsCommand(sl).Command)
19+
cobraCmd.AddCommand(NewPoolsDetailCommand(sl).Command)
20+
cobraCmd.AddCommand(NewSummaryCommand(sl).Command)
21+
return cobraCmd
22+
}
23+
24+
func BandwidthNamespace() plugin.Namespace {
25+
return plugin.Namespace{
26+
ParentName: "sl",
27+
Name: "bandwidth",
28+
Description: T("Classic Infrastructure Bandwidth commands"),
29+
}
30+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package bandwidth_test
2+
3+
import (
4+
"testing"
5+
6+
. "github.com/onsi/ginkgo"
7+
. "github.com/onsi/gomega"
8+
9+
"github.com/IBM-Cloud/ibm-cloud-cli-sdk/testhelpers/terminal"
10+
"github.ibm.com/SoftLayer/softlayer-cli/plugin/commands/bandwidth"
11+
"github.ibm.com/SoftLayer/softlayer-cli/plugin/metadata"
12+
"github.ibm.com/SoftLayer/softlayer-cli/plugin/testhelpers"
13+
"github.ibm.com/SoftLayer/softlayer-cli/plugin/utils"
14+
)
15+
16+
func TestManagers(t *testing.T) {
17+
RegisterFailHandler(Fail)
18+
RunSpecs(t, "Report Suite")
19+
}
20+
21+
var availableCommands = []string{
22+
"pools",
23+
"pools-detail",
24+
"summary",
25+
}
26+
27+
// This test suite exists to make sure commands don't get accidently removed from the actionBindings
28+
var _ = Describe("Test bandwidth commands", func() {
29+
fakeUI := terminal.NewFakeUI()
30+
fakeSession := testhelpers.NewFakeSoftlayerSession(nil)
31+
slMeta := metadata.NewSoftlayerCommand(fakeUI, fakeSession)
32+
33+
Context("New commands testable", func() {
34+
commands := bandwidth.SetupCobraCommands(slMeta)
35+
36+
var arrayCommands = []string{}
37+
for _, command := range commands.Commands() {
38+
commandName := command.Name()
39+
arrayCommands = append(arrayCommands, commandName)
40+
It("available commands "+commands.Name(), func() {
41+
available := false
42+
if utils.StringInSlice(commandName, availableCommands) != -1 {
43+
available = true
44+
}
45+
Expect(available).To(BeTrue(), commandName+" not found in array available Commands")
46+
})
47+
}
48+
for _, command := range availableCommands {
49+
commandName := command
50+
It("ibmcloud sl "+commands.Name(), func() {
51+
available := false
52+
if utils.StringInSlice(commandName, arrayCommands) != -1 {
53+
available = true
54+
}
55+
Expect(available).To(BeTrue(), commandName+" not found in ibmcloud sl "+commands.Name())
56+
})
57+
}
58+
})
59+
60+
Context("Report Namespace", func() {
61+
It("Report Name Space", func() {
62+
Expect(bandwidth.BandwidthNamespace().ParentName).To(ContainSubstring("sl"))
63+
Expect(bandwidth.BandwidthNamespace().Name).To(ContainSubstring("bandwidth"))
64+
Expect(bandwidth.BandwidthNamespace().Description).To(ContainSubstring("Classic Infrastructure Bandwidth commands"))
65+
})
66+
})
67+
})

plugin/commands/account/bandwidth_pools.go renamed to plugin/commands/bandwidth/pools.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package account
1+
package bandwidth
22

33
import (
44
"fmt"
@@ -11,19 +11,19 @@ import (
1111
"github.ibm.com/SoftLayer/softlayer-cli/plugin/utils"
1212
)
1313

14-
type BandwidthPoolsCommand struct {
14+
type PoolsCommand struct {
1515
*metadata.SoftlayerCommand
1616
AccountManager managers.AccountManager
1717
Command *cobra.Command
1818
}
1919

20-
func NewBandwidthPoolsCommand(sl *metadata.SoftlayerCommand) *BandwidthPoolsCommand {
21-
thisCmd := &BandwidthPoolsCommand{
20+
func NewPoolsCommand(sl *metadata.SoftlayerCommand) *PoolsCommand {
21+
thisCmd := &PoolsCommand{
2222
SoftlayerCommand: sl,
2323
AccountManager: managers.NewAccountManager(sl.Session),
2424
}
2525
cobraCmd := &cobra.Command{
26-
Use: "bandwidth-pools",
26+
Use: "pools",
2727
Short: T("Displays bandwidth pool information."),
2828
Args: metadata.NoArgs,
2929
RunE: func(cmd *cobra.Command, args []string) error {
@@ -34,7 +34,7 @@ func NewBandwidthPoolsCommand(sl *metadata.SoftlayerCommand) *BandwidthPoolsComm
3434
return thisCmd
3535
}
3636

37-
func (cmd *BandwidthPoolsCommand) Run(args []string) error {
37+
func (cmd *PoolsCommand) Run(args []string) error {
3838
pools, err := cmd.AccountManager.GetBandwidthPools()
3939
if err != nil {
4040
return err

plugin/commands/account/bandwidth_pools_details.go renamed to plugin/commands/bandwidth/pools_details.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package account
1+
package bandwidth
22

33
import (
44
"bytes"
@@ -17,20 +17,20 @@ import (
1717
"github.ibm.com/SoftLayer/softlayer-cli/plugin/utils"
1818
)
1919

20-
type BandwidthPoolsDetailCommand struct {
20+
type PoolsDetailCommand struct {
2121
*metadata.SoftlayerCommand
2222
AccountManager managers.AccountManager
2323
Command *cobra.Command
2424
}
2525

26-
func NewBandwidthPoolsDetailCommand(sl *metadata.SoftlayerCommand) *BandwidthPoolsDetailCommand {
26+
func NewPoolsDetailCommand(sl *metadata.SoftlayerCommand) *PoolsDetailCommand {
2727

28-
thisCmd := &BandwidthPoolsDetailCommand{
28+
thisCmd := &PoolsDetailCommand{
2929
SoftlayerCommand: sl,
3030
AccountManager: managers.NewAccountManager(sl.Session),
3131
}
3232
cobraCmd := &cobra.Command{
33-
Use: "bandwidth-pools-detail " + T("IDENTIFIER"),
33+
Use: "pools-detail " + T("IDENTIFIER"),
3434
Short: T("Get bandwidth pool details."),
3535
Args: metadata.OneArgs,
3636
RunE: func(cmd *cobra.Command, args []string) error {
@@ -41,7 +41,7 @@ func NewBandwidthPoolsDetailCommand(sl *metadata.SoftlayerCommand) *BandwidthPoo
4141
return thisCmd
4242
}
4343

44-
func (cmd *BandwidthPoolsDetailCommand) Run(args []string) error {
44+
func (cmd *PoolsDetailCommand) Run(args []string) error {
4545

4646
outputFormat := cmd.GetOutputFlag()
4747

plugin/commands/account/bandwidth_pools_details_test.go renamed to plugin/commands/bandwidth/pools_details_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package account_test
1+
package bandwidth_test
22

33
import (
44
"errors"
@@ -12,15 +12,15 @@ import (
1212
"github.com/softlayer/softlayer-go/session"
1313
"github.com/softlayer/softlayer-go/sl"
1414

15-
"github.ibm.com/SoftLayer/softlayer-cli/plugin/commands/account"
15+
"github.ibm.com/SoftLayer/softlayer-cli/plugin/commands/bandwidth"
1616
"github.ibm.com/SoftLayer/softlayer-cli/plugin/metadata"
1717
"github.ibm.com/SoftLayer/softlayer-cli/plugin/testhelpers"
1818
)
1919

20-
var _ = Describe("account bandwidth_pools_details", func() {
20+
var _ = Describe("bandwidth pools-details", func() {
2121
var (
2222
fakeUI *terminal.FakeUI
23-
cliCommand *account.BandwidthPoolsDetailCommand
23+
cliCommand *bandwidth.PoolsDetailCommand
2424
fakeSession *session.Session
2525
slCommand *metadata.SoftlayerCommand
2626
fakeAccountManager *testhelpers.FakeAccountManager
@@ -30,12 +30,12 @@ var _ = Describe("account bandwidth_pools_details", func() {
3030
fakeSession = testhelpers.NewFakeSoftlayerSession([]string{})
3131
fakeAccountManager = new(testhelpers.FakeAccountManager)
3232
slCommand = metadata.NewSoftlayerCommand(fakeUI, fakeSession)
33-
cliCommand = account.NewBandwidthPoolsDetailCommand(slCommand)
33+
cliCommand = bandwidth.NewPoolsDetailCommand(slCommand)
3434
cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.")
3535
cliCommand.AccountManager = fakeAccountManager
3636
})
3737

38-
Describe("account bandwidth_pools_details", func() {
38+
Describe("bandwidth pools-details", func() {
3939
Context("Return error", func() {
4040
It("Set command without Id", func() {
4141
err := testhelpers.RunCobraCommand(cliCommand.Command)

plugin/commands/account/bandwidth_pools_test.go renamed to plugin/commands/bandwidth/pools_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package account_test
1+
package bandwidth_test
22

33
import (
44
"github.com/IBM-Cloud/ibm-cloud-cli-sdk/testhelpers/terminal"
@@ -7,27 +7,27 @@ import (
77

88
"github.com/softlayer/softlayer-go/session"
99

10-
"github.ibm.com/SoftLayer/softlayer-cli/plugin/commands/account"
10+
"github.ibm.com/SoftLayer/softlayer-cli/plugin/commands/bandwidth"
1111
"github.ibm.com/SoftLayer/softlayer-cli/plugin/metadata"
1212
"github.ibm.com/SoftLayer/softlayer-cli/plugin/testhelpers"
1313
)
1414

15-
var _ = Describe("Account Bandwidth-Pools", func() {
15+
var _ = Describe("Bandwidth Pools", func() {
1616
var (
1717
fakeUI *terminal.FakeUI
18-
cliCommand *account.BandwidthPoolsCommand
18+
cliCommand *bandwidth.PoolsCommand
1919
fakeSession *session.Session
2020
slCommand *metadata.SoftlayerCommand
2121
)
2222
BeforeEach(func() {
2323
fakeUI = terminal.NewFakeUI()
2424
fakeSession = testhelpers.NewFakeSoftlayerSession([]string{})
2525
slCommand = metadata.NewSoftlayerCommand(fakeUI, fakeSession)
26-
cliCommand = account.NewBandwidthPoolsCommand(slCommand)
26+
cliCommand = bandwidth.NewPoolsCommand(slCommand)
2727
cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.")
2828
})
2929

30-
Describe("Bandwidth-Pools Testing", func() {
30+
Describe("Bandwidth Pools Testing", func() {
3131
Context("Happy Path", func() {
3232
It("Runs without issue", func() {
3333
err := testhelpers.RunCobraCommand(cliCommand.Command)

0 commit comments

Comments
 (0)