コード例 #1
0
ファイル: main.go プロジェクト: cloudfoundry/firehose-plugin
func (c *NozzlerCmd) Run(cliConnection plugin.CliConnection, args []string) {
	var options *firehose.ClientOptions

	traceLogger := trace.NewLogger(os.Stdout, true, os.Getenv("CF_TRACE"), "")
	c.ui = terminal.NewUI(os.Stdin, os.Stdout, terminal.NewTeePrinter(os.Stdout), traceLogger)

	switch args[0] {
	case "nozzle":
		options = c.buildClientOptions(args)
	case "app-nozzle":
		options = c.buildClientOptions(args)
		appModel, err := cliConnection.GetApp(args[1])
		if err != nil {
			c.ui.Warn(err.Error())
			return
		}

		options.AppGUID = appModel.Guid
	default:
		return
	}

	dopplerEndpoint, err := cliConnection.DopplerEndpoint()
	if err != nil {
		c.ui.Failed(err.Error())
	}

	authToken, err := cliConnection.AccessToken()
	if err != nil {
		c.ui.Failed(err.Error())
	}

	client := firehose.NewClient(authToken, dopplerEndpoint, options, c.ui)
	client.Start()
}
コード例 #2
0
	BeforeEach(func() {
		stdin = &syncedBuffer{}
		stdout = &syncedBuffer{}

		printer = new(fakes.FakePrinter)
		printer.PrintfStub = func(format string, a ...interface{}) (n int, err error) {
			return fmt.Fprintf(stdout, format, a...)
		}
		tracePrinter = new(tracefakes.FakePrinter)

		ui = terminal.NewUI(stdin, stdout, printer, tracePrinter)
	})

	Describe("Start", func() {
		var options *firehose.ClientOptions
		Context("for app connections", func() {
			BeforeEach(func() {
				options = &firehose.ClientOptions{AppGUID: "spring-music", Debug: false, NoFilter: true}
			})
			Context("when the connection to doppler cannot be established", func() {
				It("shows a meaningful error", func() {
					client := firehose.NewClient("invalidToken", "badEndpoint", options, ui)
					client.Start()
					Expect(stdout).To(ContainSubstring("Error dialing trafficcontroller server"))
				})
			})
			Context("when the connection to doppler works", func() {
				var fakeFirehose *testhelpers.FakeFirehose
				BeforeEach(func() {
					fakeFirehose = testhelpers.NewFakeFirehoseInAppMode("ACCESS_TOKEN", "spring-music")