|
| 1 | +package bandwidth_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "errors" |
| 5 | + "strings" |
| 6 | + |
| 7 | + . "github.com/IBM-Cloud/ibm-cloud-cli-sdk/testhelpers/matchers" |
| 8 | + "github.com/IBM-Cloud/ibm-cloud-cli-sdk/testhelpers/terminal" |
| 9 | + . "github.com/onsi/ginkgo" |
| 10 | + . "github.com/onsi/gomega" |
| 11 | + "github.com/softlayer/softlayer-go/session" |
| 12 | + "github.ibm.com/SoftLayer/softlayer-cli/plugin/commands/bandwidth" |
| 13 | + "github.ibm.com/SoftLayer/softlayer-cli/plugin/metadata" |
| 14 | + "github.ibm.com/SoftLayer/softlayer-cli/plugin/testhelpers" |
| 15 | +) |
| 16 | + |
| 17 | +var _ = Describe("Bandwidth Pool delete", func() { |
| 18 | + var ( |
| 19 | + fakeUI *terminal.FakeUI |
| 20 | + cliCommand *bandwidth.DeleteCommand |
| 21 | + fakeSession *session.Session |
| 22 | + slCommand *metadata.SoftlayerCommand |
| 23 | + fakeBandwidthManager *testhelpers.FakeBandwidthManager |
| 24 | + ) |
| 25 | + BeforeEach(func() { |
| 26 | + fakeUI = terminal.NewFakeUI() |
| 27 | + fakeSession = testhelpers.NewFakeSoftlayerSession([]string{}) |
| 28 | + fakeBandwidthManager = new(testhelpers.FakeBandwidthManager) |
| 29 | + slCommand = metadata.NewSoftlayerCommand(fakeUI, fakeSession) |
| 30 | + cliCommand = bandwidth.NewDeleteCommand(slCommand) |
| 31 | + cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.") |
| 32 | + cliCommand.BandwidthManager = fakeBandwidthManager |
| 33 | + }) |
| 34 | + |
| 35 | + Describe("Bandwidth Pool delete", func() { |
| 36 | + Context("Bandwidth Pool delete without ID", func() { |
| 37 | + It("return error", func() { |
| 38 | + err := testhelpers.RunCobraCommand(cliCommand.Command) |
| 39 | + Expect(err).To(HaveOccurred()) |
| 40 | + Expect(strings.Contains(err.Error(), "Incorrect Usage: This command requires one argument")).To(BeTrue()) |
| 41 | + }) |
| 42 | + }) |
| 43 | + Context("Bandwidth Pool delete with wrong bandwidth id", func() { |
| 44 | + It("return error", func() { |
| 45 | + err := testhelpers.RunCobraCommand(cliCommand.Command, "abc") |
| 46 | + Expect(err).To(HaveOccurred()) |
| 47 | + Expect(strings.Contains(err.Error(), "Invalid input for 'Bandwidth Pool ID'. It must be a positive integer.")).To(BeTrue()) |
| 48 | + }) |
| 49 | + }) |
| 50 | + |
| 51 | + Context("Bandwidth Pool delete with correct bandwidth id but id not found", func() { |
| 52 | + BeforeEach(func() { |
| 53 | + fakeBandwidthManager.DeleteBandwidthReturns(errors.New("SoftLayer_Exception_ObjectNotFound")) |
| 54 | + }) |
| 55 | + It("return error", func() { |
| 56 | + err := testhelpers.RunCobraCommand(cliCommand.Command, "12345678") |
| 57 | + Expect(err).To(HaveOccurred()) |
| 58 | + Expect(strings.Contains(err.Error(), "SoftLayer_Exception_ObjectNotFound")).To(BeTrue()) |
| 59 | + }) |
| 60 | + }) |
| 61 | + |
| 62 | + Context("Bandwidth Pool delete with correct bandwidth id but server API call fails", func() { |
| 63 | + BeforeEach(func() { |
| 64 | + fakeBandwidthManager.DeleteBandwidthReturns(errors.New("Internal Server Error")) |
| 65 | + }) |
| 66 | + It("return error", func() { |
| 67 | + err := testhelpers.RunCobraCommand(cliCommand.Command, "12345678") |
| 68 | + Expect(err).To(HaveOccurred()) |
| 69 | + Expect(strings.Contains(err.Error(), "Internal Server Error")).To(BeTrue()) |
| 70 | + }) |
| 71 | + }) |
| 72 | + |
| 73 | + Context("Bandwidth Pool delete with correct bandwidth id", func() { |
| 74 | + BeforeEach(func() { |
| 75 | + fakeBandwidthManager.DeleteBandwidthReturns(nil) |
| 76 | + }) |
| 77 | + It("return no error", func() { |
| 78 | + err := testhelpers.RunCobraCommand(cliCommand.Command, "12345678") |
| 79 | + 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."})) |
| 82 | + }) |
| 83 | + }) |
| 84 | + }) |
| 85 | +}) |
0 commit comments