1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | var path = require('path'),
|
8 | vows = require('vows'),
|
9 | http = require('http'),
|
10 | fs = require('fs'),
|
11 | assert = require('assert'),
|
12 | winston = require('../../lib/winston'),
|
13 | helpers = require('../helpers'),
|
14 | hock = require('hock');
|
15 |
|
16 | var transport = require('./transport');
|
17 |
|
18 | var host = '127.0.0.1';
|
19 |
|
20 | vows.describe('winston/transports/http').addBatch({
|
21 | "When the HTTP endpoint": {
|
22 | topic: function () {
|
23 | var mock = this.mock = hock.createHock(),
|
24 | self = this;
|
25 |
|
26 | mock
|
27 | .post('/log', {
|
28 | "method":"collect",
|
29 | "params":{
|
30 | "level":"info",
|
31 | "message":"hello",
|
32 | "meta":{}
|
33 | }
|
34 | })
|
35 | .min(1)
|
36 | .max(1)
|
37 | .reply(200);
|
38 |
|
39 | var server = this.server = http.createServer(mock.handler);
|
40 | server.listen(0, '0.0.0.0', this.callback);
|
41 | },
|
42 | "is running": function (err) {
|
43 | assert.ifError(err);
|
44 | },
|
45 | "an instance of the Http transport": {
|
46 | topic: function () {
|
47 |
|
48 | var port = this.server.address().port;
|
49 | var self = this,
|
50 | httpTransport = new (winston.transports.Http)({
|
51 | host: host,
|
52 | port: port,
|
53 | path: 'log'
|
54 | });
|
55 |
|
56 | httpTransport.log('info', 'hello', function (logErr, logged) {
|
57 | self.mock.done(function (doneErr) {
|
58 | self.callback(null, logErr, logged, doneErr);
|
59 | });
|
60 | });
|
61 | },
|
62 | "should log to the specified URL": function (_, err, logged, requested) {
|
63 | assert.ifError(err);
|
64 | assert.isTrue(logged);
|
65 | assert.ifError(requested);
|
66 | this.server.close();
|
67 | }
|
68 | }
|
69 | }
|
70 | }).export(module);
|