2 * input-test.js: Tests for Loggly input requests
4 * (C) 2010 Nodejitsu Inc.
9 var path = require('path'),
10 vows = require('vows'),
11 assert = require('assert'),
12 helpers = require('./helpers');
16 config = helpers.loadConfig(),
17 loggly = require('../lib/loggly').createClient(config),
18 logglyJSON = require('../lib/loggly').createClient(config);
20 logglyJSON.config.json = true;
22 vows.describe('node-loggly/inputs').addBatch({
23 "When using the node-loggly client": {
24 "the getInputs() method": {
26 loggly.getInputs(this.callback);
28 "should return a list of valid inputs": function (err, inputs) {
30 inputs.forEach(function (input) {
31 helpers.assertInput(input);
35 "the getInput method": {
36 "when called with a plaintext input": {
38 loggly.getInput('test', this.callback);
40 "should return a valid input": function (err, input) {
42 helpers.assertInput(input);
44 "of the format 'text'": function (err, input) {
46 assert.equal(input.format, 'text');
48 "that matches the first input in the test configuration": function (err, input) {
49 assert.equal(config.inputs.test.token,input.input_token);
50 assert.equal(config.inputs.test.id,input.id);
51 testContext.input = input;
54 "when called with a json input": {
56 logglyJSON.getInput('test_json', this.callback);
58 "should return a valid input": function (err, input) {
60 helpers.assertInput(input);
62 "of the format 'json'": function (err, input) {
64 assert.equal(input.format, 'json');
66 "that matches the second input in the test configuration": function (err, input) {
67 assert.equal(config.inputs.test_json.token,input.input_token);
68 assert.equal(config.inputs.test_json.id,input.id);
69 testContext.inputJSON = input;
75 "When using the node-loggly client": {
77 "to a 'text' input": {
78 "when passed a callback": {
81 config.inputs.test.token,
82 'this is a test logging message from /test/input-test.js',
85 "should log messages to loggly": function (err, result) {
87 assert.isObject(result);
88 assert.equal(result.response, 'ok');
91 "when not passed a callback": {
93 var emitter = loggly.log(config.inputs.test.token, 'this is a test logging message from /test/input-test.js');
94 emitter.on('log', this.callback.bind(null, null));
96 "should log messages to loggly": function (err, result) {
98 assert.isObject(result);
99 assert.equal(result.response, 'ok');
103 "to a 'json' input": {
104 "when passed a callback": {
107 config.inputs.test_json.token,
109 timestamp: new Date().getTime(),
110 message: 'this is a test logging message from /test/input-test.js'
114 "should log messages to loggly": function (err, result) {
116 assert.isObject(result);
117 assert.equal(result.response, 'ok');
120 "when not passed a callback": {
122 var emitter = logglyJSON.log(
123 config.inputs.test_json.token,
125 timestamp: new Date().getTime(),
126 message: 'this is a test logging message from /test/input-test.js'
129 emitter.on('log', this.callback.bind(null, null));
131 "should log messages to loggly": function (err, result) {
133 assert.isObject(result);
134 assert.equal(result.response, 'ok');
141 "When using an instance of an input": {
142 "the log() method of the 'text' instance": {
143 "when passed a callback": {
145 testContext.input.log('this is a test logging message from /test/input-test.js', this.callback);
147 "should log messages to loggly": function (err, result) {
149 assert.isObject(result);
150 assert.equal(result.response, 'ok');
153 "when not passed a callback": {
155 var emitter = testContext.input.log('this is a test logging message from /test/input-test.js');
156 emitter.on('log', this.callback.bind(null, null));
158 "should log messages to loggly": function (err, result) {
160 assert.isObject(result);
161 assert.equal(result.response, 'ok');
165 "the log() method of the 'json' instance": {
166 "when passed a callback": {
168 testContext.inputJSON.log(
170 timestamp: new Date().getTime(),
171 message: 'this is a test logging message from /test/input-test.js'
175 "should log messages to loggly": function (err, result) {
177 assert.isObject(result);
178 assert.equal(result.response, 'ok');
181 "when not passed a callback": {
183 var emitter = testContext.inputJSON.log({
184 timestamp: new Date().getTime(),
185 message: 'this is a test logging message from /test/input-test.js'
187 emitter.on('log', this.callback.bind(null, null));
189 "should log messages to loggly": function (err, result) {
191 assert.isObject(result);
192 assert.equal(result.response, 'ok');