コード例 #1
0
ファイル: weblogs_test.go プロジェクト: keep94/weblogs
func TestSupportHijack(t *testing.T) {
	// test that loggers.Capture supports hijacking
	buf := &bytes.Buffer{}
	clock := &clock{Time: kTime}
	handler := weblogs.HandlerWithOptions(
		&handler{Clock: clock, Hijack: true},
		&weblogs.Options{
			Writer: buf,
			Logger: weblogs.ApacheCommonLogger(),
			Now:    clock.Now()})
	handler.ServeHTTP(
		kNilResponseWriter,
		newRequest("192.168.101.103:4444", "GET", "/bar/baz?query=short"))
	expected := "192.168.101.103 - - [23/Mar/2013:13:14:15 +0000] \"GET /bar/baz?query=short HTTP/1.0\" 0 0\n"
	verifyLogs(t, expected, buf.String())
}
コード例 #2
0
ファイル: weblogs_test.go プロジェクト: keep94/weblogs
func TestLogStatus200(t *testing.T) {
	buf := &bytes.Buffer{}
	clock := &clock{Time: kTime}
	handler := weblogs.HandlerWithOptions(
		&handler{Message: "1234567"},
		&weblogs.Options{
			Writer: buf,
			Logger: weblogs.ApacheCommonLogger(),
			Now:    clock.Now()})
	request := newRequest("192.168.5.1:3333", "GET", "/foo/bar?query=tall")
	request.URL.User = url.User("fred")
	handler.ServeHTTP(
		kNilResponseWriter,
		request)
	expected := "192.168.5.1 - fred [23/Mar/2013:13:14:15 +0000] \"GET /foo/bar?query=tall HTTP/1.0\" 200 7\n"
	verifyLogs(t, expected, buf.String())
}