|
| 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 add", func() { |
| 15 | + var ( |
| 16 | + fakeUI *terminal.FakeUI |
| 17 | + cliCommand *cdn.OriginAddCommand |
| 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.NewOriginAddCommand(slCommand) |
| 26 | + cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.") |
| 27 | + }) |
| 28 | + |
| 29 | + Describe("Cdn origin add", func() { |
| 30 | + Context("Cdn origin add, Invalid Usage", func() { |
| 31 | + It("Set command with an invalid output option", func() { |
| 32 | + err := testhelpers.RunCobraCommand(cliCommand.Command, "--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 | + It("Set command without id", func() { |
| 37 | + err := testhelpers.RunCobraCommand(cliCommand.Command) |
| 38 | + Expect(err).To(HaveOccurred()) |
| 39 | + Expect(err.Error()).To(ContainSubstring("Incorrect Usage: This command requires one argument")) |
| 40 | + }) |
| 41 | + It("Set command without flag hostname", func() { |
| 42 | + err := testhelpers.RunCobraCommand(cliCommand.Command, "123456789") |
| 43 | + Expect(err).To(HaveOccurred()) |
| 44 | + Expect(err.Error()).To(ContainSubstring(`required flag(s) "origin", "path" not set`)) |
| 45 | + }) |
| 46 | + It("Set command without flag origin", func() { |
| 47 | + err := testhelpers.RunCobraCommand(cliCommand.Command, "123456789", "--origin", "123.123.123.123") |
| 48 | + Expect(err).To(HaveOccurred()) |
| 49 | + Expect(err.Error()).To(ContainSubstring(`required flag(s) "path" not set`)) |
| 50 | + }) |
| 51 | + It("Set command without flag http or https", func() { |
| 52 | + err := testhelpers.RunCobraCommand(cliCommand.Command, "123456789", "--origin", "123.123.123.123", "--path", "/example/videos") |
| 53 | + Expect(err).To(HaveOccurred()) |
| 54 | + Expect(err.Error()).To(ContainSubstring(`Incorrect Usage: 'http or https' is required`)) |
| 55 | + }) |
| 56 | + It("Set command with flag wrong origin-type", func() { |
| 57 | + err := testhelpers.RunCobraCommand(cliCommand.Command, "123456789", "--origin", "123.123.123.123", "--path", "/example/videos", "--http", "80", "--origin-type", "asdfgh") |
| 58 | + Expect(err).To(HaveOccurred()) |
| 59 | + Expect(err.Error()).To(ContainSubstring(`Incorrect Usage: --origintype`)) |
| 60 | + }) |
| 61 | + It("Set command with flag wrong optimize", func() { |
| 62 | + err := testhelpers.RunCobraCommand(cliCommand.Command, "123456789", "--origin", "123.123.123.123", "--path", "/example/videos", "--http", "80", "--optimize", "notPermit") |
| 63 | + Expect(err).To(HaveOccurred()) |
| 64 | + Expect(err.Error()).To(ContainSubstring(`Incorrect Usage: --optimize`)) |
| 65 | + }) |
| 66 | + It("Set command with flag wrong cache-key", func() { |
| 67 | + err := testhelpers.RunCobraCommand(cliCommand.Command, "123456789", "--origin", "123.123.123.123", "--path", "/example/videos", "--http", "80", "--cache-key", "notPermit") |
| 68 | + Expect(err).To(HaveOccurred()) |
| 69 | + Expect(err.Error()).To(ContainSubstring(`Incorrect Usage: --cache-key`)) |
| 70 | + }) |
| 71 | + It("Set command with flag originType like storage and empty bucket-name", func() { |
| 72 | + err := testhelpers.RunCobraCommand(cliCommand.Command, "123456789", "--origin", "123.123.123.123", "--path", "/example/videos", "--http", "80", "--origin-type", "storage") |
| 73 | + Expect(err).To(HaveOccurred()) |
| 74 | + Expect(err.Error()).To(ContainSubstring(`Incorrect Usage: --bucket-name can not be empty`)) |
| 75 | + }) |
| 76 | + }) |
| 77 | + |
| 78 | + Context("Cdn origin add, correct use", func() { |
| 79 | + It("return cdn origin add", func() { |
| 80 | + err := testhelpers.RunCobraCommand(cliCommand.Command, "123456789", "--origin", "123.123.123.123","--path", "/example/videos/", "--http", "80", "--origin-type", "storage", "--bucket-name", "bucketName", "--file-extensions", "jpg") |
| 81 | + Expect(err).NotTo(HaveOccurred()) |
| 82 | + Expect(fakeUI.Outputs()).To(ContainSubstring("CDN Unique ID")) |
| 83 | + Expect(fakeUI.Outputs()).To(ContainSubstring("354034879028850")) |
| 84 | + Expect(fakeUI.Outputs()).To(ContainSubstring("File Extension")) |
| 85 | + Expect(fakeUI.Outputs()).To(ContainSubstring("jpg,pdf,jpeg,png")) |
| 86 | + Expect(fakeUI.Outputs()).To(ContainSubstring("Header")) |
| 87 | + Expect(fakeUI.Outputs()).To(ContainSubstring("header.test.com")) |
| 88 | + Expect(fakeUI.Outputs()).To(ContainSubstring("Path")) |
| 89 | + Expect(fakeUI.Outputs()).To(ContainSubstring("/example/videos")) |
| 90 | + Expect(fakeUI.Outputs()).To(ContainSubstring("Cache Key Rule")) |
| 91 | + Expect(fakeUI.Outputs()).To(ContainSubstring("include-all")) |
| 92 | + Expect(fakeUI.Outputs()).To(ContainSubstring("Performance Configuration")) |
| 93 | + Expect(fakeUI.Outputs()).To(ContainSubstring("General web delivery")) |
| 94 | + Expect(fakeUI.Outputs()).To(ContainSubstring("Status")) |
| 95 | + Expect(fakeUI.Outputs()).To(ContainSubstring("RUNNING")) |
| 96 | + }) |
| 97 | + It("return cdn in format json", func() { |
| 98 | + err := testhelpers.RunCobraCommand(cliCommand.Command, "123456789", "--origin", "123.123.123.123","--path", "/example/videos/", "--http", "80", "--output", "json") |
| 99 | + Expect(err).NotTo(HaveOccurred()) |
| 100 | + Expect(fakeUI.Outputs()).To(ContainSubstring(`"Name": "CDN Unique ID",`)) |
| 101 | + Expect(fakeUI.Outputs()).To(ContainSubstring(`"Value": "354034879028850"`)) |
| 102 | + Expect(fakeUI.Outputs()).To(ContainSubstring(`[`)) |
| 103 | + Expect(fakeUI.Outputs()).To(ContainSubstring(`{`)) |
| 104 | + Expect(fakeUI.Outputs()).To(ContainSubstring(`}`)) |
| 105 | + Expect(fakeUI.Outputs()).To(ContainSubstring(`]`)) |
| 106 | + }) |
| 107 | + }) |
| 108 | + }) |
| 109 | +}) |
0 commit comments