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: improve check in test-os #14655

Closed
wants to merge 1 commit into from
Closed
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: 2 additions & 1 deletion test/parallel/test-os.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ const interfaces = os.networkInterfaces();
switch (platform) {
case 'linux':
{
const filter = (e) => e.address === '127.0.0.1';
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',
Copy link
Contributor

Choose a reason for hiding this comment

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

[warning 🚨 scope-creep]
AFAICT expected and the asserting could be hoisted, and switch replaced with if or trinary for selecting interfaces.lo / interfaces['Loopback Pseudo-Interface 1']

Copy link
Member Author

Choose a reason for hiding this comment

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

Some reasons to maybe not do that:

  • If we want to add macOS to the switch statement (in another PR), it will have a different expected value. (The MAC address is different. Yes, the MAC address is different on Mac. Ha ha, ha ha, gosh, I'm funny.)

  • Probably don't want to replace the switch because we need a do-nothing default for macos, smartos... A switch makes sense here, I think. I mean, you can make it work with an if, of course. But I think this more verbose code is actually more readable even though it does violate DRY. (I often don't value DRY much in tests, TBH.)

Even if I'm wrong about that evaluation... must...resist....scope creep.

mac: '00:00:00:00:00:00', family: 'IPv4',
Expand Down