(t *testing.T)
| 54 | } |
| 55 | |
| 56 | func TestConditional(t *testing.T) { |
| 57 | a := assertions.New(t) |
| 58 | |
| 59 | flag := false |
| 60 | middleware := Conditional( |
| 61 | func(next http.Handler) http.Handler { |
| 62 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 63 | flag = true |
| 64 | next.ServeHTTP(w, r) |
| 65 | }) |
| 66 | }, |
| 67 | func(r *http.Request) bool { |
| 68 | return r.Header.Get("X-Condition") == "foo" |
| 69 | }, |
| 70 | ) |
| 71 | r := httptest.NewRequest(http.MethodGet, "/", nil) |
| 72 | r.Header.Set("X-Condition", "bar") |
| 73 | rec := httptest.NewRecorder() |
| 74 | middleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 75 | a.So(flag, should.Equal, false) |
| 76 | })).ServeHTTP(rec, r) |
| 77 | |
| 78 | r = httptest.NewRequest(http.MethodGet, "/", nil) |
| 79 | r.Header.Set("X-Condition", "foo") |
| 80 | rec = httptest.NewRecorder() |
| 81 | middleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 82 | a.So(flag, should.Equal, true) |
| 83 | })).ServeHTTP(rec, r) |
| 84 | } |
nothing calls this directly
no test coverage detected