|
| 1 | +package order_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "errors" |
| 5 | + |
| 6 | + "github.com/IBM-Cloud/ibm-cloud-cli-sdk/testhelpers/terminal" |
| 7 | + . "github.com/onsi/ginkgo" |
| 8 | + . "github.com/onsi/gomega" |
| 9 | + "github.com/softlayer/softlayer-go/datatypes" |
| 10 | + |
| 11 | + "github.com/softlayer/softlayer-go/session" |
| 12 | + "github.com/softlayer/softlayer-go/sl" |
| 13 | + "github.ibm.com/SoftLayer/softlayer-cli/plugin/commands/order" |
| 14 | + "github.ibm.com/SoftLayer/softlayer-cli/plugin/metadata" |
| 15 | + "github.ibm.com/SoftLayer/softlayer-cli/plugin/testhelpers" |
| 16 | +) |
| 17 | + |
| 18 | +var _ = Describe("order quote-delete", func() { |
| 19 | + var ( |
| 20 | + fakeUI *terminal.FakeUI |
| 21 | + cliCommand *order.QuoteDeleteCommand |
| 22 | + fakeSession *session.Session |
| 23 | + slCommand *metadata.SoftlayerCommand |
| 24 | + fakeOrderManager *testhelpers.FakeOrderManager |
| 25 | + ) |
| 26 | + BeforeEach(func() { |
| 27 | + fakeUI = terminal.NewFakeUI() |
| 28 | + fakeOrderManager = new(testhelpers.FakeOrderManager) |
| 29 | + fakeSession = testhelpers.NewFakeSoftlayerSession([]string{}) |
| 30 | + slCommand = metadata.NewSoftlayerCommand(fakeUI, fakeSession) |
| 31 | + cliCommand = order.NewQuoteDeleteCommand(slCommand) |
| 32 | + cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.") |
| 33 | + cliCommand.OrderManager = fakeOrderManager |
| 34 | + }) |
| 35 | + |
| 36 | + Describe("order quote-delete", func() { |
| 37 | + |
| 38 | + Context("Return error", func() { |
| 39 | + It("Set command without Id", func() { |
| 40 | + err := testhelpers.RunCobraCommand(cliCommand.Command) |
| 41 | + Expect(err).To(HaveOccurred()) |
| 42 | + Expect(err.Error()).To(ContainSubstring("Incorrect Usage: This command requires one argument")) |
| 43 | + }) |
| 44 | + |
| 45 | + It("Set command with an invalid Id", func() { |
| 46 | + err := testhelpers.RunCobraCommand(cliCommand.Command, "abcde") |
| 47 | + Expect(err).To(HaveOccurred()) |
| 48 | + Expect(err.Error()).To(ContainSubstring("Invalid input for 'Quote ID'. It must be a positive integer.")) |
| 49 | + }) |
| 50 | + |
| 51 | + It("Set invalid output", func() { |
| 52 | + err := testhelpers.RunCobraCommand(cliCommand.Command, "123456", "--output=xml") |
| 53 | + Expect(err).To(HaveOccurred()) |
| 54 | + Expect(err.Error()).To(ContainSubstring("Incorrect Usage: Invalid output format, only JSON is supported now.")) |
| 55 | + }) |
| 56 | + }) |
| 57 | + |
| 58 | + Context("Return error", func() { |
| 59 | + BeforeEach(func() { |
| 60 | + fakeOrderManager.DeleteQuoteReturns(datatypes.Billing_Order_Quote{}, errors.New("Failed to delete Quote")) |
| 61 | + }) |
| 62 | + It("Failed delete Quote", func() { |
| 63 | + err := testhelpers.RunCobraCommand(cliCommand.Command, "123456") |
| 64 | + Expect(err).To(HaveOccurred()) |
| 65 | + Expect(err.Error()).To(ContainSubstring("Failed to delete Quote")) |
| 66 | + }) |
| 67 | + }) |
| 68 | + |
| 69 | + Context("Return no error", func() { |
| 70 | + BeforeEach(func() { |
| 71 | + fakerQuote := datatypes.Billing_Order_Quote{ |
| 72 | + Id: sl.Int(123456), |
| 73 | + } |
| 74 | + fakeOrderManager.DeleteQuoteReturns(fakerQuote, nil) |
| 75 | + }) |
| 76 | + It("Delete quote", func() { |
| 77 | + err := testhelpers.RunCobraCommand(cliCommand.Command, "123456") |
| 78 | + Expect(err).NotTo(HaveOccurred()) |
| 79 | + Expect(fakeUI.Outputs()).To(ContainSubstring("OK")) |
| 80 | + Expect(fakeUI.Outputs()).To(ContainSubstring("was deleted")) |
| 81 | + }) |
| 82 | + }) |
| 83 | + |
| 84 | + }) |
| 85 | +}) |
0 commit comments