-
Notifications
You must be signed in to change notification settings - Fork 43
/
exclude_test.go
58 lines (46 loc) · 1.43 KB
/
exclude_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
51
52
53
54
55
56
57
58
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MIT
package hclog
import (
"regexp"
"testing"
"github.com/stretchr/testify/assert"
)
func TestExclude(t *testing.T) {
t.Run("excludes by message", func(t *testing.T) {
var em ExcludeByMessage
em.Add("foo")
em.Add("bar")
assert.True(t, em.Exclude(Info, "foo"))
assert.True(t, em.Exclude(Info, "bar"))
assert.False(t, em.Exclude(Info, "qux"))
assert.False(t, em.Exclude(Info, "foo qux"))
assert.False(t, em.Exclude(Info, "qux bar"))
})
t.Run("excludes by prefix", func(t *testing.T) {
ebp := ExcludeByPrefix("foo: ")
assert.True(t, ebp.Exclude(Info, "foo: rocks"))
assert.False(t, ebp.Exclude(Info, "foo"))
assert.False(t, ebp.Exclude(Info, "qux foo: bar"))
})
t.Run("exclude by regexp", func(t *testing.T) {
ebr := &ExcludeByRegexp{
Regexp: regexp.MustCompile("(foo|bar)"),
}
assert.True(t, ebr.Exclude(Info, "foo"))
assert.True(t, ebr.Exclude(Info, "bar"))
assert.True(t, ebr.Exclude(Info, "foo qux"))
assert.True(t, ebr.Exclude(Info, "qux bar"))
assert.False(t, ebr.Exclude(Info, "qux"))
})
t.Run("excludes many funcs", func(t *testing.T) {
ef := ExcludeFuncs{
ExcludeByPrefix("foo: ").Exclude,
ExcludeByPrefix("bar: ").Exclude,
}
assert.True(t, ef.Exclude(Info, "foo: rocks"))
assert.True(t, ef.Exclude(Info, "bar: rocks"))
assert.False(t, ef.Exclude(Info, "foo"))
assert.False(t, ef.Exclude(Info, "qux foo: bar"))
})
}