-
Notifications
You must be signed in to change notification settings - Fork 43
/
nulllogger_test.go
48 lines (37 loc) · 1.21 KB
/
nulllogger_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
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MIT
package hclog
import (
"testing"
"github.com/stretchr/testify/assert"
)
var logger = NewNullLogger()
func TestNullLoggerIsEfficient(t *testing.T) {
// Since statements like "IsWarn()", "IsError()", etc. are used to gate
// actually writing warning and error statements, the null logger will
// be faster and more efficient if it always returns false for these calls.
assert.False(t, logger.IsTrace())
assert.False(t, logger.IsDebug())
assert.False(t, logger.IsInfo())
assert.False(t, logger.IsWarn())
assert.False(t, logger.IsError())
}
func TestNullLoggerReturnsNullLoggers(t *testing.T) {
// Sometimes the logger is asked to return subloggers.
// These should also be a nullLogger.
subLogger := logger.With()
_, ok := subLogger.(*nullLogger)
assert.True(t, ok)
subLogger = logger.Named("")
_, ok = subLogger.(*nullLogger)
assert.True(t, ok)
subLogger = logger.ResetNamed("")
_, ok = subLogger.(*nullLogger)
assert.True(t, ok)
}
func TestStandardLoggerIsntNil(t *testing.T) {
// Don't return a nil pointer for the standard logger,
// lest it cause a panic.
stdLogger := logger.StandardLogger(nil)
assert.NotEqual(t, nil, stdLogger)
}