UNPKG

6.61 kBJavaScriptView Raw
1/*
2 * input-test.js: Tests for Loggly input requests
3 *
4 * (C) 2010 Nodejitsu Inc.
5 * MIT LICENSE
6 *
7 */
8
9var path = require('path'),
10 vows = require('vows'),
11 assert = require('assert'),
12 helpers = require('./helpers');
13
14var options = {},
15 testContext = {},
16 config = helpers.loadConfig(),
17 loggly = require('../lib/loggly').createClient(config),
18 logglyJSON = require('../lib/loggly').createClient(config);
19
20logglyJSON.config.json = true;
21
22vows.describe('node-loggly/inputs').addBatch({
23 "When using the node-loggly client": {
24 "the getInputs() method": {
25 topic: function () {
26 loggly.getInputs(this.callback);
27 },
28 "should return a list of valid inputs": function (err, inputs) {
29 assert.isNull(err);
30 inputs.forEach(function (input) {
31 helpers.assertInput(input);
32 });
33 }
34 },
35 "the getInput method": {
36 "when called with a plaintext input": {
37 topic: function () {
38 loggly.getInput('test', this.callback);
39 },
40 "should return a valid input": function (err, input) {
41 assert.isNull(err);
42 helpers.assertInput(input);
43 },
44 "of the format 'text'": function (err, input) {
45 assert.isNull(err);
46 assert.equal(input.format, 'text');
47 },
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;
52 }
53 },
54 "when called with a json input": {
55 topic: function () {
56 logglyJSON.getInput('test_json', this.callback);
57 },
58 "should return a valid input": function (err, input) {
59 assert.isNull(err);
60 helpers.assertInput(input);
61 },
62 "of the format 'json'": function (err, input) {
63 assert.isNull(err);
64 assert.equal(input.format, 'json');
65 },
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;
70 }
71 }
72 }
73 }
74}).addBatch({
75 "When using the node-loggly client": {
76 "the log() method": {
77 "to a 'text' input": {
78 "when passed a callback": {
79 topic: function () {
80 loggly.log(
81 config.inputs.test.token,
82 'this is a test logging message from /test/input-test.js',
83 this.callback);
84 },
85 "should log messages to loggly": function (err, result) {
86 assert.isNull(err);
87 assert.isObject(result);
88 assert.equal(result.response, 'ok');
89 }
90 },
91 "when not passed a callback": {
92 topic: function () {
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));
95 },
96 "should log messages to loggly": function (err, result) {
97 assert.isNull(err);
98 assert.isObject(result);
99 assert.equal(result.response, 'ok');
100 }
101 }
102 },
103 "to a 'json' input": {
104 "when passed a callback": {
105 topic: function () {
106 logglyJSON.log(
107 config.inputs.test_json.token,
108 {
109 timestamp: new Date().getTime(),
110 message: 'this is a test logging message from /test/input-test.js'
111 },
112 this.callback);
113 },
114 "should log messages to loggly": function (err, result) {
115 assert.isNull(err);
116 assert.isObject(result);
117 assert.equal(result.response, 'ok');
118 }
119 },
120 "when not passed a callback": {
121 topic: function () {
122 var emitter = logglyJSON.log(
123 config.inputs.test_json.token,
124 {
125 timestamp: new Date().getTime(),
126 message: 'this is a test logging message from /test/input-test.js'
127 }
128 );
129 emitter.on('log', this.callback.bind(null, null));
130 },
131 "should log messages to loggly": function (err, result) {
132 assert.isNull(err);
133 assert.isObject(result);
134 assert.equal(result.response, 'ok');
135 }
136 }
137 }
138 }
139 }
140}).addBatch({
141 "When using an instance of an input": {
142 "the log() method of the 'text' instance": {
143 "when passed a callback": {
144 topic: function () {
145 testContext.input.log('this is a test logging message from /test/input-test.js', this.callback);
146 },
147 "should log messages to loggly": function (err, result) {
148 assert.isNull(err);
149 assert.isObject(result);
150 assert.equal(result.response, 'ok');
151 }
152 },
153 "when not passed a callback": {
154 topic: function () {
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));
157 },
158 "should log messages to loggly": function (err, result) {
159 assert.isNull(err);
160 assert.isObject(result);
161 assert.equal(result.response, 'ok');
162 }
163 }
164 },
165 "the log() method of the 'json' instance": {
166 "when passed a callback": {
167 topic: function () {
168 testContext.inputJSON.log(
169 {
170 timestamp: new Date().getTime(),
171 message: 'this is a test logging message from /test/input-test.js'
172 },
173 this.callback);
174 },
175 "should log messages to loggly": function (err, result) {
176 assert.isNull(err);
177 assert.isObject(result);
178 assert.equal(result.response, 'ok');
179 }
180 },
181 "when not passed a callback": {
182 topic: function () {
183 var emitter = testContext.inputJSON.log({
184 timestamp: new Date().getTime(),
185 message: 'this is a test logging message from /test/input-test.js'
186 });
187 emitter.on('log', this.callback.bind(null, null));
188 },
189 "should log messages to loggly": function (err, result) {
190 assert.isNull(err);
191 assert.isObject(result);
192 assert.equal(result.response, 'ok');
193 }
194 }
195 }
196 }
197}).export(module);
\No newline at end of file