(t *testing.T)
| 77 | } |
| 78 | |
| 79 | func TestLog(t *testing.T) { |
| 80 | a := assertions.New(t) |
| 81 | ch := make(logEntryChannel, 10) |
| 82 | m := Log(&log.Logger{ |
| 83 | Handler: ch, |
| 84 | }, []string{"/path", "/ignorepath"}) |
| 85 | |
| 86 | for _, tc := range []struct { |
| 87 | name string |
| 88 | path string |
| 89 | setReq func(r *http.Request) |
| 90 | validate func(t *testing.T) |
| 91 | handler func(w http.ResponseWriter, r *http.Request) |
| 92 | }{ |
| 93 | { |
| 94 | name: "NormalSuccess", |
| 95 | handler: func(w http.ResponseWriter, r *http.Request) { |
| 96 | w.WriteHeader(http.StatusOK) |
| 97 | }, |
| 98 | path: "/", |
| 99 | validate: func(t *testing.T) { |
| 100 | ch.Expect(t, func(t *testing.T, e log.Entry) { |
| 101 | verifySuccess(t, e) |
| 102 | assertions.New(t).So(e.Fields().Fields()["peer.address"], should.Equal, "192.0.2.1:1234") |
| 103 | }) |
| 104 | }, |
| 105 | }, |
| 106 | { |
| 107 | name: "RealIP", |
| 108 | setReq: func(r *http.Request) { |
| 109 | r.Header.Set("X-Real-Ip", "12.34.56.78") |
| 110 | }, |
| 111 | handler: func(w http.ResponseWriter, r *http.Request) { |
| 112 | w.WriteHeader(http.StatusOK) |
| 113 | }, |
| 114 | path: "/", |
| 115 | validate: func(t *testing.T) { |
| 116 | ch.Expect(t, func(t *testing.T, e log.Entry) { |
| 117 | verifySuccess(t, e) |
| 118 | assertions.New(t).So(e.Fields().Fields()["peer.real_ip"], should.Equal, "12.34.56.78") |
| 119 | }) |
| 120 | }, |
| 121 | }, |
| 122 | { |
| 123 | name: "IgnoreSuccess", |
| 124 | handler: func(w http.ResponseWriter, r *http.Request) { |
| 125 | w.WriteHeader(http.StatusOK) |
| 126 | }, |
| 127 | path: "/path", |
| 128 | validate: ch.ExpectNoLog, |
| 129 | }, |
| 130 | { |
| 131 | name: "IgnoreSuccess", |
| 132 | handler: func(w http.ResponseWriter, r *http.Request) { |
| 133 | w.WriteHeader(http.StatusOK) |
| 134 | }, |
| 135 | path: "/ignorepath", |
| 136 | validate: ch.ExpectNoLog, |
nothing calls this directly
no test coverage detected