adding test for send/receive.

This commit is contained in:
Kazu Yamamoto 2018-04-16 11:17:05 +09:00
parent 18ebc30692
commit 1bd3b07a96
2 changed files with 33 additions and 0 deletions

View File

@ -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
View 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