standardErrorPriority := 14

		BeforeEach(func() {
			requestChan = make(chan []byte, 1)
			server = ServeHTTP(requestChan)
		})

		AfterEach(func() {
			server.Close()
			http.DefaultServeMux = http.NewServeMux()
		})

		It("HTTP POSTs each log message to the HTTPS syslog endpoint", func() {
			outputUrl, _ := url.Parse(server.URL + "/234-bxg-234/")

			w, _ := syslogwriter.NewHttpsWriter(outputUrl, "appId", true)
			err := w.Connect()
			Expect(err).ToNot(HaveOccurred())

			parsedTime, err := time.Parse(time.RFC3339, "2006-01-02T15:04:05Z")
			byteCount, err := w.Write(standardErrorPriority, []byte("Message"), "just a test", "TEST", parsedTime.UnixNano())
			Expect(byteCount).To(Equal(76))
			Expect(err).ToNot(HaveOccurred())

			Eventually(func() string {
				return string(<-requestChan)
			}).Should(ContainSubstring("loggregator appId [just a test] - - Message"))
		})

		It("returns an error when unable to HTTP POST the log message", func() {
			outputUrl, _ := url.Parse("https://")
Beispiel #2
0
		JustBeforeEach(func() {
			requestChan = make(chan []byte, queuedRequests)
			serveMux.HandleFunc("/234-bxg-234/", syslogHandler(requestChan))
			server.Listener = listener
			server.StartTLS()
		})

		AfterEach(func() {
			server.Close()
		})

		It("HTTP POSTs each log message to the HTTPS syslog endpoint", func() {
			outputUrl, _ := url.Parse(server.URL + "/234-bxg-234/")

			w, _ := syslogwriter.NewHttpsWriter(outputUrl, "appId", true, dialer, timeout)
			err := w.Connect()
			Expect(err).ToNot(HaveOccurred())

			parsedTime, err := time.Parse(time.RFC3339, "2006-01-02T15:04:05Z")
			byteCount, err := w.Write(standardErrorPriority, []byte("Message"), "just a test", "TEST", parsedTime.UnixNano())
			Expect(byteCount).To(Equal(76))
			Expect(err).ToNot(HaveOccurred())

			Eventually(func() string {
				return string(<-requestChan)
			}).Should(ContainSubstring("loggregator appId [just a test] - - Message"))
		})

		It("returns an error when unable to HTTP POST the log message", func() {
			outputUrl, _ := url.Parse("https://")
	Describe("Exponentially backs off", func() {
		It("for https writer", func() {
			bufferSize = 6
			appId := "appId"
			var timestampsInMillis []int64
			var requests int64

			server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
				w.WriteHeader(400)
				timestampsInMillis = append(timestampsInMillis, time.Now().UnixNano()/1e6)
				atomic.AddInt64(&requests, 1)
			}))
			url, _ := url.Parse(server.URL)

			httpsWriter, err := syslogwriter.NewHttpsWriter(url, appId, true)
			Expect(err).ToNot(HaveOccurred())

			errorHandler := func(string, string, string) {}
			syslogSink = syslog.NewSyslogSink(appId, server.URL, loggertesthelper.Logger(), bufferSize, httpsWriter, errorHandler, "dropsonde-origin")
			go syslogSink.Run(inputChan)

			for i := 0; i < int(bufferSize); i++ {
				msg := fmt.Sprintf("message number %v", i)
				logMessage, _ := emitter.Wrap(factories.NewLogMessage(events.LogMessage_OUT, msg, appId, "App"), "origin")

				inputChan <- logMessage
			}
			close(inputChan)

			Eventually(func() int64 {