コード例 #1
0
		var answer string
		Eventually(done).Should(Receive(&answer))
		Expect(answer).To(Equal("https"))

		conn.ReadResponse()
	})

	It("emits HTTP startstop events", func() {
		ln := registerHandlerWithInstanceId(r, "app", "", func(conn *test_util.HttpConn) {
		}, "fake-instance-id")
		defer ln.Close()

		conn := dialProxy(proxyServer)

		fakeEmitter := fake.NewFakeEventEmitter("fake")
		dropsonde.InitializeWithEmitter(fakeEmitter)

		req := test_util.NewRequest("GET", "app", "/", nil)
		requestId, err := uuid.NewV4()
		Expect(err).NotTo(HaveOccurred())
		req.Header.Set("X-Vcap-Request-Id", requestId.String())
		conn.WriteRequest(req)

		findStartStopEvent := func() *events.HttpStartStop {
			for _, event := range fakeEmitter.GetEvents() {
				startStopEvent, ok := event.(*events.HttpStartStop)
				if ok {
					return startStopEvent
				}
			}
コード例 #2
0
import (
	"net/http"
	"reflect"

	"github.com/cloudfoundry/dropsonde"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

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

	Describe("Initialize", func() {
		It("resets the HTTP default transport to be instrumented", func() {
			dropsonde.InitializeWithEmitter(&dropsonde.NullEventEmitter{})
			Expect(reflect.TypeOf(http.DefaultTransport).Elem().Name()).To(Equal("instrumentedCancelableRoundTripper"))
		})
	})

	Describe("CreateDefaultEmitter", func() {
		Context("with origin missing", func() {
			It("returns a NullEventEmitter", func() {
				err := dropsonde.Initialize("localhost:2343", "")
				Expect(err).To(HaveOccurred())

				emitter := dropsonde.AutowiredEmitter()
				Expect(emitter).ToNot(BeNil())
				nullEmitter := &dropsonde.NullEventEmitter{}
				Expect(emitter).To(BeAssignableToTypeOf(nullEmitter))
			})