@@ -33,6 +33,7 @@ type testCase struct {
33
33
expectedLevels []string
34
34
modules []string
35
35
withRegEx bool
36
+ revert bool
36
37
shouldErr bool
37
38
}
38
39
@@ -46,22 +47,24 @@ func TestSetModuleLevel(t *testing.T) {
46
47
var tc []testCase
47
48
48
49
tc = append (tc ,
49
- testCase {"Valid" , []string {"a" , "warning" }, []string {"WARNING" }, []string {"a" }, false , false },
50
+ testCase {"Valid" , []string {"a" , "warning" }, []string {"WARNING" }, []string {"a" }, false , false , false },
50
51
// Same as before
51
- testCase {"Invalid" , []string {"a" , "foo" }, []string {"WARNING" }, []string {"a" }, false , false },
52
+ testCase {"Invalid" , []string {"a" , "foo" }, []string {"WARNING" }, []string {"a" }, false , false , false },
52
53
// Tests with regular expressions
53
54
testCase {"RegexModuleWithSubmodule" , []string {"foo" , "warning" }, []string {"WARNING" , "WARNING" , flogging .DefaultLevel ()},
54
- []string {"foo" , "foo/bar" , "baz" }, true , false },
55
+ []string {"foo" , "foo/bar" , "baz" }, true , false , false },
55
56
// Set the level for modules that contain "foo" or "baz"
56
57
testCase {"RegexOr" , []string {"foo|baz" , "debug" }, []string {"DEBUG" , "DEBUG" , "DEBUG" , flogging .DefaultLevel ()},
57
- []string {"foo" , "foo/bar" , "baz" , "random" }, true , false },
58
+ []string {"foo" , "foo/bar" , "baz" , "random" }, true , false , false },
58
59
// Set the level for modules that end with "bar"
59
60
testCase {"RegexSuffix" , []string {"bar$" , "error" }, []string {"ERROR" , flogging .DefaultLevel ()},
60
- []string {"foo/bar" , "bar/baz" }, true , false },
61
+ []string {"foo/bar" , "bar/baz" }, true , false , false },
61
62
testCase {"RegexComplex" , []string {"^[a-z]+\\ /[a-z]+#.+$" , "warning" }, []string {flogging .DefaultLevel (), flogging .DefaultLevel (), "WARNING" , "WARNING" , "WARNING" },
62
- []string {"gossip/util" , "orderer/util" , "gossip/gossip#0.0.0.0:7051" , "gossip/conn#-1" , "orderer/conn#0.0.0.0:7051" }, true , false },
63
+ []string {"gossip/util" , "orderer/util" , "gossip/gossip#0.0.0.0:7051" , "gossip/conn#-1" , "orderer/conn#0.0.0.0:7051" }, true , false , false },
63
64
testCase {"RegexInvalid" , []string {"(" , "warning" }, []string {flogging .DefaultLevel ()},
64
- []string {"foo" }, true , true },
65
+ []string {"foo" }, true , false , true },
66
+ testCase {"RevertLevels" , []string {"revertmodule1" , "warning" , "revertmodule2" , "debug" }, []string {"WARNING" , "DEBUG" , "DEBUG" },
67
+ []string {"revertmodule1" , "revertmodule2" , "revertmodule2/submodule" }, true , true , false },
65
68
)
66
69
67
70
assert := assert .New (t )
@@ -72,26 +75,33 @@ func TestSetModuleLevel(t *testing.T) {
72
75
for j := 0 ; j < len (tc [i ].modules ); j ++ {
73
76
flogging .MustGetLogger (tc [i ].modules [j ])
74
77
}
78
+ if tc [i ].revert {
79
+ flogging .SetPeerStartupModulesMap ()
80
+ }
75
81
flogging .IsSetLevelByRegExpEnabled = true // enable for call below
76
82
}
77
-
78
- _ , err := flogging .SetModuleLevel (tc [i ].args [0 ], tc [i ].args [1 ])
79
- if tc [i ].shouldErr {
80
- assert .NotNil (err , "Should have returned an error" )
83
+ for k := 0 ; k < len (tc [i ].args ); k = k + 2 {
84
+ _ , err := flogging .SetModuleLevel (tc [i ].args [k ], tc [i ].args [k + 1 ])
85
+ if tc [i ].shouldErr {
86
+ assert .NotNil (err , "Should have returned an error" )
87
+ }
81
88
}
82
- for k := 0 ; k < len (tc [i ].expectedLevels ); k ++ {
83
- assert .Equal (tc [i ].expectedLevels [k ], flogging .GetModuleLevel (tc [i ].modules [k ]))
89
+ for l := 0 ; l < len (tc [i ].expectedLevels ); l ++ {
90
+ assert .Equal (tc [i ].expectedLevels [l ], flogging .GetModuleLevel (tc [i ].modules [l ]))
91
+ }
92
+ if tc [i ].revert {
93
+ flogging .RevertToPeerStartupLevels ()
94
+ for m := 0 ; m < len (tc [i ].modules ); m ++ {
95
+ assert .Equal (flogging .GetPeerStartupLevel (tc [i ].modules [m ]), flogging .GetModuleLevel (tc [i ].modules [m ]))
96
+ }
84
97
}
85
-
86
98
if tc [i ].withRegEx {
87
99
// Force reset (a) in case the next test is non-regex, (b) so as
88
100
// to reset the modules map and reuse module names.
89
101
flogging .Reset ()
90
-
91
102
}
92
103
})
93
104
}
94
-
95
105
}
96
106
97
107
func TestInitFromSpec (t * testing.T ) {
@@ -120,25 +130,25 @@ func TestInitFromSpec(t *testing.T) {
120
130
// MODULES
121
131
122
132
tc = append (tc ,
123
- testCase {"SingleModuleLevel" , []string {"a=info" }, []string {"INFO" }, []string {"a" }, false , false },
124
- testCase {"MultipleModulesMultipleLevels" , []string {"a=info:b=debug" }, []string {"INFO" , "DEBUG" }, []string {"a" , "b" }, false , false },
125
- testCase {"MultipleModulesSameLevel" , []string {"a,b=warning" }, []string {"WARNING" , "WARNING" }, []string {"a" , "b" }, false , false },
133
+ testCase {"SingleModuleLevel" , []string {"a=info" }, []string {"INFO" }, []string {"a" }, false , false , false },
134
+ testCase {"MultipleModulesMultipleLevels" , []string {"a=info:b=debug" }, []string {"INFO" , "DEBUG" }, []string {"a" , "b" }, false , false , false },
135
+ testCase {"MultipleModulesSameLevel" , []string {"a,b=warning" }, []string {"WARNING" , "WARNING" }, []string {"a" , "b" }, false , false , false },
126
136
)
127
137
128
138
// MODULES + DEFAULT
129
139
130
140
tc = append (tc ,
131
- testCase {"GlobalDefaultAndSingleModuleLevel" , []string {"info:a=warning" }, []string {"INFO" , "WARNING" }, []string {"" , "a" }, false , false },
132
- testCase {"SingleModuleLevelAndGlobalDefaultAtEnd" , []string {"a=warning:info" }, []string {"WARNING" , "INFO" }, []string {"a" , "" }, false , false },
141
+ testCase {"GlobalDefaultAndSingleModuleLevel" , []string {"info:a=warning" }, []string {"INFO" , "WARNING" }, []string {"" , "a" }, false , false , false },
142
+ testCase {"SingleModuleLevelAndGlobalDefaultAtEnd" , []string {"a=warning:info" }, []string {"WARNING" , "INFO" }, []string {"a" , "" }, false , false , false },
133
143
)
134
144
135
145
// INVALID INPUT
136
146
137
147
tc = append (tc ,
138
- testCase {"InvalidLevel" , []string {"foo" }, []string {flogging .DefaultLevel ()}, []string {"" }, false , false },
139
- testCase {"InvalidLevelForSingleModule" , []string {"a=foo" }, []string {flogging .DefaultLevel ()}, []string {"" }, false , false },
140
- testCase {"EmptyModuleEqualsLevel" , []string {"=warning" }, []string {flogging .DefaultLevel ()}, []string {"" }, false , false },
141
- testCase {"InvalidModuleSyntax" , []string {"a=b=c" }, []string {flogging .DefaultLevel ()}, []string {"" }, false , false },
148
+ testCase {"InvalidLevel" , []string {"foo" }, []string {flogging .DefaultLevel ()}, []string {"" }, false , false , false },
149
+ testCase {"InvalidLevelForSingleModule" , []string {"a=foo" }, []string {flogging .DefaultLevel ()}, []string {"" }, false , false , false },
150
+ testCase {"EmptyModuleEqualsLevel" , []string {"=warning" }, []string {flogging .DefaultLevel ()}, []string {"" }, false , false , false },
151
+ testCase {"InvalidModuleSyntax" , []string {"a=b=c" }, []string {flogging .DefaultLevel ()}, []string {"" }, false , false , false },
142
152
)
143
153
144
154
assert := assert .New (t )
0 commit comments