accessLogger := NewFileAndLoggregatorAccessLogger(logger, "", fakeAccessFile, os.Stdout)

			go accessLogger.Run()
			accessLogger.Log(*CreateAccessLogRecord())

			os.Stdout = oldStdout
			var stdoutPayload []byte
			Eventually(func() int {
				stdoutPayload, _ = ioutil.ReadFile(fname)
				return len(stdoutPayload)
			}).ShouldNot(Equal(0))
			Expect(string(stdoutPayload)).To(MatchRegexp("^.*foo.bar.*\n"))

			var payload []byte
			Eventually(func() int {
				n, _ := fakeAccessFile.Read(&payload)
				return n
			}).ShouldNot(Equal(0))
			Expect(string(payload)).To(MatchRegexp("^.*foo.bar.*\n"))

			accessLogger.Stop()
		})
	})

	Measure("Log write speed", func(b Benchmarker) {
		w := nullWriter{}

		b.Time("writeTime", func() {
			for i := 0; i < 500; i++ {
				r := CreateAccessLogRecord()
				r.WriteTo(w)
			accessLogger.Stop()
		})

	})

	Context("with a file", func() {
		It("writes to the log file", func() {
			var fakeFile = new(test_util.FakeFile)

			accessLogger := NewFileAndLoggregatorAccessLogger(fakeFile, nil)
			go accessLogger.Run()
			accessLogger.Log(*CreateAccessLogRecord())

			var payload []byte
			Eventually(func() int {
				n, _ := fakeFile.Read(&payload)
				return n
			}).ShouldNot(Equal(0))
			Ω(string(payload)).To(MatchRegexp("^.*foo.bar.*\n"))

			accessLogger.Stop()
		})
	})

	Context("with valid hostnames", func() {
		It("creates an emitter", func() {
			e, err := NewEmitter("localhost:9843", "secret", 42)
			Ω(err).ToNot(HaveOccurred())
			Ω(e).ToNot(BeNil())

			e, err = NewEmitter("10.10.16.14:9843", "secret", 42)
Esempio n. 3
0
		})
		defer ln.Close()

		x := dialProxy(proxyServer)

		x.WriteLines([]string{
			"GET / HTTP/1.0",
			"Host: test",
		})

		x.CheckLine("HTTP/1.0 200 OK")

		var payload []byte
		Eventually(func() int {
			accessLogFile.Read(&payload)
			return len(payload)
		}).ShouldNot(BeZero())
		Ω(string(payload)).To(MatchRegexp("^test.*\n"))
		//make sure the record includes all the data
		//since the building of the log record happens throughout the life of the request
		Ω(string(payload)).To(MatchRegexp(".*200.*\n"))
	})

	It("Logs a request when it exits early", func() {
		x := dialProxy(proxyServer)

		x.WriteLines([]string{
			"GET / HTTP/0.9",
			"Host: test",
		})