-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlogical_test.go
44 lines (36 loc) · 1005 Bytes
/
logical_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
39
40
41
42
43
44
// 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 TestUseIf(t *testing.T) {
tests := []struct {
name string
cond bool
}{
{name: "true", cond: true},
{name: "false", cond: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "http://example.com", http.NoBody)
called := false
setCalledHandler := func(next http.Handler) http.Handler {
called = true
return next
}
handler := UseIf(tt.cond, setCalledHandler)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
handler.ServeHTTP(httptest.NewRecorder(), req)
if tt.cond && !called {
t.Errorf("UseIf() = %v, want %v", called, tt.cond)
}
if !tt.cond && called {
t.Errorf("UseIf() = %v, want %v", called, tt.cond)
}
})
}
}