1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
{-# LANGUAGE OverloadedStrings #-}
module Test where
import Data.List
import Network.DNS as DNS
import Test.Framework (defaultMain, testGroup, Test)
import Test.Framework.Providers.HUnit
import Test.HUnit hiding (Test)
import qualified Data.ByteString.Char8 as BS
tests :: [Test]
tests = [
testGroup "Test case" [
testCase "lookupA" test_lookupA
, testCase "lookupAAAA" test_lookupAAAA
, testCase "lookupTXT" test_lookupTXT
, testCase "lookupAviaMX" test_lookupAviaMX
, testCase "lookupAviaCNAME" test_lookupAviaCNAME
, testCase "lookupPTR" test_lookupPTR
, testCase "lookupSRV" test_lookupSRV
]
]
(?=) :: (Eq a, Show a) => IO a -> a -> IO ()
a ?= b = a >>= (@?= b)
test_lookupA :: IO ()
test_lookupA = do
rs <- makeResolvSeed defaultResolvConf
withResolver rs $ \resolver ->
DNS.lookupA resolver "www.mew.org" ?= Just ["202.232.15.101"]
(??=) :: (Ord a, Show a) => IO (Maybe [a]) -> [a] -> IO ()
a ??= bs = do
mas <- a
case mas of
Nothing -> False @? "should be Nothing"
Just as -> sort as @?= sort bs
test_lookupAAAA :: IO ()
test_lookupAAAA = do
rs <- makeResolvSeed defaultResolvConf
withResolver rs $ \resolver -> do
DNS.lookupAAAA resolver "mew.org" ?= Nothing
DNS.lookupAAAA resolver "www.mew.org" ?= Just ["2001:240:11e:c00::101"]
test_lookupTXT :: IO ()
test_lookupTXT = do
rs <- makeResolvSeed defaultResolvConf
withResolver rs $ \resolver ->
DNS.lookupTXT resolver "mew.org" ?= Just ["v=spf1 +mx -all"]
test_lookupAviaMX :: IO ()
test_lookupAviaMX = do
rs <- makeResolvSeed defaultResolvConf
withResolver rs $ \resolver ->
DNS.lookupAviaMX resolver "mixi.jp" ??= ["202.32.29.4", "202.32.29.5"]
test_lookupAviaCNAME :: IO ()
test_lookupAviaCNAME = do
rs <- makeResolvSeed defaultResolvConf
withResolver rs $ \resolver ->
DNS.lookupA resolver "ghs.google.com" ??= ["72.14.203.121"]
test_lookupPTR :: IO ()
test_lookupPTR = do
rs <- makeResolvSeed defaultResolvConf
withResolver rs $ \resolver ->
DNS.lookupPTR resolver rev ?= Just ["www-v4.iij.ad.jp."]
where
target = "210.130.137.80"
rev = BS.intercalate "." (reverse (BS.split '.' target))
`BS.append` ".in-addr.arpa"
test_lookupSRV :: IO ()
test_lookupSRV = do
rs <- makeResolvSeed defaultResolvConf
withResolver rs $ \resolver ->
DNS.lookupSRV resolver "_sip._tcp.cisco.com" ?= Just [(1,0,5060,"vcsgw.cisco.com.")]
main :: IO ()
main = defaultMain tests
|