-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Conversation
test/parallel/test-os.js
Outdated
@@ -116,8 +116,8 @@ const interfaces = os.networkInterfaces(); | |||
switch (platform) { | |||
case 'linux': | |||
{ | |||
const filter = (e) => e.address === '127.0.0.1'; | |||
const actual = interfaces.lo.filter(filter); | |||
const fltr = (e) => e.address === '127.0.0.1' && e.netmask === '255.0.0.0'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a big deal but FWIW, the fltr
const name is now inconsistent with the filter
used in the win32
case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you leave the name as filter
and just break the line on the &&
operator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cjihrig Sure, done.
test/parallel/test-os.js
Outdated
@@ -116,8 +116,8 @@ const interfaces = os.networkInterfaces(); | |||
switch (platform) { | |||
case 'linux': | |||
{ | |||
const filter = (e) => e.address === '127.0.0.1'; | |||
const actual = interfaces.lo.filter(filter); | |||
const fltr = (e) => e.address === '127.0.0.1' && e.netmask === '255.0.0.0'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you leave the name as filter
and just break the line on the &&
operator.
The check for `os.networkInterfaces()` in `test-os.js` may be too strict. It's apparently possible for a machine to be configured with multiple IPv4 loopback interfaces. Increase specificity of filter to check on only the object we expect. Fixes: nodejs#14654
@@ -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', |
There was a problem hiding this comment.
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']
There was a problem hiding this comment.
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-nothingdefault
for macos, smartos... A switch makes sense here, I think. I mean, you can make it work with anif
, 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.
👍
Apple SMH... |
Landed in 2923ed1 |
The check for `os.networkInterfaces()` in `test-os.js` may be too strict. It's apparently possible for a machine to be configured with multiple IPv4 loopback interfaces. Increase specificity of filter to check on only the object we expect. PR-URL: nodejs#14655 Fixes: nodejs#14654 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: James M Snell <[email protected]>
The check for `os.networkInterfaces()` in `test-os.js` may be too strict. It's apparently possible for a machine to be configured with multiple IPv4 loopback interfaces. Increase specificity of filter to check on only the object we expect. PR-URL: #14655 Fixes: #14654 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: James M Snell <[email protected]>
The check for `os.networkInterfaces()` in `test-os.js` may be too strict. It's apparently possible for a machine to be configured with multiple IPv4 loopback interfaces. Increase specificity of filter to check on only the object we expect. PR-URL: #14655 Fixes: #14654 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: James M Snell <[email protected]>
The check for
os.networkInterfaces()
intest-os.js
may be toostrict. It's apparently possible for a machine to be configured with
multiple IPv4 loopback interfaces. Increase specificity of filter to
check on only the object we expect.
Fixes: #14654
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
test os