|
| 1 | +package account_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 | + |
| 10 | + "github.com/softlayer/softlayer-go/session" |
| 11 | + |
| 12 | + "github.ibm.com/SoftLayer/softlayer-cli/plugin/commands/account" |
| 13 | + "github.ibm.com/SoftLayer/softlayer-cli/plugin/metadata" |
| 14 | + "github.ibm.com/SoftLayer/softlayer-cli/plugin/testhelpers" |
| 15 | +) |
| 16 | + |
| 17 | +var _ = Describe("account hook-delete", func() { |
| 18 | + var ( |
| 19 | + fakeUI *terminal.FakeUI |
| 20 | + cliCommand *account.HookDeleteCommand |
| 21 | + fakeSession *session.Session |
| 22 | + slCommand *metadata.SoftlayerCommand |
| 23 | + fakeAccountManager *testhelpers.FakeAccountManager |
| 24 | + ) |
| 25 | + BeforeEach(func() { |
| 26 | + fakeUI = terminal.NewFakeUI() |
| 27 | + fakeSession = testhelpers.NewFakeSoftlayerSession([]string{}) |
| 28 | + fakeAccountManager = new(testhelpers.FakeAccountManager) |
| 29 | + slCommand = metadata.NewSoftlayerCommand(fakeUI, fakeSession) |
| 30 | + cliCommand = account.NewHookDeleteCommand(slCommand) |
| 31 | + cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.") |
| 32 | + cliCommand.AccountManager = fakeAccountManager |
| 33 | + }) |
| 34 | + |
| 35 | + Describe("account hook-delete", func() { |
| 36 | + |
| 37 | + Context("Return error", func() { |
| 38 | + It("return error", func() { |
| 39 | + err := testhelpers.RunCobraCommand(cliCommand.Command) |
| 40 | + Expect(err).To(HaveOccurred()) |
| 41 | + Expect(err.Error()).To(ContainSubstring("Incorrect Usage: This command requires one argument")) |
| 42 | + }) |
| 43 | + |
| 44 | + It("return error", func() { |
| 45 | + err := testhelpers.RunCobraCommand(cliCommand.Command, "abc") |
| 46 | + Expect(err).To(HaveOccurred()) |
| 47 | + Expect(err.Error()).To(ContainSubstring("Invalid input for 'Hook ID'. It must be a positive integer.")) |
| 48 | + }) |
| 49 | + }) |
| 50 | + |
| 51 | + Context("Return error", func() { |
| 52 | + BeforeEach(func() { |
| 53 | + fakeAccountManager.DeleteProvisioningScriptReturns(false, errors.New("Failed to delete Provisioning Hook")) |
| 54 | + }) |
| 55 | + It("Failed to delete Provisioning Hook", func() { |
| 56 | + err := testhelpers.RunCobraCommand(cliCommand.Command, "123456") |
| 57 | + Expect(err).To(HaveOccurred()) |
| 58 | + Expect(err.Error()).To(ContainSubstring("Failed to delete Provisioning Hook")) |
| 59 | + }) |
| 60 | + }) |
| 61 | + |
| 62 | + Context("Return no error", func() { |
| 63 | + BeforeEach(func() { |
| 64 | + fakeAccountManager.DeleteProvisioningScriptReturns(true, nil) |
| 65 | + }) |
| 66 | + It("Return no error", func() { |
| 67 | + err := testhelpers.RunCobraCommand(cliCommand.Command, "123456") |
| 68 | + Expect(err).NotTo(HaveOccurred()) |
| 69 | + Expect(fakeUI.Outputs()).To(ContainSubstring("OK")) |
| 70 | + Expect(fakeUI.Outputs()).To(ContainSubstring("Successfully removed Provisioning Hook.")) |
| 71 | + }) |
| 72 | + }) |
| 73 | + }) |
| 74 | +}) |
0 commit comments