예제 #1
0
	. "github.com/onsi/gomega"
)

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

		BeforeEach(func() {
			fakeCliConnection = &pluginfakes.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"))
예제 #2
0
		fakeCliConnection.CliCommandWithoutTerminalOutputStub = func(args ...string) ([]string, error) {
			if reflect.DeepEqual(args, []string{"curl", "/v3/apps?names=my-app"}) {
				return []string{searchResult}, searchError
			} else if reflect.DeepEqual(args, []string{"curl", "/v3/apps?names=my+app"}) {
				return []string{searchResultWithSpace}, searchError
			} else if reflect.DeepEqual(args, []string{"curl", "/v3/apps/feed-dead-beef", "-X", "DELETE"}) {
				return []string{deleteResult}, deleteError
			} else if reflect.DeepEqual(args, []string{"curl", "/v3/apps/feed-dead-beef-with-space", "-X", "DELETE"}) {
				return []string{deleteResult}, deleteError
			}
			return []string{""}, nil
		}
	})

	It("deletes the app", func() {
		output := io_helpers.CaptureOutput(func() { Delete(fakeCliConnection, args) })
		Expect(fakeCliConnection.CliCommandWithoutTerminalOutputArgsForCall(1)).
			To(Equal([]string{"curl", "/v3/apps/feed-dead-beef", "-X", "DELETE"}))

		Expect(output[0]).To(Equal("Deleting app my-app..."))
		Expect(output[1]).To(Equal("OK"))
	})

	Context("When the app name has a space", func() {
		It("deletes the app", func() {
			commandArgsWithSpace := []string{"v3-delete", "my app"}

			output := io_helpers.CaptureOutput(func() { Delete(fakeCliConnection, commandArgsWithSpace) })
			Expect(fakeCliConnection.CliCommandWithoutTerminalOutputArgsForCall(1)).
				To(Equal([]string{"curl", "/v3/apps/feed-dead-beef-with-space", "-X", "DELETE"}))
예제 #3
0
파일: ui_test.go 프로젝트: fujitsu-cf/cli
var _ = Describe("UI", func() {
	var fakeLogger *tracefakes.FakePrinter
	BeforeEach(func() {
		fakeLogger = new(tracefakes.FakePrinter)
	})

	Describe("Printing message to stdout with PrintCapturingNoOutput", func() {
		It("prints strings without using the TeePrinter", func() {
			bucket := gbytes.NewBuffer()

			printer := NewTeePrinter(os.Stdout)
			printer.SetOutputBucket(bucket)

			io_helpers.SimulateStdin("", func(reader io.Reader) {
				output := io_helpers.CaptureOutput(func() {
					ui := NewUI(reader, os.Stdout, printer, fakeLogger)
					ui.PrintCapturingNoOutput("Hello")
				})

				Expect("Hello").To(Equal(strings.Join(output, "")))
				Expect(bucket.Contents()).To(HaveLen(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, os.Stdout, NewTeePrinter(os.Stdout), fakeLogger)
					ui.Say("Hello")
				})
예제 #4
0
파일: help_test.go 프로젝트: fujitsu-cf/cli
		Expect(buffer.Contents()).To(ContainSubstring("test2_cmd2"))
		Expect(buffer.Contents()).To(ContainSubstring("test2_really_long_really_long_really_long_command_name"))
	})

	It("adjusts the output format to the longest length of plugin command name", func() {
		confighelpers.PluginRepoDir = func() string {
			return filepath.Join("..", "..", "fixtures", "config", "help-plugin-test-config")
		}

		dummyTemplate := `
{{range .Commands}}{{range .CommandSubGroups}}{{range .}}
{{.Name}}%%%{{.Description}}
{{end}}{{end}}{{end}}
`
		output := io.CaptureOutput(func() {
			help.ShowHelp(os.Stdout, dummyTemplate)
		})

		cmdNameLen := len(strings.Split(output[2], "%%%")[0])

		for _, line := range output {
			if strings.TrimSpace(line) == "" {
				continue
			}

			expectedLen := len(strings.Split(line, "%%%")[0])
			Expect(cmdNameLen).To(Equal(expectedLen))
		}

	})
예제 #5
0
var _ = Describe("TeePrinter", func() {
	var (
		output  []string
		printer *TeePrinter
	)

	Describe(".Print", func() {
		var bucket *gbytes.Buffer

		BeforeEach(func() {
			bucket = gbytes.NewBuffer()

			output = io_helpers.CaptureOutput(func() {
				printer = NewTeePrinter(os.Stdout)
				printer.SetOutputBucket(bucket)
				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() {
			Expect(bucket).To(gbytes.Say("Hello "))
			Expect(bucket).To(gbytes.Say("Mom!"))
		})

		It("should decolorize text", func() {
			io_helpers.CaptureOutput(func() {