1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | var path = require('path'),
|
9 | vows = require('vows'),
|
10 | assert = require('assert'),
|
11 | nock = require('nock'),
|
12 | helpers = require('./helpers');
|
13 |
|
14 | var config = helpers.loadConfig(),
|
15 | loggly = require('../lib/loggly').createClient({
|
16 | subdomain: config.subdomain,
|
17 | token: config.token
|
18 | }),
|
19 | logglyJSON = require('../lib/loggly').createClient({
|
20 | subdomain: config.subdomain,
|
21 | token: config.token,
|
22 | json: true
|
23 | });
|
24 |
|
25 | vows.describe('node-loggly/inputs (no auth)').addBatch({
|
26 | "When using the node-loggly client without authentication": {
|
27 | "the log() method": {
|
28 | "to a 'text' input": {
|
29 | "when passed a callback": {
|
30 | topic: function() {
|
31 |
|
32 | nock("https://logs-01.loggly.com")
|
33 | .post('/inputs/' + config.token)
|
34 | .reply(200, {
|
35 | "response": "ok"
|
36 | });
|
37 |
|
38 | loggly.log(
|
39 | 'this is a test logging message from /test/input-test.js',
|
40 | this.callback
|
41 | );
|
42 | },
|
43 | "should log messages to loggly": function(err, result) {
|
44 | assert.isNull(err);
|
45 | assert.isObject(result);
|
46 | assert.equal(result.response, 'ok');
|
47 | }
|
48 | },
|
49 | }
|
50 | }
|
51 | }
|
52 | })
|
53 | .addBatch({
|
54 | "When using the node-loggly client without authentication": {
|
55 | "the log() method": {
|
56 | "to a 'text' input": {
|
57 | "when not passed a callback": {
|
58 | topic: function() {
|
59 | nock("https://logs-01.loggly.com")
|
60 | .post('/inputs/' + config.token).reply(200, {
|
61 | "response": "ok"
|
62 | });
|
63 | loggly.log('this is a test logging message from /test/input-test.js');
|
64 | loggly.on('log', this.callback.bind(null, null));
|
65 | },
|
66 | "should log messages to loggly": function(err, result) {
|
67 | assert.isNull(err);
|
68 | assert.isObject(result);
|
69 | assert.equal(result.response, 'ok');
|
70 | }
|
71 | }
|
72 | },
|
73 | }
|
74 | }
|
75 | })
|
76 | .addBatch({
|
77 | "When using the node-loggly client without authentication": {
|
78 | "the log() method": {
|
79 | "to a 'json' input": {
|
80 | "when passed a callback": {
|
81 | topic: function() {
|
82 |
|
83 | nock("https://logs-01.loggly.com")
|
84 | .post('/inputs/' + config.token).reply(200, {
|
85 | "response": "ok"
|
86 | });
|
87 | logglyJSON.log({
|
88 | timestamp: new Date().getTime(),
|
89 | message: 'this is a test logging message from /test/input-test.js'
|
90 | }, this.callback);
|
91 | },
|
92 | "should log messages to loggly": function(err, result) {
|
93 | assert.isNull(err);
|
94 | assert.isObject(result);
|
95 | assert.equal(result.response, 'ok');
|
96 | }
|
97 | }
|
98 | }
|
99 | }
|
100 | }
|
101 | })
|
102 | .addBatch({
|
103 | "When using the node-loggly client without authentication": {
|
104 | "the log() method": {
|
105 | "to a 'json' input": {
|
106 | "when not passed a callback": {
|
107 | topic: function() {
|
108 | nock("https://logs-01.loggly.com")
|
109 | .post('/inputs/' + config.token).reply(200, {
|
110 | "response": "ok"
|
111 | });
|
112 | logglyJSON.log({
|
113 | timestamp: new Date().getTime(),
|
114 | message: 'this is a test logging message from /test/input-test.js'
|
115 | });
|
116 | logglyJSON.on('log', this.callback.bind(null, null));
|
117 | },
|
118 | "should log messages to loggly": function(err, result) {
|
119 | assert.isNull(err);
|
120 | assert.isObject(result);
|
121 | assert.equal(result.response, 'ok');
|
122 | }
|
123 | }
|
124 | }
|
125 | }
|
126 | }
|
127 | }).addBatch({
|
128 | "When using the node-loggly client without authentication": {
|
129 | "the log() method": {
|
130 | "to a 'json' input with a single tag": {
|
131 | "when not passed a callback": {
|
132 | topic: function() {
|
133 | nock("https://logs-01.loggly.com")
|
134 | .post('/inputs/' + config.token).reply(200, {
|
135 | "response": "ok"
|
136 | });
|
137 | logglyJSON.log({
|
138 | timestamp: new Date().getTime(),
|
139 | message: 'this is a test logging message from /test/input-test.js'
|
140 | }, "WOOOO-TAG");
|
141 | logglyJSON.on('log', this.callback.bind(null, null));
|
142 | },
|
143 | "should log messages to loggly": function(err, result) {
|
144 | assert.isNull(err);
|
145 | assert.isObject(result);
|
146 | assert.equal(result.response, 'ok');
|
147 | }
|
148 | }
|
149 | }
|
150 | }
|
151 | }
|
152 | }).addBatch({
|
153 | "When using the node-loggly client without authentication": {
|
154 | "the log() method": {
|
155 | "to a 'json' input with tags that exist as an array": {
|
156 | "when not passed a callback": {
|
157 | topic: function() {
|
158 | nock("https://logs-01.loggly.com")
|
159 | .post('/inputs/' + config.token).reply(200, {
|
160 | "response": "ok"
|
161 | });
|
162 | logglyJSON.log({
|
163 | timestamp: new Date().getTime(),
|
164 | message: 'this is a test logging message from /test/input-test.js'
|
165 | }, ["tag", "tag2"]);
|
166 | logglyJSON.on('log', this.callback.bind(null, null));
|
167 | },
|
168 | "should log messages to loggly": function(err, result) {
|
169 | assert.isNull(err);
|
170 | assert.isObject(result);
|
171 | assert.equal(result.response, 'ok');
|
172 | }
|
173 | }
|
174 | }
|
175 | }
|
176 | }
|
177 | }).addBatch({
|
178 | "When using the node-loggly client without authentication": {
|
179 | "the log() method": {
|
180 | "takes an array": {
|
181 | "when not passed a callback": {
|
182 | topic: function() {
|
183 | nock("https://logs-01.loggly.com")
|
184 | .post('/inputs/' + config.token).reply(200, {
|
185 | "response": "ok"
|
186 | });
|
187 | logglyJSON.log([{
|
188 | work: 'it harder'
|
189 | }, {
|
190 | make: 'it better'
|
191 | }]);
|
192 | logglyJSON.on('log', this.callback.bind(null, null));
|
193 | },
|
194 | "should log messages to loggly": function(err, result) {
|
195 | assert.isNull(err);
|
196 | assert.isObject(result);
|
197 | assert.equal(result.response, 'ok');
|
198 | }
|
199 | }
|
200 | }
|
201 | }
|
202 | }
|
203 | }).export(module);
|