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