text: /*
   * Copyright (c) 2020 Pangeanic SL.
   *
   * This file is part of NEC TM
   * (see https://github.com/shasha79/nectm).
   *
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
   * with the License.  You may obtain a copy of the License at
   *
   *   http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing,
   * software distributed under the License is distributed on an
   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   * KIND, either express or implied.  See the License for the
   * specific language governing permissions and limitations
   * under the License.
   */
  
  var path = require('path'),
      http = require('http'),
      fs = require('fs'),
      hock = require('hock'),
      assume = require('assume'),
      Http = require('../../lib/winston/transports/http'),
      helpers = require('../helpers');
  
  var host = '127.0.0.1';
  
  function mockHttpServer(opts, done) {
    if (!done && typeof opts === 'function') {
      done = opts;
      opts = {};
    }
  
    var mock = hock.createHock();
    opts.path = opts.path || 'log';
    opts.payload = opts.payload || {
      level: 'info',
      message: 'hello',
      meta: {}
    };
  
    mock
      .post('/' + opts.path, opts.payload)
      .min(1)
      .max(1)
      .reply(200);
  
    var server = http.createServer(mock.handler);
    server.listen(0, '0.0.0.0', done);
    return { server, mock };
  }
  
  describe('Http({ host, port, path })', function () {
    var context;
    var server;
    beforeEach(function (done) {
      context = mockHttpServer(done);
      server = context.server;
    });
  
    it('should send logs over HTTP', function (done) {
      var port = server.address().port;
      var httpTransport = new Http({
        host: host,
        port: port,
        path: 'log'
      }).on('error', function (err) {
        assume(err).falsy();
      }).on('logged', function () {
        context.mock.done(function (err) {
          if (err) { assume(err).falsy(); }
          done();
        });
      });
  
      httpTransport.log({
        level: 'info',
        message: 'hello',
        meta: {}
      }, function (err) {
        if (err) { assume(err).falsy(); }
      });
    });
  
    afterEach(function (done) {
      server.close(done.bind(null, null));
    });
  });
  