mirror of
https://github.com/coredns/coredns.git
synced 2025-09-20 21:21:30 +02:00
Rename the old Context to State and use context.Context in the middleware for intra-middleware communication and more.
42 lines
781 B
Go
42 lines
781 B
Go
package log
|
|
|
|
/*
|
|
type erroringMiddleware struct{}
|
|
|
|
func (erroringMiddleware) ServeDNS(w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
|
return http.StatusNotFound, nil
|
|
}
|
|
|
|
func TestLoggedStatus(t *testing.T) {
|
|
var f bytes.Buffer
|
|
var next erroringMiddleware
|
|
rule := Rule{
|
|
PathScope: "/",
|
|
Format: DefaultLogFormat,
|
|
Log: log.New(&f, "", 0),
|
|
}
|
|
|
|
logger := Logger{
|
|
Rules: []Rule{rule},
|
|
Next: next,
|
|
}
|
|
|
|
r, err := http.NewRequest("GET", "/", nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
rec := httptest.NewRecorder()
|
|
|
|
status, err := logger.ServeHTTP(rec, r)
|
|
if status != 0 {
|
|
t.Error("Expected status to be 0 - was", status)
|
|
}
|
|
|
|
logged := f.String()
|
|
if !strings.Contains(logged, "404 13") {
|
|
t.Error("Expected 404 to be logged. Logged string -", logged)
|
|
}
|
|
}
|
|
*/
|