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

test: increase test coverage for os.js #14098

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test: Resolve conflicts, remove aix test case
Remove it because after 2 months it was implemented actually.
Started with this PR though
  • Loading branch information
viktor-ku committed Sep 25, 2017
commit fdd278059bd6cd32467f5237441a9f8cd4b9422a
97 changes: 30 additions & 67 deletions test/parallel/test-os.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ const is = {
}
};

const flatten = (arr) =>
arr.reduce((acc, c) =>
acc.concat(Array.isArray(c) ? flatten(c) : c), []);

process.env.TMPDIR = '/tmpdir';
process.env.TMP = '/tmp';
process.env.TEMP = '/temp';
Expand Down Expand Up @@ -114,89 +118,48 @@ if (!common.isSunOS) {
}

const interfaces = os.networkInterfaces();
const local = (e) => e.address === '127.0.0.1';
switch (platform) {
case 'linux':
<<<<<<< HEAD
{
const filter =
(e) => e.address === '127.0.0.1' && e.netmask === '255.0.0.0';
case 'linux': {
const filter = (e) =>
e.address === '127.0.0.1' &&
e.netmask === '255.0.0.0';

const actual = interfaces.lo.filter(filter);
const expected = [{ address: '127.0.0.1', netmask: '255.0.0.0',
mac: '00:00:00:00:00:00', family: 'IPv4',
internal: true, cidr: '127.0.0.1/8' }];
const expected = [{
address: '127.0.0.1',
netmask: '255.0.0.0',
mac: '00:00:00:00:00:00',
family: 'IPv4',
internal: true,
cidr: '127.0.0.1/8'
}];
assert.deepStrictEqual(actual, expected);
break;
}
case 'win32':
{
const filter = (e) => e.address === '127.0.0.1';
case 'win32': {
const filter = (e) =>
e.address === '127.0.0.1';

const actual = interfaces['Loopback Pseudo-Interface 1'].filter(filter);
const expected = [{ address: '127.0.0.1', netmask: '255.0.0.0',
mac: '00:00:00:00:00:00', family: 'IPv4',
internal: true, cidr: '127.0.0.1/8' }];
const expected = [{
address: '127.0.0.1',
netmask: '255.0.0.0',
mac: '00:00:00:00:00:00',
family: 'IPv4',
internal: true,
cidr: '127.0.0.1/8'
}];
assert.deepStrictEqual(actual, expected);
break;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should add a default:

default:
  common.printSkipMessage(`Skipping assertion of 'os.networkInterfaces()' on ${platform}`);
  break;

}
function flatten(arr) {
return arr.reduce(
(acc, c) => acc.concat(Array.isArray(c) ? flatten(c) : c),
[]
);
=======
{
const actual = interfaces.lo.filter(local);
const expected = [{
address: '127.0.0.1',
netmask: '255.0.0.0',
mac: '00:00:00:00:00:00',
family: 'IPv4',
internal: true
}];
assert.deepStrictEqual(actual, expected);
break;
}
case 'win32':
{
const actual = interfaces['Loopback Pseudo-Interface 1'].filter(local);
const expected = [{
address: '127.0.0.1',
netmask: '255.0.0.0',
mac: '00:00:00:00:00:00',
family: 'IPv4',
internal: true
}];
assert.deepStrictEqual(actual, expected);
break;
}
case 'aix':
{
// This test will fail on aix by default
// Issue: https://github.com/nodejs/node/issues/14119
const lo0 = interfaces.lo0;
// There might not be a lo0 entry configured
if (!lo0) break;
const actual = lo0.filter(local);
// We cannot test mac field because it is non-zero
delete actual[0].mac;
const expected = [{
address: '127.0.0.1',
netmask: '0.0.0.1',
family: 'IPv4',
internal: true
}];
assert.deepStrictEqual(actual, expected);
break;
}
>>>>>>> test: add os.networkInterfaces test case for aix
}
const netmaskToCIDRSuffixMap = new Map(Object.entries({
'255.0.0.0': 8,
'255.255.255.0': 24,
'ffff:ffff:ffff:ffff::': 64,
'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff': 128
}));

flatten(Object.values(interfaces))
.map((v) => ({ v, mask: netmaskToCIDRSuffixMap.get(v.netmask) }))
.forEach(({ v, mask }) => {
Expand Down