HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux wordpress-ubuntu-s-2vcpu-4gb-fra1-01 5.4.0-169-generic #187-Ubuntu SMP Thu Nov 23 14:52:28 UTC 2023 x86_64
User: root (0)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/zaklada/html/node_modules/dev-ip/test/devip.js
"use strict";

var devIp = require("../lib/dev-ip");
var respNone = require("./fixtures/resp-none");
var respSingle = require("./fixtures/resp-single");
var respMultiple = require("./fixtures/resp-multiple");
var sinon = require("sinon");
var assert = require("chai").assert;
var os = require("os");

// From the resp files
var match1 = "10.104.103.181";
var match2 = "10.104.100.12";

var regex = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;

describe("Getting the IP with a single result", function () {
    var osStub;
    var result;
    before(function () {
        osStub = sinon.stub(os, "networkInterfaces").returns(respSingle);
    });
    beforeEach(function () {
        result = devIp(null);
    });
    after(function () {
        osStub.restore();
    });
    it("should return the IP when a single match found", function () {
        var expected = match1;
        assert.deepEqual(result, [expected]);
    });
    it("should return a string matching the regex", function () {
        var actual = regex.exec(result);
        assert.isNotNull(actual);
    });
});

describe("Getting the IP with Multiple results", function () {
    var osStub;
    var result;
    before(function () {
        osStub = sinon.stub(os, "networkInterfaces").returns(respMultiple);
    });
    beforeEach(function () {
        result = devIp(null);
    });
    after(function () {
        osStub.restore();
    });
    it("should return an array of results", function () {
        assert.equal(result[0], match1);
        assert.equal(result[1], match2);
    });
    it("should return a string matching the regex", function () {
        var actual = regex.exec(result[0]);
        assert.isNotNull(actual);
        actual = regex.exec(result[1]);
        assert.isNotNull(actual);
    });
});

describe("Getting the IP with no results", function () {
    var osStub;
    var result;
    before(function () {
        osStub = sinon.stub(os, "networkInterfaces").returns(respNone);
    });
    after(function () {
        osStub.restore();
    });
    it("should return empty array", function () {
        var actual = devIp();
        assert.isArray(actual);
        assert.equal(actual.length, 0);
    });
});