var dns = require('dns')
  , util = require('util')
  , utils = require('./utils')

var exports = module.exports = function(authority) {
  if (authority !== undefined) throw Error('Authority not implemented')

  return {
    a: testType(authority, 'a'),
    aaaa: testType(authority, 'aaaa'),
    cname: testType(authority, 'cname'),
    mx: testType(authority, 'mx'),
    ns: testType(authority, 'ns'),
    ptr: testType(authority, 'ptr'),
    srv: testType(authority, 'srv'),
    txt: testType(authority, 'txt'),
  }
}

var asserts = exports.asserts = {
  address: function(res, address) {
    this.ok(typeof(res) === 'object' &&
      (res.type == 'a' || res.type == 'aaaa') &&
      Array.isArray(res.answer) && res.answer.length > 0 &&
      res.answer.indexOf(address) >= 0,
      'Address "' + address + '" in ' + JSON.stringify(res.answer))
  },
  name: function(res, name) {
    this.ok(typeof(res) === 'object' &&
      (res.type == 'cname' || res.type == 'ns' || res.type == 'ptr') &&
      Array.isArray(res.answer) && res.answer.length > 0 &&
      res.answer.indexOf(name) >= 0, 'Name "' + name + '" in ' + JSON.stringify(res.answer))
  },
}

var testType = function(authority, type) {
  return function() {
    var baseArgs = Array.prototype.slice.call(arguments)
      , baseUri = 'dns:' + (authority !== undefined ? '//' + authority + '/' : '')
      , name = [baseUri + baseArgs[0] + '?type=' + type].join(utils.SEP)

    // add test to module
    return function(test) {
      var args = Array.prototype.slice.call(baseArgs)
      args.unshift(authority)
      args.unshift(type)
      args.unshift(test)
      exports.resolve.apply(this, args)
    }
  }
}

exports.resolve = function(/* test, type, authority, domain, [opts], callback */) {
  var test = arguments[0]
    , type = arguments[1]
    , authority = arguments[2]
    , domain = arguments[3]
    , opts = {}
    , callback = null

  if (arguments.length == 6) {
    opts = arguments[4]
    callback = arguments[5]
  } else {
    callback = arguments[4]
  }

  for (var a in asserts) {
    if (!test.hasOwnProperty(a)) test[a] = asserts[a]
  }

  dns.resolve(domain, type.toUpperCase(), function(err, answer) {
    if (err) {
      test.ok(false, err)
      return test.done()
    }
    callback(test, { answer: answer, type: type })
  })
}

@@ -121,27 +121,153 @@
 ion(
-authority) %7B
+opts) %7B%0A  if (opts === undefined) %7B%0A    opts = %7B%7D%0A  %7D else if (typeof(opts) === 'string') %7B%0A    opts = opts = %7B authority: opts %7D%0A  %7D
 %0A  if (
+opts.
 auth
@@ -352,33 +352,28 @@
 a: testType(
-authority
+opts
 , 'a'),%0A    
@@ -387,25 +387,20 @@
 estType(
-authority
+opts
 , 'aaaa'
@@ -422,25 +422,20 @@
 estType(
-authority
+opts
 , 'cname
@@ -455,25 +455,20 @@
 estType(
-authority
+opts
 , 'mx'),
@@ -485,25 +485,20 @@
 estType(
-authority
+opts
 , 'ns'),
@@ -516,25 +516,20 @@
 estType(
-authority
+opts
 , 'ptr')
@@ -548,25 +548,20 @@
 estType(
-authority
+opts
 , 'srv')
@@ -580,25 +580,20 @@
 estType(
-authority
+opts
 , 'txt')
@@ -1260,25 +1260,26 @@
 unction(
-authority
+parentOpts
 , type) 
@@ -1302,97 +1302,142 @@
 ion(
-) %7B%0A    var baseArgs = Array.prototype.slice.call(arguments)%0A      , baseUri = 'dns:' + (
+opts, callback) %7B%0A    if (typeof(opts) === 'string') opts = %7B domain: opts %7D%0A    opts.type = type%0A    opts.uri = 'dns:' +%0A      (opts.
 auth
@@ -1465,16 +1465,21 @@
  '//' + 
+opts.
 authorit
@@ -1495,46 +1495,28 @@
  '')
+ +
 %0A      
-, name = %5BbaseUri + baseArgs%5B0%5D
+opts.domain
  + '
@@ -1533,25 +1533,8 @@
 type
-%5D.join(utils.SEP)
 %0A%0A  
@@ -1595,174 +1595,44 @@
     
-var args = Array.prototype.slice.call(baseArgs)%0A      args.unshift(authority)%0A      args.unshift(type)%0A      args.unshift(test)%0A      exports.resolve.apply(this, args
+exports.resolve(test, opts, callback
 )%0A  
@@ -1673,48 +1673,18 @@
 ion(
-/* 
 test, 
-type, authority, domain, %5B
 opts
-%5D
 , ca
@@ -1693,291 +1693,11 @@
 back
- */) %7B%0A  var test = arguments%5B0%5D%0A    , type = arguments%5B1%5D%0A    , authority = arguments%5B2%5D%0A    , domain = arguments%5B3%5D%0A    , opts = %7B%7D%0A    , callback = null%0A%0A  if (arguments.length == 6) %7B%0A    opts = arguments%5B4%5D%0A    callback = arguments%5B5%5D%0A  %7D else %7B%0A    callback = arguments%5B4%5D%0A  %7D%0A
+) %7B
 %0A  f
@@ -1797,16 +1797,21 @@
 lve(
+opts.
 domain, 
 type
@@ -1806,16 +1806,21 @@
 domain, 
+opts.
 type.toU
@@ -1970,16 +1970,21 @@
 , type: 
+opts.
 type %7D)%0A

Convert dns to opts based parameters