dns_uv: match the old api better, fix tests
authorBert Belder <bert@piscisaureus2.(none)>
Tue, 5 Jul 2011 19:16:13 +0000 (21:16 +0200)
committerBert Belder <bert@piscisaureus2.(none)>
Tue, 5 Jul 2011 19:17:17 +0000 (21:17 +0200)
src/cares_wrap.cc
test/internet/test-dns.js

index 3f610af..0194d3b 100644 (file)
@@ -431,7 +431,7 @@ class QuerySrvWrap: public QueryWrap {
     }
 
     Local<Array> srv_records = Array::New();
-    Local<String> host_symbol = String::NewSymbol("host");
+    Local<String> name_symbol = String::NewSymbol("name");
     Local<String> port_symbol = String::NewSymbol("port");
     Local<String> priority_symbol = String::NewSymbol("priority");
     Local<String> weight_symbol = String::NewSymbol("weight");
@@ -440,7 +440,7 @@ class QuerySrvWrap: public QueryWrap {
          srv_current;
          srv_current = srv_current->next) {
       Local<Object> srv_record = Object::New();
-      srv_record->Set(host_symbol, String::New(srv_current->host));
+      srv_record->Set(name_symbol, String::New(srv_current->host));
       srv_record->Set(port_symbol, Integer::New(srv_current->port));
       srv_record->Set(priority_symbol, Integer::New(srv_current->priority));
       srv_record->Set(weight_symbol, Integer::New(srv_current->weight));
index b833a35..746c206 100644 (file)
@@ -24,7 +24,8 @@ var assert = require('assert');
     net = require('net_uv');
     isIP = net.isIP,
     isIPv4 = net.isIPv4,
-    isIPv6 = net.isIPv6;
+    isIPv6 = net.isIPv6,
+    uv = process.useUV;
 
 var expected = 0,
     completed = 0,
@@ -58,12 +59,19 @@ function TEST(f) {
 
 
 process.on('exit', function() {
-  console.log(completed + " tests completed");
+  console.log(completed + ' tests completed (using libuv: ' + (!!uv) + ')');
   assert.equal(running, false);
   assert.strictEqual(expected, completed);
 });
 
 
+function checkWrap(req) {
+  if (uv) {
+    assert.ok(typeof req === 'object');
+  }
+}
+
+
 TEST(function test_resolve4(done) {
   var req = dns.resolve4('www.google.com', function(err, ips) {
     if (err) throw err;
@@ -77,7 +85,7 @@ TEST(function test_resolve4(done) {
     done();
   });
 
-  assert.ok(typeof req === 'object');
+  checkWrap(req);
 });
 
 
@@ -94,7 +102,7 @@ TEST(function test_resolve6(done) {
     done();
   });
 
-  assert.ok(typeof req === 'object');
+  checkWrap(req);
 });
 
 
@@ -112,7 +120,7 @@ TEST(function test_reverse_ipv4(done) {
     done();
   });
 
-  assert.ok(typeof req === 'object');
+  checkWrap(req);
 });
 
 
@@ -130,7 +138,7 @@ TEST(function test_reverse_ipv6(done) {
     done();
   });
 
-  assert.ok(typeof req === 'object');
+  checkWrap(req);
 });
 
 
@@ -146,7 +154,7 @@ TEST(function test_reverse_bogus(done) {
   }
 
   assert.ok(error instanceof Error);
-  assert.strictEqual(error.errno, "ENOTIMP");
+  uv && assert.strictEqual(error.errno, 'ENOTIMP');
 
   done();
 });
@@ -172,7 +180,7 @@ TEST(function test_resolveMx(done) {
     done();
   });
 
-  assert.ok(typeof req === 'object');
+  checkWrap(req);
 });
 
 
@@ -191,7 +199,7 @@ TEST(function test_resolveNs(done) {
     done();
   });
 
-  assert.ok(typeof req === 'object');
+  checkWrap(req);
 });
 
 
@@ -206,8 +214,8 @@ TEST(function test_resolveSrv(done) {
       assert.ok(item);
       assert.ok(typeof item === 'object');
 
-      assert.ok(item.host);
-      assert.ok(typeof item.host === 'string');
+      assert.ok(item.name);
+      assert.ok(typeof item.name === 'string');
 
       assert.ok(typeof item.port === 'number');
       assert.ok(typeof item.priority === 'number');
@@ -217,7 +225,7 @@ TEST(function test_resolveSrv(done) {
     done();
   });
 
-  assert.ok(typeof req === 'object');
+  checkWrap(req);
 });
 
 
@@ -236,7 +244,7 @@ TEST(function test_resolveCname(done) {
     done();
   });
 
-  assert.ok(typeof req === 'object');
+  checkWrap(req);
 });
 
 
@@ -249,7 +257,7 @@ TEST(function test_lookup_ipv4_explicit(done) {
     done();
   });
 
-  assert.ok(typeof req === 'object');
+  checkWrap(req);
 });
 
 
@@ -262,7 +270,7 @@ TEST(function test_lookup_ipv4_implicit(done) {
     done();
   });
 
-  assert.ok(typeof req === 'object');
+  checkWrap(req);
 });
 
 
@@ -275,7 +283,7 @@ TEST(function test_lookup_ipv6_explicit(done) {
     done();
   });
 
-  assert.ok(typeof req === 'object');
+  checkWrap(req);
 });
 
 
@@ -288,19 +296,20 @@ TEST(function test_lookup_ipv6_implicit(done) {
     done();
   });
 
-  assert.ok(typeof req === 'object');
+  checkWrap(req);
 });
 
 
 TEST(function test_lookup_failure(done) {
   var req = dns.lookup('does.not.exist', 4, function(err, ip, family) {
     assert.ok(err instanceof Error);
-    assert.strictEqual(err.errno, 'ENOTFOUND');
+    assert.strictEqual(err.errno, dns.NOTFOUND)
+    uv && assert.strictEqual(err.errno, 'ENOTFOUND');
 
     done();
   });
 
-  assert.ok(typeof req === 'object');
+  checkWrap(req);
 });
 
 
@@ -313,25 +322,25 @@ TEST(function test_lookup_null(done) {
     done();
   });
 
-  assert.ok(typeof req === 'object');
+  checkWrap(req);
 });
 
 
 TEST(function test_lookup_ip_ipv4(done) {
-  var req = dns.lookup("127.0.0.1", function(err, ip, family) {
+  var req = dns.lookup('127.0.0.1', function(err, ip, family) {
     if (err) throw err;
-    assert.strictEqual(ip, "127.0.0.1");
+    assert.strictEqual(ip, '127.0.0.1');
     assert.strictEqual(family, 4);
 
     done();
   });
 
-  assert.ok(typeof req === 'object');
+  checkWrap(req);
 });
 
 
 TEST(function test_lookup_ip_ipv6(done) {
-  var req = dns.lookup("::1", function(err, ip, family) {
+  var req = dns.lookup('::1', function(err, ip, family) {
     if (err) throw err;
     assert.ok(net.isIPv6(ip));
     assert.strictEqual(family, 6);
@@ -339,26 +348,26 @@ TEST(function test_lookup_ip_ipv6(done) {
     done();
   });
 
-  assert.ok(typeof req === 'object');
+  checkWrap(req);
 });
 
 
 TEST(function test_lookup_localhost_ipv4(done) {
-  var req = dns.lookup("localhost", 4, function(err, ip, family) {
+  var req = dns.lookup('localhost', 4, function(err, ip, family) {
     if (err) throw err;
-    assert.strictEqual(ip, "127.0.0.1");
+    assert.strictEqual(ip, '127.0.0.1');
     assert.strictEqual(family, 4);
 
     done();
   });
 
-  assert.ok(typeof req === 'object');
+  checkWrap(req);
 });
 
 
 /* Disabled because it appears to be not working on linux. */
 /* TEST(function test_lookup_localhost_ipv6(done) {
-  var req = dns.lookup("localhost", 6, function(err, ip, family) {
+  var req = dns.lookup('localhost', 6, function(err, ip, family) {
     if (err) throw err;
     assert.ok(net.isIPv6(ip));
     assert.strictEqual(family, 6);
@@ -366,5 +375,5 @@ TEST(function test_lookup_localhost_ipv4(done) {
     done();
   });
 
-  assert.ok(typeof req === 'object');
+  checkWrap(req);
 }); */