|
| 1 | +package cdn_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/IBM-Cloud/ibm-cloud-cli-sdk/testhelpers/terminal" |
| 5 | + . "github.com/onsi/ginkgo" |
| 6 | + . "github.com/onsi/gomega" |
| 7 | + "github.com/softlayer/softlayer-go/session" |
| 8 | + |
| 9 | + "github.ibm.com/SoftLayer/softlayer-cli/plugin/commands/cdn" |
| 10 | + "github.ibm.com/SoftLayer/softlayer-cli/plugin/metadata" |
| 11 | + "github.ibm.com/SoftLayer/softlayer-cli/plugin/testhelpers" |
| 12 | +) |
| 13 | + |
| 14 | +var _ = Describe("Cdn origin list Cdn", func() { |
| 15 | + var ( |
| 16 | + fakeUI *terminal.FakeUI |
| 17 | + cliCommand *cdn.OriginListCommand |
| 18 | + fakeSession *session.Session |
| 19 | + slCommand *metadata.SoftlayerCommand |
| 20 | + ) |
| 21 | + BeforeEach(func() { |
| 22 | + fakeUI = terminal.NewFakeUI() |
| 23 | + fakeSession = testhelpers.NewFakeSoftlayerSession([]string{}) |
| 24 | + slCommand = metadata.NewSoftlayerCommand(fakeUI, fakeSession) |
| 25 | + cliCommand = cdn.NewOriginListCommand(slCommand) |
| 26 | + cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.") |
| 27 | + }) |
| 28 | + |
| 29 | + Describe("Cdn origin list", func() { |
| 30 | + Context("Cdn origin list, Invalid Usage", func() { |
| 31 | + It("Set command with an invalid output option", func() { |
| 32 | + err := testhelpers.RunCobraCommand(cliCommand.Command, "123456789", "--output=xml") |
| 33 | + Expect(err).To(HaveOccurred()) |
| 34 | + Expect(err.Error()).To(ContainSubstring("Incorrect Usage: Invalid output format, only JSON is supported now.")) |
| 35 | + }) |
| 36 | + |
| 37 | + It("Set command with an invalid output option", func() { |
| 38 | + err := testhelpers.RunCobraCommand(cliCommand.Command) |
| 39 | + Expect(err).To(HaveOccurred()) |
| 40 | + Expect(err.Error()).To(ContainSubstring("Incorrect Usage: This command requires one argument.")) |
| 41 | + }) |
| 42 | + }) |
| 43 | + |
| 44 | + Context("Cdn origin list, correct use", func() { |
| 45 | + It("return cdn list", func() { |
| 46 | + err := testhelpers.RunCobraCommand(cliCommand.Command, "123456789") |
| 47 | + Expect(err).NotTo(HaveOccurred()) |
| 48 | + Expect(fakeUI.Outputs()).To(ContainSubstring("Path")) |
| 49 | + Expect(fakeUI.Outputs()).To(ContainSubstring("Origin")) |
| 50 | + Expect(fakeUI.Outputs()).To(ContainSubstring("/example1/*")) |
| 51 | + Expect(fakeUI.Outputs()).To(ContainSubstring("123.123.123.123")) |
| 52 | + Expect(fakeUI.Outputs()).To(ContainSubstring("RUNNING")) |
| 53 | + }) |
| 54 | + |
| 55 | + It("return origin list in format json", func() { |
| 56 | + err := testhelpers.RunCobraCommand(cliCommand.Command, "123456789", "--output", "json") |
| 57 | + Expect(err).NotTo(HaveOccurred()) |
| 58 | + Expect(fakeUI.Outputs()).To(ContainSubstring(`"Path": "/example1/*",`)) |
| 59 | + Expect(fakeUI.Outputs()).To(ContainSubstring(`"Origin": "123.123.123.123",`)) |
| 60 | + Expect(fakeUI.Outputs()).To(ContainSubstring(`"Http Port": "80",`)) |
| 61 | + Expect(fakeUI.Outputs()).To(ContainSubstring(`"Status": "RUNNING"`)) |
| 62 | + Expect(fakeUI.Outputs()).To(ContainSubstring(`[`)) |
| 63 | + Expect(fakeUI.Outputs()).To(ContainSubstring(`{`)) |
| 64 | + Expect(fakeUI.Outputs()).To(ContainSubstring(`}`)) |
| 65 | + Expect(fakeUI.Outputs()).To(ContainSubstring(`]`)) |
| 66 | + }) |
| 67 | + }) |
| 68 | + }) |
| 69 | +}) |
0 commit comments