-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdebug_test.go
38 lines (32 loc) · 942 Bytes
/
debug_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright (c) Liam Stanley <[email protected]>. All rights reserved. Use of
// this source code is governed by the MIT license that can be found in
// the LICENSE file.
package chix
import (
"net/http"
"net/http/httptest"
"testing"
)
func TestUseDebug(t *testing.T) {
tests := []struct {
name string
debug bool
}{
{name: "debug", debug: true},
{name: "not debug", debug: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "http://example.com", http.NoBody)
handler := UseDebug(tt.debug)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if IsDebug(r) != tt.debug {
t.Errorf("IsDebug() = %v, want %v", IsDebug(r), tt.debug)
}
if IsDebugCtx(r.Context()) != tt.debug {
t.Errorf("IsDebugCtx() = %v, want %v", IsDebugCtx(r.Context()), tt.debug)
}
}))
handler.ServeHTTP(httptest.NewRecorder(), req)
})
}
}