github.com/jasonkeene/cli@v6.14.1-0.20160816203908-ca5715166dfb+incompatible/plugin_examples/call_cli_cmd/main/call_cli_cmd_test.go (about) 1 package main_test 2 3 import ( 4 "github.com/cloudfoundry/cli/plugin/pluginfakes" 5 . "github.com/cloudfoundry/cli/plugin_examples/call_cli_cmd/main" 6 io_helpers "github.com/cloudfoundry/cli/testhelpers/io" 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 ) 10 11 var _ = Describe("CallCliCmd", func() { 12 Describe(".Run", func() { 13 var fakeCliConnection *pluginfakes.FakeCliConnection 14 var callCliCommandPlugin *CliCmd 15 16 BeforeEach(func() { 17 fakeCliConnection = &pluginfakes.FakeCliConnection{} 18 callCliCommandPlugin = &CliCmd{} 19 }) 20 21 It("calls the cli command that is passed as an argument", func() { 22 io_helpers.CaptureOutput(func() { 23 callCliCommandPlugin.Run(fakeCliConnection, []string{"cli-command", "plugins", "arg1"}) 24 }) 25 26 Expect(fakeCliConnection.CliCommandArgsForCall(0)[0]).To(Equal("plugins")) 27 Expect(fakeCliConnection.CliCommandArgsForCall(0)[1]).To(Equal("arg1")) 28 }) 29 30 It("ouputs the text returned by the cli command", func() { 31 fakeCliConnection.CliCommandReturns([]string{"Hi", "Mom"}, nil) 32 output := io_helpers.CaptureOutput(func() { 33 callCliCommandPlugin.Run(fakeCliConnection, []string{"cli-command", "plugins", "arg1"}) 34 }) 35 36 Expect(output[1]).To(Equal("---------- Command output from the plugin ----------")) 37 Expect(output[2]).To(Equal("# 0 value: Hi")) 38 Expect(output[3]).To(Equal("# 1 value: Mom")) 39 Expect(output[4]).To(Equal("---------- FIN -----------")) 40 }) 41 }) 42 })