Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Enable IPv4 tests on Travis - fixes #22 #24

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const ipaddr = require('ipaddr.js');

function findIp(gateway) {
const interfaces = os.networkInterfaces();
console.log(interfaces);
const gatewayIp = ipaddr.parse(gateway);
let ip;

Expand All @@ -27,13 +28,15 @@ function findIp(gateway) {

function promise(family) {
return defaultGateway[family]().then(result => {
console.log(result);
return findIp(result.gateway) || null;
}).catch(() => null);
}

function sync(family) {
try {
const result = defaultGateway[family].sync();
console.log(result);
return findIp(result.gateway) || null;
} catch (error) {
return null;
Expand Down
18 changes: 6 additions & 12 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {isIPv4, isIPv6} from 'net';
import test from 'ava';
import internalIp from '.';

// Travis VMs don't have IPs on their interfaces
// https://docs.travis-ci.com/user/ci-environment/#Networking
// Travis VMs have no IPv6 interfaces
// https://docs.travis-ci.com/user/ip-addresses/
const isCI = Boolean(process.env.CI);

test('IPv6', async t => {
Expand All @@ -17,11 +17,8 @@ test('IPv6', async t => {

test('IPv4', async t => {
const ip = await internalIp.v4();
if (isCI) {
t.is(ip, null);
} else {
t.true(isIPv4(ip));
}
console.log(ip);
t.true(isIPv4(ip));
});

test('synchronous IPv6', t => {
Expand All @@ -35,9 +32,6 @@ test('synchronous IPv6', t => {

test('synchronous IPv4', t => {
const ip = internalIp.v4.sync();
if (isCI) {
t.is(ip, null);
} else {
t.true(isIPv4(ip));
}
console.log(ip);
t.true(isIPv4(ip));
});