summaryrefslogtreecommitdiff
path: root/node_modules/winston/test/transports/http-test.js
blob: 65f3cc72ce85a9c7dd27da5a400f9f1e90ed34fe (plain)
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
/*
 * http-test.js: Tests for instances of the HTTP transport
 *
 * MIT LICENSE
 */

var path = require('path'),
    vows = require('vows'),
    http = require('http'),
    fs = require('fs'),
    assert = require('assert'),
    winston = require('../../lib/winston'),
    helpers = require('../helpers'),
    hock = require('hock');

var transport = require('./transport');

var host = '127.0.0.1';

vows.describe('winston/transports/http').addBatch({
  "When the HTTP endpoint": {
    topic: function () {
      var mock = this.mock = hock.createHock(),
          self = this;

        mock
          .post('/log', {
            "method":"collect",
            "params":{
              "level":"info",
              "message":"hello",
              "meta":{}
            }
          })
          .min(1)
          .max(1)
          .reply(200);

      var server = this.server = http.createServer(mock.handler);
      server.listen(0, '0.0.0.0', this.callback);
    },
    "is running": function (err) {
      assert.ifError(err);
    },
    "an instance of the Http transport": {
      topic: function () {

      var port = this.server.address().port;
        var self = this,
            httpTransport = new (winston.transports.Http)({
              host: host,
              port: port,
              path: 'log'
            });

        httpTransport.log('info', 'hello', function (logErr, logged) {
          self.mock.done(function (doneErr) {
            self.callback(null, logErr, logged, doneErr);
          });
        });
      },
      "should log to the specified URL": function (_, err, logged, requested) {
        assert.ifError(err);
        assert.isTrue(logged);
        assert.ifError(requested);
        this.server.close();
      }
    }
  }
}).export(module);