-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtrace_test.go
More file actions
36 lines (31 loc) · 1.15 KB
/
trace_test.go
File metadata and controls
36 lines (31 loc) · 1.15 KB
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
package logging
import (
"os"
"strings"
"testing"
"github.com/test-go/testify/assert"
)
func TestIsTraceEnabled(t *testing.T) {
tests := []struct {
name string
inName string
inID string
env string
expectedEnabled bool
}{
{"match name", "log", "github/log", "TRACE=log", true},
{"match id", "log", "github/log", "TRACE=github/log", true},
{"match id regex", "log", "github/log", "TRACE=github/.*", true},
{"match all", "log", "github/log", "TRACE=.*", true},
{"match then denied by name", "log", "github/log", "TRACE=.*,-log", false},
{"match then denied by id", "log", "github/log", "TRACE=.*,-github/log", false},
{"match then denied by id regex", "log", "github/log", "TRACE=.*,-github/.*", false},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
os.Setenv("TRACE", strings.TrimPrefix(test.env, "TRACE="))
isEnabled := IsTraceEnabled(test.inName, test.inID)
assert.Equal(t, test.expectedEnabled, isEnabled, "Expected trace to be enabled=%t for %s @ %s with env %s but it was enabled=%t", test.expectedEnabled, test.inName, test.inID, test.env, isEnabled)
})
}
}