| 52 | } |
| 53 | |
| 54 | func TestLog(t *testing.T) { |
| 55 | rurl := mustParse("http://foo.com/?q=x") |
| 56 | uurl := mustParse("http://7.8.9.0:5678/foo?q=x") |
| 57 | start := time.Date(2016, 1, 1, 0, 0, 0, 0, time.UTC) |
| 58 | e := &Event{ |
| 59 | Start: start, |
| 60 | End: start.Add(123456789 * time.Nanosecond), |
| 61 | Request: &http.Request{ |
| 62 | RequestURI: rurl.RequestURI(), |
| 63 | Header: http.Header{ |
| 64 | "User-Agent": {"Mozilla Firefox"}, |
| 65 | "Referer": {"http://foo.com/"}, |
| 66 | "X-Forwarded-For": {"3.3.3.3"}, |
| 67 | }, |
| 68 | RemoteAddr: "2.2.2.2:666", |
| 69 | Host: rurl.Host, |
| 70 | URL: rurl, |
| 71 | Method: "GET", |
| 72 | Proto: "HTTP/1.1", |
| 73 | }, |
| 74 | Response: &http.Response{ |
| 75 | StatusCode: 200, |
| 76 | ContentLength: 1234, |
| 77 | Header: http.Header{"foo": []string{"bar"}}, |
| 78 | Request: &http.Request{ |
| 79 | RemoteAddr: "5.6.7.8:1234", |
| 80 | }, |
| 81 | }, |
| 82 | RequestURL: rurl, |
| 83 | UpstreamAddr: uurl.Host, |
| 84 | UpstreamService: "svc-a", |
| 85 | UpstreamURL: uurl, |
| 86 | } |
| 87 | |
| 88 | tests := []struct { |
| 89 | format string |
| 90 | out string |
| 91 | }{ |
| 92 | {"$header.Referer", "http://foo.com/\n"}, |
| 93 | {"$header.X-Forwarded-For", "3.3.3.3\n"}, |
| 94 | {"$header.user-agent", "Mozilla Firefox\n"}, |
| 95 | {"$remote_addr", "2.2.2.2:666\n"}, |
| 96 | {"$remote_host", "2.2.2.2\n"}, |
| 97 | {"$remote_port", "666\n"}, |
| 98 | {"$request", "GET /?q=x HTTP/1.1\n"}, |
| 99 | {"$request_args", "q=x\n"}, |
| 100 | {"$request_host", "foo.com\n"}, // TODO(fs): is this correct? |
| 101 | {"$request_method", "GET\n"}, |
| 102 | {"$request_proto", "HTTP/1.1\n"}, |
| 103 | {"$request_scheme", "http\n"}, |
| 104 | {"$request_uri", "/?q=x\n"}, |
| 105 | {"$request_url", "http://foo.com/?q=x\n"}, |
| 106 | {"$response_body_size", "1234\n"}, |
| 107 | {"$response_status", "200\n"}, |
| 108 | {"$response_time_ms", "0.123\n"}, // TODO(fs): is this correct? |
| 109 | {"$response_time_ns", "0.123456789\n"}, // TODO(fs): is this correct? |
| 110 | {"$response_time_us", "0.123456\n"}, // TODO(fs): is this correct? |
| 111 | {"$time_common", "01/Jan/2016:00:00:00 +0000\n"}, |