UNPKG

1.79 kBJavaScriptView Raw
1/*
2 * http-test.js: Tests for instances of the HTTP transport
3 *
4 * MIT LICENSE
5 */
6
7var 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
16var transport = require('./transport');
17
18var host = '127.0.0.1';
19
20vows.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);