FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
stackrox/pkg/logging/module_test.go at master · stackrox/stackrox · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
stackrox
/
stackrox
Public
Notifications
You must be signed in to change notification settings
Fork
191
Star
1.3k
Code
Issues
54
Pull requests
603
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
stackrox
/
pkg
/
logging
/
module_test.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
113 lines (92 loc) · 3.32 KB
Breadcrumbs
stackrox
/
pkg
/
logging
/
module_test.go
Copy path
File metadata and controls
113 lines (92 loc) · 3.32 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package
logging
import
(
"testing"
"github.com/stackrox/rox/pkg/uuid"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
func
TestGetCallingModule
(
t
*
testing.
T
) {
assert
.
Equal
(
t
,
"pkg/logging"
,
getCallingModule
(
0
))
}
func
TestCurrentModuleReturnsValidModule
(
t
*
testing.
T
) {
assert
.
NotNil
(
t
,
CurrentModule
())
}
func
TestForEachModuleVisitsIndividualModules
(
t
*
testing.
T
) {
// Make sure that pkg/logging is registered
assert
.
NotNil
(
t
,
CurrentModule
())
assert
.
NotNil
(
t
,
ModuleForName
(
"some/module"
))
visited
:=
map
[
string
]
struct
{}{}
ForEachModule
(
func
(
name
string
,
m
*
Module
) {
if
m
!=
nil
{
visited
[
name
]
=
struct
{}{}
}
},
SelectAll
)
assert
.
Contains
(
t
,
visited
,
"pkg/logging"
)
assert
.
Contains
(
t
,
visited
,
"some/module"
)
}
func
TestParseDefaultModuleLevels_Success
(
t
*
testing.
T
) {
levels
,
errs
:=
parseDefaultModuleLevels
(
"foo=Info,, bar =debug,"
)
assert
.
Equal
(
t
,
levels
,
map
[
string
]zapcore.
Level
{
"foo"
:
zapcore
.
InfoLevel
,
"bar"
:
zapcore
.
DebugLevel
,
})
assert
.
Empty
(
t
,
errs
)
}
func
TestParseDefaultModuleLevels_Errs
(
t
*
testing.
T
) {
levels
,
errs
:=
parseDefaultModuleLevels
(
"foo=Info, baz , bar =random, qux=debug,"
)
assert
.
Equal
(
t
,
levels
,
map
[
string
]zapcore.
Level
{
"foo"
:
zapcore
.
InfoLevel
,
"qux"
:
zapcore
.
DebugLevel
,
})
assert
.
Len
(
t
,
errs
,
2
)
}
func
TestNilModuleAlwaysReturnsFalseOnUnref
(
t
*
testing.
T
) {
var
m
*
Module
assert
.
False
(
t
,
m
.
unref
())
}
func
TestModuleSetLogLevel
(
t
*
testing.
T
) {
CurrentModule
().
SetLogLevel
(
zapcore
.
DebugLevel
)
assert
.
Equal
(
t
,
zapcore
.
DebugLevel
,
CurrentModule
().
GetLogLevel
())
}
func
TestModuleRefCountingWorks
(
t
*
testing.
T
) {
module
:=
newModule
(
uuid
.
NewV4
().
String
(),
zap
.
NewAtomicLevelAt
(
zapcore
.
InfoLevel
))
module
.
ref
()
assert
.
False
(
t
,
module
.
unref
())
assert
.
True
(
t
,
module
.
unref
())
}
func
TestLoggerCreatedFromModuleReferencesModule
(
t
*
testing.
T
) {
module
:=
newModule
(
uuid
.
NewV4
().
String
(),
zap
.
NewAtomicLevelAt
(
zapcore
.
InfoLevel
))
logger
:=
module
.
Logger
()
assert
.
Equal
(
t
,
module
,
logger
.
module
)
}
func
TestRegistryPurgesModulesWithRefCountOfZero
(
t
*
testing.
T
) {
name
:=
uuid
.
NewV4
().
String
()
modules
.
getOrAddModule
(
name
)
modules
.
unrefModule
(
name
)
assert
.
NotContains
(
t
,
modules
.
modules
,
name
)
}
func
TestLoggerCreatedFromModuleUpdatesLogLevel
(
t
*
testing.
T
) {
for
zapLevel
:=
range
validLevels
{
module
:=
newModule
(
uuid
.
NewV4
().
String
(),
zap
.
NewAtomicLevelAt
(
zapcore
.
InfoLevel
))
logger
:=
module
.
Logger
()
module
.
SetLogLevel
(
zapLevel
)
assert
.
True
(
t
,
logger
.
SugaredLogger
().
Desugar
().
Core
().
Enabled
(
zapLevel
))
// uses internal knowledge of how Enabled(level) method works
assert
.
False
(
t
,
logger
.
SugaredLogger
().
Desugar
().
Core
().
Enabled
(
zapLevel
-
1
))
}
}
func
TestLoggerLevelUpdatesWithGlobalLevel
(
t
*
testing.
T
) {
module
:=
ModuleForName
(
uuid
.
NewV4
().
String
())
logger
:=
module
.
Logger
()
level
:=
GetGlobalLogLevel
()
module
.
SetLogLevel
(
zapcore
.
DebugLevel
)
// verify the global level remains unchanged
assert
.
Equal
(
t
,
level
,
GetGlobalLogLevel
())
assert
.
True
(
t
,
logger
.
SugaredLogger
().
Desugar
().
Core
().
Enabled
(
zapcore
.
DebugLevel
))
SetGlobalLogLevel
(
zapcore
.
WarnLevel
)
// verify logger level changes with global level
assert
.
Equal
(
t
,
zapcore
.
WarnLevel
,
GetGlobalLogLevel
())
assert
.
True
(
t
,
logger
.
SugaredLogger
().
Desugar
().
Core
().
Enabled
(
zapcore
.
WarnLevel
))
assert
.
False
(
t
,
logger
.
SugaredLogger
().
Desugar
().
Core
().
Enabled
(
zapcore
.
InfoLevel
))
}
Back
|
FazBrowse Home
|
New Git URL