-
Notifications
You must be signed in to change notification settings - Fork 49
/
rejecter_test.go
50 lines (45 loc) · 1.03 KB
/
rejecter_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
45
46
47
48
49
50
package jose
import (
"testing"
"github.com/luraproject/lura/v2/config"
"github.com/luraproject/lura/v2/logging"
)
func TestChainedRejecterFactory(t *testing.T) {
rf := ChainedRejecterFactory([]RejecterFactory{
NopRejecterFactory{},
RejecterFactoryFunc(func(_ logging.Logger, _ *config.EndpointConfig) Rejecter {
return RejecterFunc(func(in map[string]interface{}) bool {
v, ok := in["key"].(int)
return ok && v == 42
})
}),
})
rejecter := rf.New(nil, nil)
for _, tc := range []struct {
name string
in map[string]interface{}
expected bool
}{
{
name: "empty",
in: map[string]interface{}{},
},
{
name: "reject",
in: map[string]interface{}{"key": 42},
expected: true,
},
{
name: "pass-1",
in: map[string]interface{}{"key": "42"},
},
{
name: "pass-2",
in: map[string]interface{}{"key": 9876},
},
} {
if v := rejecter.Reject(tc.in); tc.expected != v {
t.Errorf("unexpected result for %s. have %v, want %v", tc.name, v, tc.expected)
}
}
}