diff options
author | Rich Trott <rtrott@gmail.com> | 2016-05-11 23:03:24 -0700 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2016-05-13 22:33:56 -0700 |
commit | 1a0c80a1da361b46e45ad6c4478233cc70155761 (patch) | |
tree | 552d4115826902bd278045dedf9b08d83319077e /test/internet | |
parent | 517d1da47c97851967db78f1b267434c59dd6830 (diff) | |
download | node-new-1a0c80a1da361b46e45ad6c4478233cc70155761.tar.gz |
test: remove common.getServiceName()
Replace lightly-used services file parsing in favor of
confirming one of a small number of allowable values in service name
lookup tests.
In https://github.com/nodejs/node-v0.x-archive/issues/8047, it was
decided that this sort of service file parsing was superior to
hardcoding acceptable values, but I'm not convinced:
* No guarantee that the host uses /etc/services before, e.g., nscd.
* Increases complexity of tests without guaranteeing robustness.
I think that simply checking against a small set of expected values
may be a better solution. Ideally, there would also be a unit test that
used a test double for the appropriate `cares` function and confirms
that it is called with the correct parameters, but now we're getting way
ahead of ourselves.
PR-URL: https://github.com/nodejs/node/pull/6709
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'test/internet')
-rw-r--r-- | test/internet/test-dns-ipv4.js | 21 | ||||
-rw-r--r-- | test/internet/test-dns-ipv6.js | 19 |
2 files changed, 3 insertions, 37 deletions
diff --git a/test/internet/test-dns-ipv4.js b/test/internet/test-dns-ipv4.js index 0781496392..06c1056a26 100644 --- a/test/internet/test-dns-ipv4.js +++ b/test/internet/test-dns-ipv4.js @@ -1,5 +1,5 @@ 'use strict'; -const common = require('../common'); +require('../common'); const assert = require('assert'); const dns = require('dns'); const net = require('net'); @@ -173,24 +173,7 @@ TEST(function test_lookupservice_ip_ipv4(done) { if (err) throw err; assert.equal(typeof host, 'string'); assert(host); - - /* - * Retrieve the actual HTTP service name as setup on the host currently - * running the test by reading it from /etc/services. This is not ideal, - * as the service name lookup could use another mechanism (e.g nscd), but - * it's already better than hardcoding it. - */ - var httpServiceName = common.getServiceName(80, 'tcp'); - if (!httpServiceName) { - /* - * Couldn't find service name, reverting to the most sensible default - * for port 80. - */ - httpServiceName = 'http'; - } - - assert.strictEqual(service, httpServiceName); - + assert(['http', 'www', '80'].includes(service)); done(); }); diff --git a/test/internet/test-dns-ipv6.js b/test/internet/test-dns-ipv6.js index 2929361f16..a9e46c8478 100644 --- a/test/internet/test-dns-ipv6.js +++ b/test/internet/test-dns-ipv6.js @@ -182,24 +182,7 @@ TEST(function test_lookupservice_ip_ipv6(done) { if (err) throw err; assert.equal(typeof host, 'string'); assert(host); - - /* - * Retrieve the actual HTTP service name as setup on the host currently - * running the test by reading it from /etc/services. This is not ideal, - * as the service name lookup could use another mechanism (e.g nscd), but - * it's already better than hardcoding it. - */ - var httpServiceName = common.getServiceName(80, 'tcp'); - if (!httpServiceName) { - /* - * Couldn't find service name, reverting to the most sensible default - * for port 80. - */ - httpServiceName = 'http'; - } - - assert.strictEqual(service, httpServiceName); - + assert(['http', 'www', '80'].includes(service)); done(); }); |