Пример #1
0
		req = test_util.NewRequest("GET", "example.com", "/", nil)
		resp = httptest.NewRecorder()
		nextCalled = false
	})

	AfterEach(func() {
		Expect(nextCalled).To(BeTrue(), "Expected the next handler to be called.")
	})

	Context("with Zipkin enabled", func() {
		BeforeEach(func() {
			handler = handlers.NewZipkin(true, headersToLog, logger)
		})

		It("sets zipkin headers", func() {
			handler.ServeHTTP(resp, req, nextHandler)
			Expect(req.Header.Get(router_http.B3SpanIdHeader)).ToNot(BeEmpty())
			Expect(req.Header.Get(router_http.B3TraceIdHeader)).ToNot(BeEmpty())
			Expect(req.Header.Get(router_http.B3ParentSpanIdHeader)).To(BeEmpty())
		})

		It("adds zipkin headers to access log record", func() {
			handler.ServeHTTP(resp, req, nextHandler)
			Expect(*headersToLog).To(ContainElement(router_http.B3SpanIdHeader))
			Expect(*headersToLog).To(ContainElement(router_http.B3TraceIdHeader))
			Expect(*headersToLog).To(ContainElement(router_http.B3ParentSpanIdHeader))
		})

		Context("with B3TraceIdHeader and B3SpanIdHeader already set", func() {
			BeforeEach(func() {
				req.Header.Set(router_http.B3TraceIdHeader, "Bogus Value")
Пример #2
0
		extraHeadersToLog = []string{}

		accessLogger = &fakes.FakeAccessLogger{}

		handler = handlers.NewAccessLog(accessLogger, &extraHeadersToLog)

		nextCalled = false
	})

	AfterEach(func() {
		Expect(nextCalled).To(BeTrue(), "Expected the next handler to be called.")
	})

	It("sets an access log record on the context", func() {
		handler.ServeHTTP(proxyWriter, req, nextHandler)
		alr := proxyWriter.Context().Value("AccessLogRecord")
		Expect(alr).ToNot(BeNil())
		Expect(alr).To(BeAssignableToTypeOf(&schema.AccessLogRecord{}))
	})

	It("logs the access log record after all subsequent handlers have run", func() {
		handler.ServeHTTP(proxyWriter, req, nextHandler)

		Expect(accessLogger.LogCallCount()).To(Equal(1))

		alr := accessLogger.LogArgsForCall(0)

		Expect(alr.StartedAt).ToNot(BeZero())
		Expect(alr.Request).To(Equal(req))
		Expect(*alr.ExtraHeadersToLog).To(Equal(extraHeadersToLog))