github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+incompatible/plugin/rpc/call_command_registry_test.go (about) 1 package rpc_test 2 3 import ( 4 "github.com/cloudfoundry/cli/cf/command_registry" 5 . "github.com/cloudfoundry/cli/plugin/rpc" 6 . "github.com/cloudfoundry/cli/plugin/rpc/fake_command" 7 8 . "github.com/cloudfoundry/cli/testhelpers/matchers" 9 testterm "github.com/cloudfoundry/cli/testhelpers/terminal" 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 ) 13 14 var _ = Describe("calling commands in command_registry", func() { 15 16 _ = FakeCommand1{} //make sure fake_command is imported and self-registered with init() 17 18 var ( 19 ui *testterm.FakeUI 20 deps command_registry.Dependency 21 ) 22 23 BeforeEach(func() { 24 deps = command_registry.NewDependency() 25 ui = &testterm.FakeUI{} 26 deps.Ui = ui 27 28 cmd := command_registry.Commands.FindCommand("fake-non-codegangsta-command") 29 command_registry.Commands.SetCommand(cmd.SetDependency(deps, true)) 30 31 cmd2 := command_registry.Commands.FindCommand("fake-non-codegangsta-command2") 32 command_registry.Commands.SetCommand(cmd2.SetDependency(deps, true)) 33 }) 34 35 It("runs the command requirements", func() { 36 NewNonCodegangstaRunner().Command([]string{"fake-non-codegangsta-command"}, deps, false) 37 Expect(ui.Outputs).To(ContainSubstrings([]string{"Requirement executed"})) 38 }) 39 40 It("calls the command Execute() func", func() { 41 NewNonCodegangstaRunner().Command([]string{"fake-non-codegangsta-command"}, deps, false) 42 Expect(ui.Outputs).To(ContainSubstrings([]string{"Command Executed"})) 43 }) 44 45 It("sets the dependency of the command", func() { 46 NewNonCodegangstaRunner().Command([]string{"fake-non-codegangsta-command"}, deps, false) 47 Expect(ui.Outputs).To(ContainSubstrings([]string{"SetDependency() called, pluginCall true"})) 48 }) 49 50 It("returns an error if any of the requirements fail", func() { 51 err := NewNonCodegangstaRunner().Command([]string{"fake-non-codegangsta-command2"}, deps, false) 52 53 Expect(err).To(HaveOccurred()) 54 Expect(err.Error()).To(ContainSubstring("Error in requirement")) 55 }) 56 57 It("returns an error if invalid flag is provided", func() { 58 err := NewNonCodegangstaRunner().Command([]string{"fake-non-codegangsta-command", "-badFlag"}, deps, false) 59 60 Expect(err).To(HaveOccurred()) 61 Expect(err.Error()).To(ContainSubstring("Invalid flag: -badFlag")) 62 }) 63 64 })