2014-07-17 09:34:26 +02:00
|
|
|
/**
|
|
|
|
* Copyright 2014 IBM Corp.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
**/
|
|
|
|
var should = require("should");
|
2015-03-06 15:14:47 +01:00
|
|
|
var sinon = require("sinon");
|
|
|
|
var util = require("util");
|
2014-07-17 09:34:26 +02:00
|
|
|
|
|
|
|
describe("red/log", function() {
|
|
|
|
it('can be required without errors', function() {
|
|
|
|
require("../../red/log");
|
|
|
|
});
|
2015-03-06 11:18:33 +01:00
|
|
|
|
|
|
|
var log = require("../../red/log");
|
2015-03-06 23:58:30 +01:00
|
|
|
var sett = {logging: { console: { level: 'metric', metrics: true } } };
|
2015-03-06 15:14:47 +01:00
|
|
|
log.init(sett);
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
var spy = sinon.spy(util, 'log');
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function() {
|
|
|
|
util.log.restore();
|
|
|
|
});
|
2015-03-06 11:18:33 +01:00
|
|
|
|
|
|
|
it('it can raise an error', function() {
|
2015-03-06 15:14:47 +01:00
|
|
|
var ret = log.error("This is an error");
|
|
|
|
sinon.assert.calledWithMatch(util.log,"");
|
2015-03-06 11:18:33 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('it can raise a trace', function() {
|
2015-03-06 15:14:47 +01:00
|
|
|
var ret = log.trace("This is a trace");
|
|
|
|
sinon.assert.calledWithMatch(util.log,"");
|
2015-03-06 11:18:33 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('it can raise a debug', function() {
|
2015-03-06 15:14:47 +01:00
|
|
|
var ret = log.debug("This is a debug");
|
|
|
|
sinon.assert.calledWithMatch(util.log,"");
|
|
|
|
});
|
|
|
|
|
2015-03-08 17:53:48 +01:00
|
|
|
it('it can raise a metric', function() {
|
|
|
|
var metrics = {};
|
|
|
|
metrics.level = log.METRIC;
|
|
|
|
metrics.nodeid = "testid";
|
|
|
|
metrics.event = "node.test.testevent";
|
|
|
|
metrics.msgid = "12345";
|
|
|
|
metrics.value = "the metric payload";
|
|
|
|
var ret = log.log(metrics);
|
|
|
|
sinon.assert.calledWithMatch(util.log,"");
|
|
|
|
});
|
|
|
|
|
2015-03-08 16:26:24 +01:00
|
|
|
it('it checks metrics are enabled', function() {
|
2015-03-06 15:14:47 +01:00
|
|
|
log.metric().should.equal(true);
|
2015-03-07 14:22:21 +01:00
|
|
|
var sett = {logging: { console: { level: 'info', metrics: false } } };
|
|
|
|
log.init(sett);
|
2015-03-06 11:18:33 +01:00
|
|
|
});
|
2015-03-07 14:22:21 +01:00
|
|
|
|
2015-03-08 16:26:24 +01:00
|
|
|
it('it checks metrics are disabled', function() {
|
|
|
|
log.metric().should.equal(false);
|
|
|
|
});
|
|
|
|
|
2014-07-17 09:34:26 +02:00
|
|
|
});
|