mirror of
https://github.com/kazu-yamamoto/dns.git
synced 2024-10-06 02:27:35 +03:00
adding test for send/receive.
This commit is contained in:
parent
18ebc30692
commit
1bd3b07a96
@ -63,10 +63,12 @@ Test-Suite network
|
||||
Ghc-Options: -Wall
|
||||
Main-Is: Spec.hs
|
||||
Other-Modules: LookupSpec
|
||||
IOSpec
|
||||
Build-Depends: dns
|
||||
, base
|
||||
, bytestring
|
||||
, hspec
|
||||
, network
|
||||
|
||||
Test-Suite spec
|
||||
Type: exitcode-stdio-1.0
|
||||
|
31
test2/IOSpec.hs
Normal file
31
test2/IOSpec.hs
Normal file
@ -0,0 +1,31 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module IOSpec where
|
||||
|
||||
import Network.DNS.IO as DNS
|
||||
import Network.DNS.Types as DNS
|
||||
import Network.Socket hiding (send)
|
||||
import Test.Hspec
|
||||
|
||||
spec :: Spec
|
||||
spec = describe "send/receive" $ do
|
||||
|
||||
it "resolves well with UDP" $ do
|
||||
let hints = defaultHints { addrFamily = AF_INET, addrSocketType = Datagram, addrFlags = [AI_NUMERICHOST]}
|
||||
addr:_ <- getAddrInfo (Just hints) (Just "8.8.8.8") (Just "domain")
|
||||
sock <- socket (addrFamily addr) (addrSocketType addr) (addrProtocol addr)
|
||||
connect sock $ addrAddress addr
|
||||
let qry = encodeQuestions 1 [Question "www.mew.org" A] [] False
|
||||
send sock qry
|
||||
ans <- receive sock
|
||||
identifier (header ans) `shouldBe` 1
|
||||
|
||||
it "resolves well with TCP" $ do
|
||||
let hints = defaultHints { addrFamily = AF_INET, addrSocketType = Stream, addrFlags = [AI_NUMERICHOST]}
|
||||
addr:_ <- getAddrInfo (Just hints) (Just "8.8.8.8") (Just "domain")
|
||||
sock <- socket (addrFamily addr) (addrSocketType addr) (addrProtocol addr)
|
||||
connect sock $ addrAddress addr
|
||||
let qry = encodeQuestions 1 [Question "www.mew.org" A] [] False
|
||||
sendVC sock qry
|
||||
ans <- receiveVC sock
|
||||
identifier (header ans) `shouldBe` 1
|
Loading…
Reference in New Issue
Block a user