-
Notifications
You must be signed in to change notification settings - Fork 31
/
filter_test.go
38 lines (34 loc) · 1.01 KB
/
filter_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 2016 Qiang Xue. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package log_test
import (
"strings"
"testing"
"github.com/go-ozzo/ozzo-log"
)
func TestFilterAllow(t *testing.T) {
tests := []struct {
cats []string
cat string
expected bool
}{
{[]string{}, "", true},
{[]string{}, "system", true},
{[]string{"system"}, "", false},
{[]string{"system"}, "system", true},
{[]string{"system"}, "system.db", false},
{[]string{"system.*"}, "", false},
{[]string{"system.*"}, "system", false},
{[]string{"system.*"}, "system.", true},
{[]string{"system.*"}, "system.db", true},
}
for _, test := range tests {
filter := log.Filter{MaxLevel: log.LevelDebug, Categories: test.cats}
filter.Init()
e := &log.Entry{Category: test.cat}
if filter.Allow(e) != test.expected {
t.Errorf("filter(%q).Allow(%q) = %v, expected %v", strings.Join(test.cats, ","), test.cat, filter.Allow(e), test.expected)
}
}
}