Skip to content

Commit 2a4fb30

Browse files
#727 updated a few strings and fixed the unit tests
1 parent 39ae237 commit 2a4fb30

6 files changed

Lines changed: 44 additions & 34 deletions

File tree

plugin/commands/bandwidth/pools_delete.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,19 @@ func NewDeleteCommand(sl *metadata.SoftlayerCommand) (cmd *DeleteCommand) {
4040
func (cmd *DeleteCommand) Run(args []string) error {
4141
bandwidthPoolId, err := strconv.Atoi(args[0])
4242
if err != nil {
43-
return slErrors.NewInvalidSoftlayerIdInputError("Bandwidth Pool ID")
43+
return slErrors.NewInvalidSoftlayerIdInputError("IDENTIFIER")
4444
}
4545

4646
err = cmd.BandwidthManager.DeletePool(bandwidthPoolId)
47-
// if err != nil {
48-
// return slErrors.NewAPIError(T("Failed to delete bandwidth with Id: {{.bandwidthPoolId}}.\n", map[string]interface{}{"bandwidthPoolId": bandwidthPoolId}), err.Error(), 2)
4947

50-
// }
5148
if err != nil {
5249
if strings.Contains(err.Error(), slErrors.SL_EXP_OBJ_NOT_FOUND) {
53-
return slErrors.NewAPIError(T("Unable to find Bandwidth pool with ID {{.bandwidthPoolId}}.\n", map[string]interface{}{"bandwidthPoolId": bandwidthPoolId}), err.Error(), 0)
50+
return slErrors.NewAPIError(T("Unable to find bandwidth pool with ID {{.bandwidthPoolId}}.\n", map[string]interface{}{"bandwidthPoolId": bandwidthPoolId}), err.Error(), 0)
5451
}
55-
return slErrors.NewAPIError(T("Failed to delete bandwidth with Id: {{.bandwidthPoolId}}.\n", map[string]interface{}{"bandwidthPoolId": bandwidthPoolId}), err.Error(), 2)
52+
return slErrors.NewAPIError(T("Failed to delete bandwidth pool with Id: {{.bandwidthPoolId}}.\n", map[string]interface{}{"bandwidthPoolId": bandwidthPoolId}), err.Error(), 2)
5653

5754
}
5855
cmd.UI.Ok()
59-
cmd.UI.Print(T("BandwidthPool associated with Id {{.bandwidthPoolId}} was deleted.", map[string]interface{}{"bandwidthPoolId": bandwidthPoolId}))
56+
cmd.UI.Print(T("Bandwidth pool {{.bandwidthPoolId}} was deleted.", map[string]interface{}{"bandwidthPoolId": bandwidthPoolId}))
6057
return nil
6158
}

plugin/commands/bandwidth/pools_delete_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ package bandwidth_test
22

33
import (
44
"errors"
5-
"strings"
65

7-
. "github.com/IBM-Cloud/ibm-cloud-cli-sdk/testhelpers/matchers"
86
"github.com/IBM-Cloud/ibm-cloud-cli-sdk/testhelpers/terminal"
97
. "github.com/onsi/ginkgo"
108
. "github.com/onsi/gomega"
@@ -37,48 +35,50 @@ var _ = Describe("Bandwidth Pool delete", func() {
3735
It("return error", func() {
3836
err := testhelpers.RunCobraCommand(cliCommand.Command)
3937
Expect(err).To(HaveOccurred())
40-
Expect(strings.Contains(err.Error(), "Incorrect Usage: This command requires one argument")).To(BeTrue())
38+
Expect(err.Error()).To(ContainSubstring(""))
39+
Expect(err.Error()).To(ContainSubstring("Incorrect Usage: This command requires one argument"))
40+
4141
})
4242
})
4343
Context("Bandwidth Pool delete with wrong bandwidth id", func() {
4444
It("return error", func() {
4545
err := testhelpers.RunCobraCommand(cliCommand.Command, "abc")
4646
Expect(err).To(HaveOccurred())
47-
Expect(strings.Contains(err.Error(), "Invalid input for 'Bandwidth Pool ID'. It must be a positive integer.")).To(BeTrue())
47+
Expect(err.Error()).To(ContainSubstring("Invalid input for 'IDENTIFIER'. It must be a positive integer."))
4848
})
4949
})
5050

5151
Context("Bandwidth Pool delete with correct bandwidth id but id not found", func() {
5252
BeforeEach(func() {
53-
fakeBandwidthManager.DeleteBandwidthReturns(errors.New("SoftLayer_Exception_ObjectNotFound"))
53+
fakeBandwidthManager.DeletePoolReturns(errors.New("SoftLayer_Exception_ObjectNotFound"))
5454
})
5555
It("return error", func() {
5656
err := testhelpers.RunCobraCommand(cliCommand.Command, "12345678")
5757
Expect(err).To(HaveOccurred())
58-
Expect(strings.Contains(err.Error(), "SoftLayer_Exception_ObjectNotFound")).To(BeTrue())
58+
Expect(err.Error()).To(ContainSubstring("SoftLayer_Exception_ObjectNotFound"))
5959
})
6060
})
6161

6262
Context("Bandwidth Pool delete with correct bandwidth id but server API call fails", func() {
6363
BeforeEach(func() {
64-
fakeBandwidthManager.DeleteBandwidthReturns(errors.New("Internal Server Error"))
64+
fakeBandwidthManager.DeletePoolReturns(errors.New("Internal Server Error"))
6565
})
6666
It("return error", func() {
6767
err := testhelpers.RunCobraCommand(cliCommand.Command, "12345678")
6868
Expect(err).To(HaveOccurred())
69-
Expect(strings.Contains(err.Error(), "Internal Server Error")).To(BeTrue())
69+
Expect(err.Error()).To(ContainSubstring("Internal Server Error"))
7070
})
7171
})
7272

7373
Context("Bandwidth Pool delete with correct bandwidth id", func() {
7474
BeforeEach(func() {
75-
fakeBandwidthManager.DeleteBandwidthReturns(nil)
75+
fakeBandwidthManager.DeletePoolReturns(nil)
7676
})
7777
It("return no error", func() {
7878
err := testhelpers.RunCobraCommand(cliCommand.Command, "12345678")
7979
Expect(err).NotTo(HaveOccurred())
80-
Expect(fakeUI.Outputs()).To(ContainSubstrings([]string{"OK"}))
81-
Expect(fakeUI.Outputs()).To(ContainSubstrings([]string{"BandwidthPool associated with Id 12345678 was deleted."}))
80+
Expect(fakeUI.Outputs()).To(ContainSubstring("OK"))
81+
Expect(fakeUI.Outputs()).To(ContainSubstring("Bandwidth pool 12345678 was deleted."))
8282
})
8383
})
8484
})

plugin/commands/bandwidth/pools_edit.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"github.com/softlayer/softlayer-go/datatypes"
77
"github.com/spf13/cobra"
88

9-
"github.ibm.com/SoftLayer/softlayer-cli/plugin/errors"
109
slErrors "github.ibm.com/SoftLayer/softlayer-cli/plugin/errors"
1110
. "github.ibm.com/SoftLayer/softlayer-cli/plugin/i18n"
1211
"github.ibm.com/SoftLayer/softlayer-cli/plugin/managers"
@@ -61,25 +60,23 @@ func NewEditCommand(sl *metadata.SoftlayerCommand) (cmd *EditCommand) {
6160
func (cmd *EditCommand) Run(args []string) error {
6261
bandwidthPoolId, err := strconv.Atoi(args[0])
6362
if err != nil {
64-
return slErrors.NewInvalidSoftlayerIdInputError("Bandwidth Pool ID")
65-
}
66-
if cmd.Name == "" {
67-
return slErrors.NewInvalidUsageError(T("--name must be specified."))
63+
return slErrors.NewInvalidSoftlayerIdInputError("IDENTIFIER")
6864
}
65+
6966
locationGroup, err := cmd.BandwidthManager.GetLocationGroup()
7067
if err != nil {
71-
return errors.NewAPIError(T("Failed to get Location Group."), err.Error(), 2)
68+
return err
7269
}
7370
idLocationGroup := finId_LocationGroup(locationGroup, LOCATION_GROUPS1[cmd.Name])
7471

7572
_, err = cmd.BandwidthManager.EditPool(bandwidthPoolId, idLocationGroup, cmd.Name)
7673
if err != nil {
77-
return slErrors.NewAPIError(T("Failed to edit bandwidth with Id: {{.bandwidthPoolId}}.\n", map[string]interface{}{"bandwidthPoolId": bandwidthPoolId}), err.Error(), 2)
74+
return err
7875

7976
}
8077
cmd.UI.Ok()
8178
subs := map[string]interface{}{"bandwidthPoolId": bandwidthPoolId}
82-
cmd.UI.Print(T("BandwidthPool associated with Id {{.bandwidthPoolId}} was edited successfully.", subs))
79+
cmd.UI.Print(T("Bandwidth pool {{.bandwidthPoolId}} was edited successfully.", subs))
8380
return nil
8481
}
8582

plugin/commands/bandwidth/pools_edit_test.go

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

33
import (
4+
45
"errors"
5-
"strings"
66

77
"github.com/IBM-Cloud/ibm-cloud-cli-sdk/testhelpers/terminal"
88
. "github.com/onsi/ginkgo"
@@ -32,22 +32,38 @@ var _ = Describe("Bandwidth Pool edit", func() {
3232
})
3333

3434
Describe("Bandwidth Pool edit", func() {
35-
Context("Bandwidth Pool cancel without ID", func() {
35+
Context("Bandwidth Pool invalid usage", func() {
3636
It("return error", func() {
3737
err := testhelpers.RunCobraCommand(cliCommand.Command)
3838
Expect(err).To(HaveOccurred())
39-
Expect(strings.Contains(err.Error(), "Incorrect Usage: This command requires one argument")).To(BeTrue())
39+
Expect(err.Error()).To(ContainSubstring("Incorrect Usage: This command requires one argument"))
40+
41+
})
42+
It("return error", func() {
43+
err := testhelpers.RunCobraCommand(cliCommand.Command, "123456")
44+
Expect(err).To(HaveOccurred())
45+
Expect(err.Error()).To(ContainSubstring(`required flag(s) "name" not set`))
4046
})
4147
})
42-
Context("Bandwidth Pool edit with correct Bandwidth Pool associated with id and --name ibm-internal-test", func() {
48+
Context("Happy Path", func() {
4349
BeforeEach(func() {
44-
fakeBandwidthManager.EditBandwidthReturns(true, errors.New("The Bandwidth Pool associated with Id 12345678 was edited successfully."))
50+
fakeBandwidthManager.EditPoolReturns(true, nil)
4551
})
4652
It("return error", func() {
4753
err := testhelpers.RunCobraCommand(cliCommand.Command, "12345678", "--name", "ibm-internal-test")
4854
Expect(err).NotTo(HaveOccurred())
4955
Expect(fakeUI.Outputs()).To(ContainSubstring("OK"))
50-
Expect(fakeUI.Outputs()).To(ContainSubstring("The Bandwidth Pool associated with Id 12345678 was edited successfully."))
56+
Expect(fakeUI.Outputs()).To(ContainSubstring("Bandwidth pool 12345678 was edited successfully."))
57+
})
58+
})
59+
Context("API Errors", func() {
60+
BeforeEach(func() {
61+
fakeBandwidthManager.EditPoolReturns(false, errors.New("API ERROR"))
62+
})
63+
It("return error", func() {
64+
err := testhelpers.RunCobraCommand(cliCommand.Command, "12345678", "--name", "ibm-internal-test")
65+
Expect(err).To(HaveOccurred())
66+
Expect(err.Error()).To(ContainSubstring("API ERROR"))
5167
})
5268
})
5369
})

plugin/commands/user/vpn_disable.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (cmd *VpnDisableCommand) Run(args []string) error {
4848
}
4949
success, err := cmd.UserManager.EditUser(userTemplate, userID)
5050
if err != nil {
51-
return slErrors.NewAPIError(T(""), err.Error(), 2)
51+
return err
5252
}
5353
if success {
5454
cmd.UI.Ok()

plugin/commands/user/vpn_enable.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (cmd *VpnEnableCommand) Run(args []string) error {
4848
}
4949
success, err := cmd.UserManager.EditUser(userTemplate, userID)
5050
if err != nil {
51-
return slErrors.NewAPIError(T(""), err.Error(), 2)
51+
return err
5252
}
5353
if success {
5454
cmd.UI.Ok()

0 commit comments

Comments
 (0)