Permalink
Browse files

Move hSpec tests for 'lookupNSAuth' into the (tested) docs for 'looku…

…pNSAuth'.

Remove unused imports from LookupSpec.hs.
  • Loading branch information...
1 parent 2bb99a9 commit ecaa45a839ffdf120bd5304efa0025e11ecaf64e @orlitzky orlitzky committed Sep 12, 2013
Showing with 23 additions and 21 deletions.
  1. +23 −4 Network/DNS/Lookup.hs
  2. +0 −17 test2/LookupSpec.hs
View
@@ -261,10 +261,29 @@ lookupNSImpl lookup_function rlv dom = do
lookupNS :: Resolver -> Domain -> IO (Either DNSError [Domain])
lookupNS = lookupNSImpl DNS.lookup
-{-|
- Resolving 'Domain' by 'NS'. Results taken from the AUTHORITY section
- of the response.
--}
+-- | Look up all \'NS\' records for the given hostname. The results
+-- are taken from the AUTHORITY section of the response and not the
+-- usual ANSWER (use 'lookupNS' for that). For details, see e.g.
+-- <http://www.zytrax.com/books/dns/ch15/>.
+--
+-- There will typically be more than one name server for a
+-- domain. It is therefore extra important to sort the results if
+-- you prefer them to be at all deterministic.
+--
+-- For an example, we can look up the nameservers for
+-- \"example.com\" from one of the root servers, a.gtld-servers.net,
+-- the IP address of which was found beforehand:
+--
+-- >>> import Data.List (sort)
+-- >>> let hostname = Data.ByteString.Char8.pack "example.com"
+-- >>>
+-- >>> let ri = RCHostName "192.5.6.30" -- a.gtld-servers.net
+-- >>> let rc = defaultResolvConf { resolvInfo = ri }
+-- >>> rs <- makeResolvSeed rc
+-- >>> ns <- withResolver rs $ \resolver -> lookupNSAuth resolver hostname
+-- >>> fmap sort ns
+-- Right ["a.iana-servers.net.","b.iana-servers.net."]
+--
lookupNSAuth :: Resolver -> Domain -> IO (Either DNSError [Domain])
lookupNSAuth = lookupNSImpl DNS.lookupAuth
View
@@ -2,9 +2,7 @@
module LookupSpec where
-import Control.Applicative
import qualified Data.ByteString.Char8 as BS
-import Data.List
import Network.DNS as DNS
import Test.Hspec
@@ -19,21 +17,6 @@ spec = do
`shouldReturn`
Right []
- describe "lookupNSAuth" $ do
- it "gets NS" $ do
- -- We expect the GTLD servers to return the NS in the
- -- AUTHORITY section of the response.
- let ri = RCHostName "192.5.6.30" -- a.gtld-servers.net
- let rc = defaultResolvConf { resolvInfo = ri }
- rs <- makeResolvSeed rc
- withResolver rs $ \resolver -> do
- actual <- DNS.lookupNSAuth resolver "example.com"
- let expected = Right ["a.iana-servers.net.",
- "b.iana-servers.net."]
- -- The order of NS records is variable, so we sort the
- -- result.
- sort <$> actual `shouldBe` expected
-
describe "lookupTXT" $ do
it "gets TXT" $ do
rs <- makeResolvSeed defaultResolvConf

0 comments on commit ecaa45a

Please sign in to comment.