|
| 1 | +package user_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 | + "github.com/softlayer/softlayer-go/session" |
| 11 | + "github.com/softlayer/softlayer-go/sl" |
| 12 | + |
| 13 | + "github.ibm.com/SoftLayer/softlayer-cli/plugin/commands/user" |
| 14 | + "github.ibm.com/SoftLayer/softlayer-cli/plugin/metadata" |
| 15 | + "github.ibm.com/SoftLayer/softlayer-cli/plugin/testhelpers" |
| 16 | +) |
| 17 | + |
| 18 | +var _ = Describe("user vpn-enable", func() { |
| 19 | + var ( |
| 20 | + fakeUI *terminal.FakeUI |
| 21 | + cliCommand *user.VpnDisableCommand |
| 22 | + fakeSession *session.Session |
| 23 | + slCommand *metadata.SoftlayerCommand |
| 24 | + fakeUserManager *testhelpers.FakeUserManager |
| 25 | + ) |
| 26 | + BeforeEach(func() { |
| 27 | + fakeUI = terminal.NewFakeUI() |
| 28 | + fakeSession = testhelpers.NewFakeSoftlayerSession([]string{}) |
| 29 | + fakeUserManager = new(testhelpers.FakeUserManager) |
| 30 | + slCommand = metadata.NewSoftlayerCommand(fakeUI, fakeSession) |
| 31 | + cliCommand = user.NewVpnDisableCommand(slCommand) |
| 32 | + cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.") |
| 33 | + cliCommand.UserManager = fakeUserManager |
| 34 | + |
| 35 | + testUser = datatypes.User_Customer{ |
| 36 | + SslVpnAllowedFlag: sl.Bool(false), |
| 37 | + } |
| 38 | + }) |
| 39 | + |
| 40 | + Describe("user vpn-enable", func() { |
| 41 | + |
| 42 | + Context("Return error", func() { |
| 43 | + It("Set command without Argument", func() { |
| 44 | + err := testhelpers.RunCobraCommand(cliCommand.Command) |
| 45 | + Expect(err).To(HaveOccurred()) |
| 46 | + Expect(err.Error()).To(ContainSubstring("Incorrect Usage: This command requires one argument.")) |
| 47 | + }) |
| 48 | + |
| 49 | + It("Set command with an invalid user Id", func() { |
| 50 | + err := testhelpers.RunCobraCommand(cliCommand.Command, "abcde") |
| 51 | + Expect(err).To(HaveOccurred()) |
| 52 | + Expect(err.Error()).To(ContainSubstring("Invalid input for 'User ID'. It must be a positive integer.")) |
| 53 | + }) |
| 54 | + }) |
| 55 | + |
| 56 | + Context("Account cancel-item, softlayer errors", func() { |
| 57 | + It("Set command with unknow item ID", func() { |
| 58 | + fakeUserManager.EditUserReturns(true, errors.New("SoftLayer_Exception_ObjectNotFound: Unable to find object with id of '123'. (HTTP 404)")) |
| 59 | + err := testhelpers.RunCobraCommand(cliCommand.Command, "123") |
| 60 | + Expect(err).To(HaveOccurred()) |
| 61 | + Expect(err.Error()).To(ContainSubstring("SoftLayer_Exception_ObjectNotFound: Unable to find object with id of '123'. (HTTP 404)")) |
| 62 | + }) |
| 63 | + }) |
| 64 | + |
| 65 | + Context("Return no error", func() { |
| 66 | + BeforeEach(func() { |
| 67 | + fakeUserManager.EditUserReturns(true, nil) |
| 68 | + }) |
| 69 | + It("enable", func() { |
| 70 | + err := testhelpers.RunCobraCommand(cliCommand.Command, "111111") |
| 71 | + Expect(err).NotTo(HaveOccurred()) |
| 72 | + Expect(fakeUI.Outputs()).To(ContainSubstring("OK")) |
| 73 | + }) |
| 74 | + }) |
| 75 | + }) |
| 76 | +}) |
0 commit comments