diff --git a/README.md b/README.md index e055c233a..37d0eb82d 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ The following core Node.js modules (v8.7.0+) have been implemented: | [console](https://nodejs.org/api/console.html) | :heavy_check_mark: | | [crypto](https://nodejs.org/api/crypto.html) | :heavy_check_mark: | | [dgram](https://nodejs.org/api/dgram.html) | | -| [dns](https://nodejs.org/api/dns.html) | | +| [dns](https://nodejs.org/api/dns.html) | :heavy_check_mark: | | [events](https://nodejs.org/api/events.html) | | | [fs](https://nodejs.org/api/fs.html) | :heavy_check_mark: | | [http](https://nodejs.org/api/http.html) | | diff --git a/app/current/src/main/scala/io/scalajs/nodejs/dns/DNS.scala b/app/current/src/main/scala/io/scalajs/nodejs/dns/DNS.scala index 27ca06371..22a805225 100644 --- a/app/current/src/main/scala/io/scalajs/nodejs/dns/DNS.scala +++ b/app/current/src/main/scala/io/scalajs/nodejs/dns/DNS.scala @@ -13,16 +13,7 @@ import scala.scalajs.js.| * @see https://nodejs.org/api/dns.html */ @js.native -trait DNS extends js.Object { - - ///////////////////////////////////////////////////////////////////////////////// - // Methods - ///////////////////////////////////////////////////////////////////////////////// - - /** - * Returns an array of IP address strings that are being used for name resolution. - */ - def getServers(): js.Array[String] = js.native +trait DNS extends IResolver { /** * Resolves a hostname (e.g. 'nodejs.org') into the first found A (IPv4) or AAAA (IPv6) record. options can be an @@ -42,7 +33,7 @@ trait DNS extends js.Object { * All properties are optional. * @example dns.lookup(hostname[, options], callback) */ - def lookup(hostname: String, options: DnsOptions | Int, callback: DnsCallback1[String]): Unit = js.native + def lookup(hostname: String, options: DnsOptions | Int, callback: DnsCallback2[String, Int]): Unit = js.native /** * Resolves a hostname (e.g. 'nodejs.org') into the first found A (IPv4) or AAAA (IPv6) record. options can be an @@ -79,156 +70,6 @@ trait DNS extends js.Object { * @example dns.lookupService('127.0.0.1', 22, (err, hostname, service) => { ... }) */ def lookupService(address: String, port: Int, callback: DnsCallback2[String, String]): Unit = js.native - - /** - * Uses the DNS protocol to resolve a hostname (e.g. 'nodejs.org') into an array of the record types specified by rrtype. - * On error, err is an Error object, where err.code is one of the error codes listed here. - * @param hostname the hostname - * @param rrtype the given rrtype - * Valid values for rrtype are: - * 'A' - IPV4 addresses, default - * 'AAAA' - IPV6 addresses - * 'MX' - mail exchange records - * 'TXT' - text records - * 'SRV' - SRV records - * 'PTR' - PTR records - * 'NS' - name server records - * 'CNAME' - canonical name records - * 'SOA' - start of authority record - * 'NAPTR' - name authority pointer record - * @param callback the callback function has arguments (err, addresses). When successful, addresses will be an array. - * The type of each item in addresses is determined by the record type, and described in the - * documentation for the corresponding lookup methods. - * @example dns.resolve(hostname[, rrtype], callback) - */ - def resolve[A](hostname: String, rrtype: RRType, callback: DnsCallback1[A]): Unit = js.native - - /** - * Uses the DNS protocol to resolve a hostname (e.g. 'nodejs.org') into an array of the record types specified by rrtype. - * On error, err is an Error object, where err.code is one of the error codes listed here. - * @param hostname the hostname - * @param callback the callback function has arguments (err, addresses). When successful, addresses will be an array. The type of - * each item in addresses is determined by the record type, and described in the documentation for the corresponding - * lookup methods. - * @example dns.resolve(hostname[, rrtype], callback) - */ - def resolve(hostname: String, callback: DnsCallback1[js.Array[String]]): Unit = js.native - - /** - * Uses the DNS protocol to resolve a IPv4 addresses (A records) for the hostname. The addresses argument passed to - * the callback function will contain an array of IPv4 addresses (e.g. ['74.125.79.104', '74.125.79.105', '74.125.79.106']). - * @example dns.resolve4(hostname, callback) - */ - def resolve4(hostname: String, callback: DnsCallback1[js.Array[String]]): Unit = js.native - - /** - * Uses the DNS protocol to resolve a IPv6 addresses (AAAA records) for the hostname. The addresses argument passed - * to the callback function will contain an array of IPv6 addresses. - * @example dns.resolve6(hostname, callback) - */ - def resolve6(hostname: String, callback: DnsCallback1[js.Array[String]]): Unit = js.native - - /** - * Uses the DNS protocol to resolve CNAME records for the hostname. The addresses argument passed to the callback - * function will contain an array of canonical name records available for the hostname (e.g. ['bar.example.com']). - * @example dns.resolveCname(hostname, callback) - */ - def resolveCname(hostname: String, callback: DnsCallback1[js.Array[String]]): Unit = js.native - - /** - * Uses the DNS protocol to resolve mail exchange records (MX records) for the hostname. The addresses argument - * passed to the callback function will contain an array of objects containing both a priority and exchange property - * (e.g. [{priority: 10, exchange: 'mx.example.com'}, ...]). - * @example dns.resolveMx(hostname, callback) - */ - def resolveMx(hostname: String, callback: DnsCallback1[MX]): Unit = js.native - - /** - * Uses the DNS protocol to resolve regular expression based records (NAPTR records) for the hostname. The callback - * function has arguments (err, addresses). The addresses argument passed to the callback function will contain an - * array of objects with the following properties: - * - * @example dns.resolveNaptr(hostname, callback) - */ - def resolveNaptr(hostname: String, callback: DnsCallback1[NAPTR]): Unit = js.native - - /** - * Uses the DNS protocol to resolve name server records (NS records) for the hostname. The addresses argument passed - * to the callback function will contain an array of name server records available for hostname - * (e.g., ['ns1.example.com', 'ns2.example.com']). - * @example dns.resolveNs(hostname, callback) - */ - def resolveNs(hostname: String, callback: DnsCallback1[js.Array[String]]): Unit = js.native - - /** - * Uses the DNS protocol to resolve a start of authority record (SOA record) for the hostname. The addresses argument - * passed to the callback function will be an object with the following properties: - * - * @example dns.resolveSoa(hostname, callback) - */ - def resolveSoa(hostname: String, callback: DnsCallback1[SOA]): Unit = js.native - - /** - * Uses the DNS protocol to resolve service records (SRV records) for the hostname. The addresses argument passed to - * the callback function will be an array of objects with the following properties: - * - * @example dns.resolveSrv(hostname, callback) - */ - def resolveSrv(hostname: String, callback: DnsCallback1[SRV]): Unit = js.native - - /** - * Uses the DNS protocol to resolve pointer records (PTR records) for the hostname. The addresses argument passed to - * the callback function will be an array of strings containing the reply records. - * @example dns.resolvePtr(hostname, callback) - */ - def resolvePtr(hostname: String, callback: DnsCallback1[js.Array[String]]): Unit = js.native - - /** - * Uses the DNS protocol to resolve text queries (TXT records) for the hostname. The addresses argument passed to the - * callback function is is a two-dimentional array of the text records available for hostname - * (e.g., [ ['v=spf1 ip4:0.0.0.0 ', '~all' ] ]). Each sub-array contains TXT chunks of one record. Depending on the - * use case, these could be either joined together or treated separately. - * @example dns.resolveTxt(hostname, callback) - */ - def resolveTxt(hostname: String, callback: DnsCallback1[js.Array[js.Array[String]]]): Unit = js.native - - /** - * Performs a reverse DNS query that resolves an IPv4 or IPv6 address to an array of hostnames. - * The callback function has arguments (err, hostnames), where hostnames is an array of resolved hostnames for the given ip. - * On error, err is an Error object, where err.code is one of the DNS error codes. - * @example dns.reverse(ip, callback) - */ - def reverse(ipAddress: String, callback: DnsCallback1[js.Array[String]]): Unit = js.native - - /** - * Sets the IP addresses of the servers to be used when resolving. The servers argument is an array of IPv4 or IPv6 addresses. - * If a port specified on the address it will be removed. - * An error will be thrown if an invalid address is provided. - * The dns.setServers() method must not be called while a DNS query is in progress. - * @example dns.setServers(servers) - */ - def setServers(servers: js.Array[String]): Unit = js.native - } /** @@ -238,6 +79,11 @@ trait DNS extends js.Object { @JSImport("dns", JSImport.Namespace) object DNS extends DNS { + @js.native + object promises extends js.Object { + type Resolver = PromisesResolver + } + ///////////////////////////////////////////////////////////////////////////////// // Error Codes ///////////////////////////////////////////////////////////////////////////////// diff --git a/app/current/src/main/scala/io/scalajs/nodejs/dns/DnsOptions.scala b/app/current/src/main/scala/io/scalajs/nodejs/dns/DnsOptions.scala index d366e60dc..5f7c7152c 100644 --- a/app/current/src/main/scala/io/scalajs/nodejs/dns/DnsOptions.scala +++ b/app/current/src/main/scala/io/scalajs/nodejs/dns/DnsOptions.scala @@ -2,17 +2,8 @@ package io.scalajs.nodejs.dns import scala.scalajs.js -/** - * DNS Options - * @param family The record family. If present, must be the integer 4 or 6. If not provided, both IP v4 - * and v6 addresses are accepted. - * @param hints If present, it should be one or more of the supported getaddrinfo flags. If hints is not - * provided, then no flags are passed to getaddrinfo. Multiple flags can be passed through hints by logically - * ORing their values. See supported getaddrinfo flags for more information on supported flags. - * @param all When true, the callback returns all resolved addresses in an array, otherwise returns a - * single address. Defaults to false. - */ class DnsOptions(var family: js.UndefOr[Int] = js.undefined, var hints: js.UndefOr[Int] = js.undefined, - var all: js.UndefOr[Boolean] = js.undefined) + var all: js.UndefOr[Boolean] = js.undefined, + var verbatim: js.UndefOr[Boolean] = js.undefined) extends js.Object diff --git a/app/current/src/main/scala/io/scalajs/nodejs/dns/MX.scala b/app/current/src/main/scala/io/scalajs/nodejs/dns/MX.scala deleted file mode 100644 index 2e3e1fd0f..000000000 --- a/app/current/src/main/scala/io/scalajs/nodejs/dns/MX.scala +++ /dev/null @@ -1,18 +0,0 @@ -package io.scalajs.nodejs.dns - -import scala.scalajs.js - -/** - * Represents an MX record. - *
-  * {
-  * exchange: 'bing-com.mail.protection.outlook.com',
-  * priority: 10
-  * }
-  * 
- */ -@js.native -trait MX extends js.Object { - var exchange: String = js.native - var priority: Integer = js.native -} diff --git a/app/current/src/main/scala/io/scalajs/nodejs/dns/NAPTR.scala b/app/current/src/main/scala/io/scalajs/nodejs/dns/NAPTR.scala deleted file mode 100644 index 3dc7bc81d..000000000 --- a/app/current/src/main/scala/io/scalajs/nodejs/dns/NAPTR.scala +++ /dev/null @@ -1,26 +0,0 @@ -package io.scalajs.nodejs.dns - -import scala.scalajs.js - -/** - * Represents a DNS NAPTR record. - *
-  * {
-  * flags: "s",
-  * service: "SIP+D2U",
-  * regexp: "",
-  * replacement: "_sip._udp.example.com",
-  * order: 30,
-  * preference: 100
-  * }
-  * 
- */ -@js.native -trait NAPTR extends js.Object { - var flags: String = js.native - var service: String = js.native - var regexp: String = js.native - var replacement: String = js.native - var order: Integer = js.native - var preference: Integer = js.native -} diff --git a/app/current/src/main/scala/io/scalajs/nodejs/dns/PromiseResolver.scala b/app/current/src/main/scala/io/scalajs/nodejs/dns/PromiseResolver.scala new file mode 100644 index 000000000..f26e98f67 --- /dev/null +++ b/app/current/src/main/scala/io/scalajs/nodejs/dns/PromiseResolver.scala @@ -0,0 +1,29 @@ +package io.scalajs.nodejs.dns + +import com.thoughtworks.enableMembersIf + +import scala.scalajs.js +import scala.scalajs.js.annotation.JSImport + +@js.native +@enableMembersIf(io.scalajs.nodejs.CompilerSwitches.gteNodeJs10) +@JSImport("dns", "promises.Resolver") +class PromisesResolver extends js.Object { + def getServers(): js.Array[String] = js.native + def setServers(servers: js.Array[String]): Unit = js.native + + def resolve(hostname: String, rrtype: RRType): js.Promise[ResolveResult] = js.native + def resolve(hostname: String): js.Promise[js.Array[String]] = js.native + def resolve4(hostname: String, options: TtlOptions = js.native): js.Promise[js.Array[String]] = js.native + def resolve6(hostname: String, options: TtlOptions = js.native): js.Promise[js.Array[String]] = js.native + def resolveAny(hostname: String): js.Promise[js.Array[ResolveObject]] = js.native + def resolveCname(hostname: String): js.Promise[js.Array[String]] = js.native + def resolveMx(hostname: String): js.Promise[js.Array[MX]] = js.native + def resolveNaptr(hostname: String): js.Promise[js.Array[NAPTR]] = js.native + def resolveNs(hostname: String): js.Promise[js.Array[String]] = js.native + def resolveSoa(hostname: String): js.Promise[js.Array[SOA]] = js.native + def resolveSrv(hostname: String): js.Promise[js.Array[SRV]] = js.native + def resolvePtr(hostname: String): js.Promise[js.Array[String]] = js.native + def resolveTxt(hostname: String): js.Promise[js.Array[String]] = js.native + def reverse(ipAddress: String): js.Promise[js.Array[String]] = js.native +} diff --git a/app/current/src/main/scala/io/scalajs/nodejs/dns/ResolveObject.scala b/app/current/src/main/scala/io/scalajs/nodejs/dns/ResolveObject.scala new file mode 100644 index 000000000..7b67c9fa6 --- /dev/null +++ b/app/current/src/main/scala/io/scalajs/nodejs/dns/ResolveObject.scala @@ -0,0 +1,58 @@ +package io.scalajs.nodejs.dns + +import scala.scalajs.js + +@js.native +sealed trait ResolveObject extends js.Object {} + +@js.native +trait AddressTtl extends ResolveObject { + val address: String = js.native + val ttl: Int = js.native +} + +@js.native +trait ValueOnly extends ResolveObject { + val value: String = js.native +} + +@js.native +trait MX extends ResolveObject { + val priority: Int = js.native + val exchange: String = js.native +} + +@js.native +trait NAPTR extends ResolveObject { + val flags: String = js.native + val service: String = js.native + val regexp: String = js.native + val replacement: String = js.native + val order: Int = js.native + val preference: Int = js.native +} + +@js.native +trait SOA extends ResolveObject { + val nsname: String = js.native + val hostmaster: String = js.native + val serial: Int = js.native + val refresh: Int = js.native + val retry: Int = js.native + val expire: Int = js.native + val minttl: Int = js.native +} + +@js.native +trait SRV extends ResolveObject { + val name: String = js.native + val priority: Int = js.native + val port: Int = js.native + val weight: Int = js.native +} + +@js.native +trait TXT extends ResolveObject { + val `type`: String = js.native + val entires: js.Array[js.Array[String]] = js.native +} diff --git a/app/current/src/main/scala/io/scalajs/nodejs/dns/Resolver.scala b/app/current/src/main/scala/io/scalajs/nodejs/dns/Resolver.scala new file mode 100644 index 000000000..8a4e2b5b0 --- /dev/null +++ b/app/current/src/main/scala/io/scalajs/nodejs/dns/Resolver.scala @@ -0,0 +1,48 @@ +package io.scalajs.nodejs.dns + +import scala.scalajs.js +import scala.scalajs.js.annotation.JSImport + +@js.native +@JSImport("dns", "Resolver") +class Resolver extends IResolver { + def cancel(): Unit = js.native +} + +@js.native +trait IResolver extends js.Object { + + def getServers(): js.Array[String] = js.native + + def resolve(hostname: String, rrtype: RRType, callback: DnsCallback1[ResolveResult]): Unit = + js.native + def resolve(hostname: String, callback: DnsCallback1[js.Array[String]]): Unit = js.native + + def resolve4(hostname: String, options: TtlOptions, callback: DnsCallback1[js.Array[String]]): Unit = js.native + def resolve4(hostname: String, callback: DnsCallback1[js.Array[String]]): Unit = js.native + + def resolve6(hostname: String, callback: DnsCallback1[js.Array[String]]): Unit = js.native + def resolve6(hostname: String, options: TtlOptions, callback: DnsCallback1[js.Array[String]]): Unit = js.native + + def resolveAny(hostname: String, callback: DnsCallback1[js.Array[ResolveObject]]): Unit = js.native + + def resolveCname(hostname: String, callback: DnsCallback1[js.Array[String]]): Unit = js.native + + def resolveMx(hostname: String, callback: DnsCallback1[js.Array[MX]]): Unit = js.native + + def resolveNaptr(hostname: String, callback: DnsCallback1[js.Array[NAPTR]]): Unit = js.native + + def resolveNs(hostname: String, callback: DnsCallback1[js.Array[String]]): Unit = js.native + + def resolveSoa(hostname: String, callback: DnsCallback1[js.Array[SOA]]): Unit = js.native + + def resolveSrv(hostname: String, callback: DnsCallback1[js.Array[SRV]]): Unit = js.native + + def resolvePtr(hostname: String, callback: DnsCallback1[js.Array[String]]): Unit = js.native + + def resolveTxt(hostname: String, callback: DnsCallback1[js.Array[js.Array[String]]]): Unit = js.native + + def reverse(ipAddress: String, callback: DnsCallback1[js.Array[String]]): Unit = js.native + + def setServers(servers: js.Array[String]): Unit = js.native +} diff --git a/app/current/src/main/scala/io/scalajs/nodejs/dns/SOA.scala b/app/current/src/main/scala/io/scalajs/nodejs/dns/SOA.scala deleted file mode 100644 index d79b9cff2..000000000 --- a/app/current/src/main/scala/io/scalajs/nodejs/dns/SOA.scala +++ /dev/null @@ -1,28 +0,0 @@ -package io.scalajs.nodejs.dns - -import scala.scalajs.js - -/** - * Represents a DNS SOA record. - *
-  * {
-  * nsname: 'ns.example.com',
-  * hostmaster: 'root.example.com',
-  * serial: 2013101809,
-  * refresh: 10000,
-  * retry: 2400,
-  * expire: 604800,
-  * minttl: 3600
-  * }
-  * 
- */ -@js.native -trait SOA extends js.Object { - var nsname: String = js.native - var hostmaster: String = js.native - var serial: Integer = js.native - var refresh: Integer = js.native - var retry: Integer = js.native - var expire: Integer = js.native - var minttl: Integer = js.native -} diff --git a/app/current/src/main/scala/io/scalajs/nodejs/dns/SRV.scala b/app/current/src/main/scala/io/scalajs/nodejs/dns/SRV.scala deleted file mode 100644 index 13038436b..000000000 --- a/app/current/src/main/scala/io/scalajs/nodejs/dns/SRV.scala +++ /dev/null @@ -1,22 +0,0 @@ -package io.scalajs.nodejs.dns - -import scala.scalajs.js - -/** - * Represents a DNS SRV record. - *
-  * {
-  * priority: 10,
-  * weight: 5,
-  * port: 21223,
-  * name: 'service.example.com'
-  * }
-  * 
- */ -@js.native -trait SRV extends js.Object { - var priority: Integer = js.native - var weight: Integer = js.native - var port: Integer = js.native - var name: String = js.native -} diff --git a/app/current/src/main/scala/io/scalajs/nodejs/dns/TtlOptions.scala b/app/current/src/main/scala/io/scalajs/nodejs/dns/TtlOptions.scala new file mode 100644 index 000000000..de7e9c98f --- /dev/null +++ b/app/current/src/main/scala/io/scalajs/nodejs/dns/TtlOptions.scala @@ -0,0 +1,7 @@ +package io.scalajs.nodejs.dns + +import scala.scalajs.js + +class TtlOptions( + val ttl: js.UndefOr[Boolean] = js.undefined +) extends js.Object {} diff --git a/app/current/src/main/scala/io/scalajs/nodejs/dns/package.scala b/app/current/src/main/scala/io/scalajs/nodejs/dns/package.scala index e3682530e..c71ce4fe0 100644 --- a/app/current/src/main/scala/io/scalajs/nodejs/dns/package.scala +++ b/app/current/src/main/scala/io/scalajs/nodejs/dns/package.scala @@ -23,6 +23,8 @@ package object dns { type RRType = String + type ResolveResult = js.Array[String | ResolveObject] | SOA + ///////////////////////////////////////////////////////////////////////////////// // Constants ///////////////////////////////////////////////////////////////////////////////// @@ -61,7 +63,7 @@ package object dns { * DNS Extensions * @param dns the DNS instance */ - implicit class DNSExtensions(val dns: DNS) extends AnyVal { + implicit final class DNSExtensions(private val dns: DNS) extends AnyVal { /** * Resolves a hostname (e.g. 'nodejs.org') into the first found A (IPv4) or AAAA (IPv6) record. options can be an @@ -69,8 +71,8 @@ package object dns { * integer, then it must be 4 or 6. */ @inline - def lookupFuture(hostname: String, options: DnsOptions | Int = null): Future[String] = { - promiseWithError1[DnsError, String](dns.lookup(hostname, options, _)) + def lookupFuture(hostname: String, options: DnsOptions | Int = null): Future[(String, Int)] = { + promiseWithError2[DnsError, String, Int](dns.lookup(hostname, options, _)) } /** @@ -96,8 +98,8 @@ package object dns { * @param hostname the hostname */ @inline - def resolveFuture[T](hostname: String, rrtype: RRType = null): Future[T] = { - promiseWithError1[DnsError, T](dns.resolve[T](hostname, rrtype, _)) + def resolveFuture(hostname: String, rrtype: RRType = null): Future[ResolveResult] = { + promiseWithError1[DnsError, ResolveResult](dns.resolve(hostname, rrtype, _)) } /** diff --git a/app/nodejs-v10/src/test/scala/nodejs/dns/DNSAsyncTest.scala b/app/nodejs-v10/src/test/scala/nodejs/dns/DNSAsyncTest.scala new file mode 100644 index 000000000..37d86c84b --- /dev/null +++ b/app/nodejs-v10/src/test/scala/nodejs/dns/DNSAsyncTest.scala @@ -0,0 +1,46 @@ +package io.scalajs.nodejs +package dns + +import org.scalatest.AsyncFunSpec + +import scala.concurrent.ExecutionContext +import scala.scalajs.js + +/** + * DNS Tests + */ +class DNSAsyncTest extends AsyncFunSpec { + private val domain = "google.com" + private val resolver = new DNS.promises.Resolver() + + override implicit val executionContext = ExecutionContext.Implicits.global + + describe("PromisesResolver") { + it("supports resolveFuture:MX") { + resolver.resolve(domain, RRTYPE_MX).toFuture map { response => + val result = response.asInstanceOf[js.Array[MX]] + assert(result(0).priority > 0 && result(0).exchange.nonEmpty) + } + } + + it("supports resolveFuture:NS") { + resolver.resolve(domain, RRTYPE_NS).toFuture map { response => + val result = response.asInstanceOf[js.Array[String]] + assert(result(0).nonEmpty) + } + } + + it("supports resolveFuture:SOA") { + resolver.resolve(domain, RRTYPE_SOA).toFuture map { response => + val result = response.asInstanceOf[SOA] + assert(result.expire > 0 && result.hostmaster.nonEmpty) + } + } + + it("supports reverseFuture") { + resolver.reverse("216.58.218.142").toFuture map { hostnames => + assert(hostnames.nonEmpty && hostnames(0).nonEmpty) + } + } + } +} diff --git a/app/nodejs-v8/src/test/scala/nodejs/dns/DNSAsyncTest.scala b/app/nodejs-v8/src/test/scala/nodejs/dns/DNSAsyncTest.scala new file mode 100644 index 000000000..0701af2bf --- /dev/null +++ b/app/nodejs-v8/src/test/scala/nodejs/dns/DNSAsyncTest.scala @@ -0,0 +1,58 @@ +package io.scalajs.nodejs +package dns + +import org.scalatest.AsyncFunSpec + +import scala.concurrent.ExecutionContext +import scala.scalajs.js + +/** + * DNS Tests + */ +class DNSAsyncTest extends AsyncFunSpec { + private val domain = "google.com" + override implicit val executionContext = ExecutionContext.Implicits.global + + describe("DNS") { + it("supports lookupFuture") { + DNS.lookupFuture(domain) map { + case (ipAddress, ttl) => + assert(ttl > 0 && ipAddress.nonEmpty) + } + } + + it("supports lookupServiceFuture:SSH") { + DNS.lookupServiceFuture("127.0.0.1", 22) map { + case (hostname, service) => + assert(hostname.nonEmpty && service.nonEmpty) + } + } + + it("supports resolveFuture:MX") { + DNS.resolveFuture(domain, RRTYPE_MX) map { response => + val result = response.asInstanceOf[js.Array[MX]] + assert(result(0).priority > 0 && result(0).exchange.nonEmpty) + } + } + + it("supports resolveFuture:NS") { + DNS.resolveFuture(domain, RRTYPE_NS) map { response => + val result = response.asInstanceOf[js.Array[String]] + assert(result(0).nonEmpty) + } + } + + it("supports resolveFuture:SOA") { + DNS.resolveFuture(domain, RRTYPE_SOA) map { response => + val result = response.asInstanceOf[SOA] + assert(result.expire > 0 && result.hostmaster.nonEmpty) + } + } + + it("supports reverseFuture") { + DNS.reverseFuture("216.58.218.142") map { hostnames => + assert(hostnames.nonEmpty && hostnames(0).nonEmpty) + } + } + } +} diff --git a/app/nodejs-v8/src/test/scala/nodejs/dns/DNSTest.scala b/app/nodejs-v8/src/test/scala/nodejs/dns/DNSTest.scala index 9cac7d484..77a29b2c9 100644 --- a/app/nodejs-v8/src/test/scala/nodejs/dns/DNSTest.scala +++ b/app/nodejs-v8/src/test/scala/nodejs/dns/DNSTest.scala @@ -1,82 +1,42 @@ package io.scalajs.nodejs package dns -import io.scalajs.util.JSONHelper._ import org.scalatest.FunSpec -import scala.scalajs.concurrent.JSExecutionContext.Implicits.queue import scala.scalajs.js /** * DNS Tests */ class DNSTest extends FunSpec { - private val domain = "yahoo.com" + private val domain = "google.com" describe("DNS") { it("supports lookup") { DNS.lookup(domain, (err, ipAddress) => { - Assert.equal(err, null, err.toJson) + assert(err === null) info(s"lookup - ipAddress: $ipAddress") }) } - it("supports lookupFuture") { - DNS.lookupFuture(domain) map { ipAddress => - info(s"lookupFuture - ipAddress: $ipAddress") - } - } - it("supports lookupService:SSH") { DNS.lookupService("127.0.0.1", 22, (err, hostname, service) => { - Assert.equal(err, null, err.toJson) - info(s"lookupService - hostname => $hostname, service => $service") + assert(err === null) + assert(hostname.nonEmpty) + assert(service.nonEmpty) }) } - it("supports lookupServiceFuture:SSH") { - DNS.lookupServiceFuture("127.0.0.1", 22) map { - case (hostname, service) => - info(s"lookupServiceFuture - hostname: $hostname, service => $service") - } - } - it("supports resolve:NS") { DNS.resolve( domain, "NS", - (err: DnsError, addresses: js.Array[String]) => { - Assert.equal(err, null, err.toJson) - info(s"resolve:NS - addresses: ${addresses.mkString(", ")}") + (err: DnsError, addresses: ResolveResult) => { + assert(err === null) + assert(addresses.asInstanceOf[js.Array[String]].nonEmpty) } ) } - - it("supports resolveFuture:MX") { - DNS.resolveFuture[js.Array[MX]](domain, RRTYPE_MX) map { response => - info(s"resolveFuture:MX - response: ${response.toJson}") - } - } - - it("supports resolveFuture:NS") { - DNS.resolveFuture[js.Array[String]](domain, "NS") map { addresses => - info(s"resolveFuture - addresses: ${addresses.mkString(", ")}") - } - } - - it("supports resolveFuture:SOA") { - DNS.resolveFuture[SOA](domain, RRTYPE_SOA) foreach { response => - info(s"resolveFuture:SOA: response: ${response.toJson}") - } - } - - it("supports reverseFuture") { - DNS.reverseFuture("216.58.218.142") map { hostnames => - info(s"reverseFuture - hostname: ${hostnames.mkString(", ")}") - } - } - } - }