|
| 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 purge", func() { |
| 15 | + var ( |
| 16 | + fakeUI *terminal.FakeUI |
| 17 | + cliCommand *cdn.PurgeCommand |
| 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.NewPurgeCommand(slCommand) |
| 26 | + cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.") |
| 27 | + }) |
| 28 | + |
| 29 | + Describe("Cdn purge", func() { |
| 30 | + Context("Cdn purge, Invalid Usage", func() { |
| 31 | + It("Set command without id and path", func() { |
| 32 | + err := testhelpers.RunCobraCommand(cliCommand.Command) |
| 33 | + Expect(err).To(HaveOccurred()) |
| 34 | + Expect(err.Error()).To(ContainSubstring("Incorrect Usage: This command requires two arguments.")) |
| 35 | + }) |
| 36 | + }) |
| 37 | + |
| 38 | + Context("Cdn purge, correct use", func() { |
| 39 | + It("return cdn purge", func() { |
| 40 | + err := testhelpers.RunCobraCommand(cliCommand.Command, "123456789", "/example/") |
| 41 | + Expect(err).NotTo(HaveOccurred()) |
| 42 | + Expect(fakeUI.Outputs()).To(ContainSubstring("Date")) |
| 43 | + Expect(fakeUI.Outputs()).To(ContainSubstring("Path")) |
| 44 | + Expect(fakeUI.Outputs()).To(ContainSubstring("Saved")) |
| 45 | + Expect(fakeUI.Outputs()).To(ContainSubstring("Status")) |
| 46 | + Expect(fakeUI.Outputs()).To(ContainSubstring("/example/")) |
| 47 | + Expect(fakeUI.Outputs()).To(ContainSubstring("UNSAVED")) |
| 48 | + Expect(fakeUI.Outputs()).To(ContainSubstring("SUCCESS")) |
| 49 | + }) |
| 50 | + It("return cdn purge in format json", func() { |
| 51 | + err := testhelpers.RunCobraCommand(cliCommand.Command, "123456789", "/example/", "--output", "json") |
| 52 | + Expect(err).NotTo(HaveOccurred()) |
| 53 | + Expect(fakeUI.Outputs()).To(ContainSubstring(`"Date":`)) |
| 54 | + Expect(fakeUI.Outputs()).To(ContainSubstring(`"Path": "/example/",`)) |
| 55 | + Expect(fakeUI.Outputs()).To(ContainSubstring(`"Saved": "UNSAVED",`)) |
| 56 | + Expect(fakeUI.Outputs()).To(ContainSubstring(`"Status": "SUCCESS"`)) |
| 57 | + Expect(fakeUI.Outputs()).To(ContainSubstring(`[`)) |
| 58 | + Expect(fakeUI.Outputs()).To(ContainSubstring(`{`)) |
| 59 | + Expect(fakeUI.Outputs()).To(ContainSubstring(`}`)) |
| 60 | + Expect(fakeUI.Outputs()).To(ContainSubstring(`]`)) |
| 61 | + }) |
| 62 | + }) |
| 63 | + }) |
| 64 | +}) |
0 commit comments