|
| 1 | +package account_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "errors" |
| 5 | + "time" |
| 6 | + |
| 7 | + "github.com/IBM-Cloud/ibm-cloud-cli-sdk/testhelpers/terminal" |
| 8 | + . "github.com/onsi/ginkgo" |
| 9 | + . "github.com/onsi/gomega" |
| 10 | + |
| 11 | + "github.com/softlayer/softlayer-go/datatypes" |
| 12 | + "github.com/softlayer/softlayer-go/session" |
| 13 | + "github.com/softlayer/softlayer-go/sl" |
| 14 | + |
| 15 | + "github.ibm.com/SoftLayer/softlayer-cli/plugin/commands/account" |
| 16 | + "github.ibm.com/SoftLayer/softlayer-cli/plugin/metadata" |
| 17 | + "github.ibm.com/SoftLayer/softlayer-cli/plugin/testhelpers" |
| 18 | +) |
| 19 | + |
| 20 | +var _ = Describe("account hook-create", func() { |
| 21 | + var ( |
| 22 | + fakeUI *terminal.FakeUI |
| 23 | + cliCommand *account.HookCreateCommand |
| 24 | + fakeSession *session.Session |
| 25 | + slCommand *metadata.SoftlayerCommand |
| 26 | + fakeAccountManager *testhelpers.FakeAccountManager |
| 27 | + ) |
| 28 | + BeforeEach(func() { |
| 29 | + fakeUI = terminal.NewFakeUI() |
| 30 | + fakeSession = testhelpers.NewFakeSoftlayerSession([]string{}) |
| 31 | + fakeAccountManager = new(testhelpers.FakeAccountManager) |
| 32 | + slCommand = metadata.NewSoftlayerCommand(fakeUI, fakeSession) |
| 33 | + cliCommand = account.NewHookCreateCommand(slCommand) |
| 34 | + cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.") |
| 35 | + cliCommand.AccountManager = fakeAccountManager |
| 36 | + }) |
| 37 | + |
| 38 | + Describe("account hook-create", func() { |
| 39 | + |
| 40 | + Context("Return error", func() { |
| 41 | + |
| 42 | + It("Set invalid output", func() { |
| 43 | + err := testhelpers.RunCobraCommand(cliCommand.Command, "--name=myhook", "--uri=http://myuritest.com", "--output=xml") |
| 44 | + Expect(err).To(HaveOccurred()) |
| 45 | + Expect(err.Error()).To(ContainSubstring("Incorrect Usage: Invalid output format, only JSON is supported now.")) |
| 46 | + }) |
| 47 | + }) |
| 48 | + |
| 49 | + Context("Return error", func() { |
| 50 | + BeforeEach(func() { |
| 51 | + fakeAccountManager.CreateProvisioningScriptReturns(datatypes.Provisioning_Hook{}, errors.New("Failed to create Provisioning Hook")) |
| 52 | + }) |
| 53 | + It("Failed to create Provisioning Hook", func() { |
| 54 | + err := testhelpers.RunCobraCommand(cliCommand.Command, "--name=myhook", "--uri=http://myuritest.com") |
| 55 | + Expect(err).To(HaveOccurred()) |
| 56 | + Expect(err.Error()).To(ContainSubstring("Failed to create Provisioning Hook")) |
| 57 | + }) |
| 58 | + }) |
| 59 | + |
| 60 | + Context("Return no error", func() { |
| 61 | + BeforeEach(func() { |
| 62 | + created, _ := time.Parse(time.RFC3339, "2017-11-08T00:00:00Z") |
| 63 | + fakerHook := datatypes.Provisioning_Hook{ |
| 64 | + Id: sl.Int(123456), |
| 65 | + Name: sl.String("My Hook"), |
| 66 | + CreateDate: sl.Time(created), |
| 67 | + Uri: sl.String("http://myuritest.com"), |
| 68 | + } |
| 69 | + fakeAccountManager.CreateProvisioningScriptReturns(fakerHook, nil) |
| 70 | + }) |
| 71 | + It("Return no error", func() { |
| 72 | + err := testhelpers.RunCobraCommand(cliCommand.Command, "--name=myhook", "--uri=http://myuritest.com") |
| 73 | + Expect(err).NotTo(HaveOccurred()) |
| 74 | + Expect(fakeUI.Outputs()).To(ContainSubstring("123456")) |
| 75 | + Expect(fakeUI.Outputs()).To(ContainSubstring("My Hook")) |
| 76 | + Expect(fakeUI.Outputs()).To(ContainSubstring("2017-11-08T00:00:00Z")) |
| 77 | + Expect(fakeUI.Outputs()).To(ContainSubstring("http://myuritest.com")) |
| 78 | + }) |
| 79 | + }) |
| 80 | + }) |
| 81 | +}) |
0 commit comments