<commit_before>// Load modules

var Hapi = require('hapi');
var Code = require('code');
var Lab = require('lab');
var University = require('../lib');
var Version = require('../lib/version');
var Path = require('path');

//declare internals

var internals = {};

// Test shortcuts

var lab = exports.lab = Lab.script();
var expect = Code.expect;
var it = lab.test;


it('starts server and returns hapi server object', function (done) {

    University.init({}, {}, function (err, server) {

        expect(err).to.not.exist();
        expect(server).to.be.instanceof(Hapi.Server);

        server.stop(done);
    });
});

it('starts server on provided port', function (done) {

    University.init({connections: [{port: 5000}]}, {}, function (err, server) {

        expect(err).to.not.exist();
        expect(server.info.port).to.equal(5000);

        server.stop(done);
    });
});

it('handles register plugin errors', { parallel: false }, function (done) {

    var orig = Version.register;
    Version.register = function (server, options, next) {

        Version.register = orig;
        return next(new Error('register version failed'));
    };

    Version.register.attributes = {
        name: 'fake version'
    };

    University.init(internals.manifest, internals.composeOptions, function (err, server) {

        expect(err).to.exist();
        expect(err.message).to.equal('register version failed');

        done();
    });
});

internals.manifest = {
    connections: [
        {
            port: 0
        }
    ],
    plugins: {
        './version': {}
    }
};

internals.composeOptions = {
    relativeTo: Path.resolve(__dirname, '../lib')
};<commit_msg>Bringing coverage to 100%, without being rigorous<commit_after>// Load modules

var Hapi = require('hapi');
var Code = require('code');
var Lab = require('lab');
var University = require('../lib');
var Version = require('../lib/version');
var Path = require('path');
var Config = require('../lib/config');

//declare internals

var internals = {};

// Test shortcuts

var lab = exports.lab = Lab.script();
var describe = lab.experiment;
var expect = Code.expect;
var it = lab.test;

describe('/index', function () {
    it('starts server and returns hapi server object', function (done) {

        University.init({}, {}, function (err, server) {

            expect(err).to.not.exist();
            expect(server).to.be.instanceof(Hapi.Server);

            server.stop(done);
        });
    });

    it('starts server on provided port', function (done) {

        University.init({connections: [{port: 5000}]}, {}, function (err, server) {

            expect(err).to.not.exist();
            expect(server.info.port).to.equal(5000);

            server.stop(done);
        });
    });

    it('handles register plugin errors', { parallel: false }, function (done) {

        var orig = Version.register;
        Version.register = function (server, options, next) {

            Version.register = orig;
            return next(new Error('register version failed'));
        };

        Version.register.attributes = {
            name: 'fake version'
        };

        University.init(internals.manifest, internals.composeOptions, function (err, server) {

            expect(err).to.exist();
            expect(err.message).to.equal('register version failed');

            done();
        });
    });

    it('forces re-routing to https', function(done) {

        University.init(internals.manifest, internals.composeOptions, function (err, server) {

            server.inject('/version', function (res) {

                expect(res.statusCode).to.equal(301);
                server.stop(done);
            });
        });
    });

    internals.manifest = {
        connections: [
        {
            host: 'localhost',
            port: 0,
            labels: ['web']
        },
            {
                host: 'localhost',
                port: 0,
                labels: ['web-tls'],
                tls: Config.tls
            }
        ],
        plugins: {
            './version': {}
        }
    };
});

internals.composeOptions = {
    relativeTo: Path.resolve(__dirname, '../lib')
};
{'fraction_non_alphanumeric': 0.1589878252566245, 'fraction_numerical': 0.005968011458582, 'mean_word_length': 2.2430340557275543, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1401498', 'n_tokens_mistral': 1228, 'n_tokens_neox': 1154, 'n_words': 273}