-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstdlib_test.go
More file actions
50 lines (44 loc) · 1.13 KB
/
stdlib_test.go
File metadata and controls
50 lines (44 loc) · 1.13 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package stdlib
import (
"os"
"testing"
"github.com/rs/zerolog"
"github.com/stretchr/testify/assert"
)
func TestSetLogLevel(t *testing.T) {
testCases := []struct {
name string
level string
expected zerolog.Level
}{
{"trace level", "trace", zerolog.TraceLevel},
{"debug level", "debug", zerolog.DebugLevel},
{"info level", "info", zerolog.InfoLevel},
{"warn level", "warn", zerolog.WarnLevel},
{"error level", "error", zerolog.ErrorLevel},
{"invalid level", "invalid", zerolog.Disabled},
{"empty level", "", zerolog.Disabled},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
if tc.level != "" {
_ = os.Setenv(LOG_LEVEL, tc.level)
defer func() { _ = os.Unsetenv(LOG_LEVEL) }()
}
SetLogLevel()
assert.Equal(t, tc.expected, zerolog.GlobalLevel())
})
}
}
func TestPlaceholder(t *testing.T) {
// Test that Placeholder is empty struct
assert.Equal(t, struct{}{}, Placeholder)
// Test AnyType can hold different types
var anyVal AnyType
anyVal = 42
assert.Equal(t, 42, anyVal)
anyVal = "test"
assert.Equal(t, "test", anyVal)
anyVal = true
assert.Equal(t, true, anyVal)
}