}
	})

	Describe("SetOnConnectCallback", func() {
		BeforeEach(func() {
			testServer = httptest.NewServer(handlers.NewWebsocketHandler(messagesToSend, 100*time.Millisecond, loggertesthelper.Logger()))
			trafficControllerUrl = "ws://" + testServer.Listener.Addr().String()
			close(messagesToSend)
		})

		It("sets a callback and calls it when connecting", func() {
			called := false
			cb := func() { called = true }

			connection = noaa.NewConsumer(trafficControllerUrl, tlsSettings, nil)
			connection.SetOnConnectCallback(cb)

			logChan := make(chan *events.LogMessage, 100)
			connection.TailingLogsWithoutReconnect(appGuid, authToken, logChan)

			Eventually(func() bool { return called }).Should(BeTrue())
		})

		Context("when the connection fails", func() {
			It("does not call the callback", func() {
				trafficControllerUrl = "!!!bad-url"

				called := false
				cb := func() { called = true }

				connection = noaa.NewConsumer(trafficControllerUrl, tlsSettings, nil)
Exemple #2
0
		}
	})

	Describe("SetOnConnectCallback", func() {
		BeforeEach(func() {
			testServer = httptest.NewServer(handlers.NewWebsocketHandler(messagesToSend, 100*time.Millisecond, loggertesthelper.Logger()))
			trafficControllerUrl = "ws://" + testServer.Listener.Addr().String()
			close(messagesToSend)
		})

		It("sets a callback and calls it when connecting", func() {
			called := false
			cb := func() { called = true }

			cnsmr = noaa.NewConsumer(trafficControllerUrl, tlsSettings, nil)
			cnsmr.SetOnConnectCallback(cb)

			logChan := make(chan *events.LogMessage, 100)
			cnsmr.TailingLogsWithoutReconnect(appGuid, authToken, logChan)

			Eventually(func() bool { return called }).Should(BeTrue())
		})

		Context("when the connection fails", func() {
			It("does not call the callback", func() {
				trafficControllerUrl = "!!!bad-url"

				called := false
				cb := func() { called = true }

				cnsmr = noaa.NewConsumer(trafficControllerUrl, tlsSettings, nil)