Permalink
Browse files

Add tests to illustrate inability to blacklist ‘error’ level messages…

… of a given namespace.
  • Loading branch information...
1 parent ddecea5 commit f1717bad531289f80d14d2880871924a428a4b9c @roark roark committed Nov 6, 2016
Showing with 43 additions and 4 deletions.
  1. +43 −4 test/filter.test.js
View
@@ -8,17 +8,43 @@ function filter(name, level) {
}
function enable(str) {
- f.clear();
// whitelisted only mode
- f.defaultResult = false;
+ constructRules('whitelist', str);
+}
- var parts = (str || '*.debug').split(/[\s,]+/), i, expr;
+function deny(str) {
+ // blacklisted only mode
+ constructRules('blacklist', str);
+}
+
+function constructRules(type, str) {
+ f.clear();
+
+ var defaultLevel;
+ if (type === 'whitelist') {
+ f.defaultResult = false;
+ defaultLevel = 'debug';
+ }
+ else if (type === 'blacklist') {
+ f.defaultResult = true
+ defaultLevel = 'error';
+ }
+ var parts = (str || '*.'+defaultLevel).split(/[\s,]+/), i, expr;
+ var rule, level;
for(i = 0; i < parts.length; i++) {
expr = parts[i].split('.');
if(expr.length > 2) {
expr = [ expr.slice(0, -1).join('.'), expr.slice(-1).join() ];
}
- f.allow(new RegExp('^'+expr[0].replace('*', '.*')), expr[1] || 'debug');
+ rule = new RegExp('^'+expr[0].replace('*', '.*'));
+ level = expr[1] || defaultLevel;
+
+ if (type === 'whitelist') {
+ f.allow(rule, level);
+ }
+ else if (type === 'blacklist') {
+ f.deny(rule, level);
+ }
}
}
@@ -74,6 +100,19 @@ exports['enable two modules with levels'] = function(done) {
done();
};
+exports['deny two modules with levels'] = function(done) {
+ deny('aaa.error,bbb.debug');
+ assert.ok(!filter('aaa', 'debug'));
+ assert.ok(!filter('aaa', 'info'));
+ assert.ok(!filter('aaa', 'warn'));
+ assert.ok(!filter('aaa', 'error'));
+ assert.ok(!filter('bbb', 'debug'));
+ assert.ok(filter('bbb', 'info'));
+ assert.ok(filter('bbb', 'warn'));
+ assert.ok(filter('bbb', 'error'));
+ done();
+};
+
exports['when the module name contains a dot'] = function(done) {
enable('aaa.bbb.warn');
assert.ok(!filter('aaa.bbb', 'debug'));

0 comments on commit f1717ba

Please sign in to comment.