Example #1
0
	io_helpers "github.com/nttlabs/cli/testhelpers/io"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("TeePrinter", func() {
	var (
		output  []string
		printer *TeePrinter
	)

	Describe(".Print", func() {
		BeforeEach(func() {
			output = io_helpers.CaptureOutput(func() {
				printer = NewTeePrinter()
				printer.Print("Hello ")
				printer.Print("Mom!")
			})
		})

		It("should delegate to fmt.Print", func() {
			Expect(output[0]).To(Equal("Hello Mom!"))
		})

		It("should save the output to the slice", func() {
			outputs := printer.GetOutputAndReset()
			Expect(outputs[0]).To(Equal("Hello "))
			Expect(outputs[1]).To(Equal("Mom!"))
		})

		It("should decolorize text", func() {
Example #2
0
	. "github.com/onsi/gomega"
)

var _ = Describe("CallCliCmd", func() {
	Describe(".Run", func() {
		var fakeCliConnection *fakes.FakeCliConnection
		var callCliCommandPlugin *CliCmd

		BeforeEach(func() {
			fakeCliConnection = &fakes.FakeCliConnection{}
			callCliCommandPlugin = &CliCmd{}
		})

		It("calls the cli command that is passed as an argument", func() {
			io_helpers.CaptureOutput(func() {
				callCliCommandPlugin.Run(fakeCliConnection, []string{"cli-command", "plugins", "arg1"})
			})

			Expect(fakeCliConnection.CliCommandArgsForCall(0)[0]).To(Equal("plugins"))
			Expect(fakeCliConnection.CliCommandArgsForCall(0)[1]).To(Equal("arg1"))
		})

		It("ouputs the text returned by the cli command", func() {
			fakeCliConnection.CliCommandReturns([]string{"Hi", "Mom"}, nil)
			output := io_helpers.CaptureOutput(func() {
				callCliCommandPlugin.Run(fakeCliConnection, []string{"cli-command", "plugins", "arg1"})
			})

			Expect(output[1]).To(Equal("---------- Command output from the plugin ----------"))
			Expect(output[2]).To(Equal("# 0  value:  Hi"))
			Expect(output[3]).To(Equal("# 1  value:  Mom"))
Example #3
0
	io_helpers "github.com/nttlabs/cli/testhelpers/io"

	. "github.com/nttlabs/cli/cf/terminal"
	. "github.com/nttlabs/cli/testhelpers/matchers"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("UI", func() {

	Describe("Printing message to stdout with PrintCapturingNoOutput", func() {
		It("prints strings without using the TeePrinter", func() {
			printer := NewTeePrinter()
			io_helpers.SimulateStdin("", func(reader io.Reader) {
				output := io_helpers.CaptureOutput(func() {
					ui := NewUI(reader, printer)
					ui.PrintCapturingNoOutput("Hello")
				})

				Expect("Hello").To(Equal(strings.Join(output, "")))
				Expect(len(printer.GetOutputAndReset())).To(Equal(0))
			})
		})
	})

	Describe("Printing message to stdout with Say", func() {
		It("prints strings", func() {
			io_helpers.SimulateStdin("", func(reader io.Reader) {
				output := io_helpers.CaptureOutput(func() {
					ui := NewUI(reader, NewTeePrinter())
					ui.Say("Hello")
				})
Example #4
0
	testterm "github.com/nttlabs/cli/testhelpers/terminal"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Help", func() {
	It("shows help for all commands", func() {
		commandFactory := createCommandFactory()

		dummyTemplate := `
{{range .Commands}}{{range .CommandSubGroups}}{{range .}}
{{.Name}}
{{end}}{{end}}{{end}}
`
		output := io_helpers.CaptureOutput(func() {
			app.ShowHelp(dummyTemplate, createApp(commandFactory))
		})

		for _, metadata := range commandFactory.CommandMetadatas() {
			Expect(commandInOutput(metadata.Name, output)).To(BeTrue(), metadata.Name+" not in help")
		}
	})

	It("shows help for all installed plugin's commands", func() {
		config_helpers.PluginRepoDir = func() string {
			return filepath.Join("..", "..", "fixtures", "config", "help-plugin-test-config")
		}

		commandFactory := createCommandFactory()

		dummyTemplate := `
Example #5
0
	})

	Context("when given a command name to run", func() {
		It("runs the command with that name", func() {
			for _, cmdName := range expectedCommandNames {
				app.Run([]string{"", cmdName})
				Expect(cmdRunner.cmdName).To(Equal(cmdName))
			}
		})
	})

	Context("when running 'cf --help'", func() {
		It("should output the help in our custom format", func() {

			output := io_helpers.CaptureOutput(func() {
				app.Run([]string{"", "--help"})
			})

			mergedOutput := strings.Join(output, "\n")
			Expect(mergedOutput).To(ContainSubstring("CF_TRACE=true"), "CF_TRACE=true not in help")
			Expect(mergedOutput).To(ContainSubstring("CF_PLUGIN_HOME=path/to/dir/"))

			for _, name := range expectedCommandNames {
				Expect(mergedOutput).To(ContainSubstring(name), name+" not in help")
			}
		})
	})

	Context("when the user provides an unknown command name", func() {
		It("should complain loudly and then panic", func() {
			Expect(func() {
Example #6
0
				outputCapture := &fakes.FakeOutputCapture{}
				rpcService, err = NewRpcService(app, outputCapture, nil)
				Expect(err).ToNot(HaveOccurred())

				err := rpcService.Start()
				Expect(err).ToNot(HaveOccurred())

				pingCli(rpcService.Port())
			})

			It("returns false in success if the command cannot be found", func() {
				io_helpers.CaptureOutput(func() {
					client, err = rpc.Dial("tcp", "127.0.0.1:"+rpcService.Port())
					Expect(err).ToNot(HaveOccurred())

					var success bool
					err = client.Call("CliRpcCmd.CallCoreCommand", []string{"not_a_cmd"}, &success)
					Expect(success).To(BeFalse())
					Expect(err).ToNot(HaveOccurred())
				})
			})

			It("returns an error if a command cannot parse provided flags", func() {
				io_helpers.CaptureOutput(func() {
					client, err = rpc.Dial("tcp", "127.0.0.1:"+rpcService.Port())
					Expect(err).ToNot(HaveOccurred())

					var success bool
					err = client.Call("CliRpcCmd.CallCoreCommand", []string{"test_cmd", "-invalid_flag"}, &success)

					Expect(err).To(HaveOccurred())