コード例 #1
0
ファイル: main.go プロジェクト: markstgodard/routing-api-cli
func main() {
	fmt.Println()
	app := cli.NewApp()
	app.Name = "rtr"
	app.Usage = "A CLI for the Router API server."
	authors := []cli.Author{cli.Author{Name: "Cloud Foundry Routing Team", Email: "*****@*****.**"}}
	app.Authors = authors
	app.Commands = cliCommands
	app.CommandNotFound = commandNotFound
	app.Version = "2.1.0"

	cli.AppHelpTemplate = cli.AppHelpTemplate + environmentVariableHelp + "\n"

	trace.NewLogger(os.Getenv(RTR_TRACE))

	app.Run(os.Args)
	os.Exit(0)
}
コード例 #2
0
ファイル: token_fetcher_test.go プロジェクト: krumts/gorouter
					verifyBody("grant_type=client_credentials"),
					ghttp.RespondWithJSONEncoded(http.StatusOK, responseBody),
				))

			fetcher := NewTokenFetcher(cfg)
			token, err := fetcher.FetchToken()
			Expect(err).NotTo(HaveOccurred())
			Expect(server.ReceivedRequests()).Should(HaveLen(1))
			Expect(token.AccessToken).To(Equal("the token"))
			Expect(token.ExpireTime).To(Equal(20))
		})

		It("logs requests and responses", func() {
			stdout := bytes.NewBuffer([]byte{})
			trace.SetStdout(stdout)
			trace.NewLogger("true")

			server.AppendHandlers(
				ghttp.RespondWith(http.StatusBadRequest, "you messed up"),
			)

			fetcher := NewTokenFetcher(cfg)
			_, err := fetcher.FetchToken()
			Expect(err).To(HaveOccurred())

			r, err := ioutil.ReadAll(stdout)
			log := string(r)
			Expect(err).NotTo(HaveOccurred())
			Expect(log).To(ContainSubstring("REQUEST: "))
			Expect(log).To(ContainSubstring("POST /oauth/token HTTP/1.1"))
コード例 #3
0
		})

		Describe("Next", func() {
			Context("When the event source returns an error", func() {
				It("returns the error", func() {
					fakeRawEventSource.NextReturns(sse.Event{}, errors.New("boom"))
					_, err := eventSource.Next()
					Expect(err.Error()).To(Equal("boom"))
				})
			})

			Context("When the event source successfully returns an event", func() {
				It("logs the event", func() {
					stdout := bytes.NewBuffer([]byte{})
					trace.SetStdout(stdout)
					trace.Logger = trace.NewLogger("true")
					rawEvent := sse.Event{
						ID:    "1",
						Name:  "Test",
						Data:  []byte(`{"route":"jim.com","port":8080,"ip":"1.1.1.1","ttl":60,"log_guid":"logs"}`),
						Retry: 1,
					}
					expectedJSON, _ := json.Marshal(rawEvent)

					fakeRawEventSource.NextReturns(rawEvent, nil)
					eventSource.Next()

					log, err := ioutil.ReadAll(stdout)
					Expect(err).NotTo(HaveOccurred())
					Expect(log).To(ContainSubstring("EVENT: "))
					Expect(log).To(ContainSubstring(string(expectedJSON)))