From: Eugene Crosser Date: Thu, 17 Apr 2014 09:44:14 +0000 (+0400) Subject: move test functionality into main program X-Git-Tag: 0.9.0.0~52 X-Git-Url: http://average.org/gitweb/?a=commitdiff_plain;h=b499364fc244111c99b003775c88fcb35633f26b;p=pdns-pipe-nmc.git move test functionality into main program --- diff --git a/pdns-pipe-nmc.hs b/pdns-pipe-nmc.hs index 6e42ac2..f2669a2 100644 --- a/pdns-pipe-nmc.hs +++ b/pdns-pipe-nmc.hs @@ -2,9 +2,14 @@ module Main where -import System.IO +import Prelude hiding (readFile) +import System.Environment +import System.IO hiding (readFile) +import System.IO.Error +import Control.Exception +import Text.Show.Pretty hiding (String) import Control.Monad -import Data.ByteString.Lazy hiding (reverse, putStr, putStrLn) +import Data.ByteString.Lazy hiding (reverse, putStr, putStrLn, head) import qualified Data.ByteString.Char8 as C (pack) import qualified Data.ByteString.Lazy.Char8 as L (pack) import qualified Data.Text as T (pack) @@ -67,7 +72,7 @@ queryNmc mgr cfg qid fqdn = -- Main entry -main = do +mainNmc = do cfg <- readConfig confFile @@ -102,9 +107,32 @@ main = do putStr $ pdnsReport ("No support for AXFR " ++ xfrreq) PdnsRequestPing -> putStrLn "END" --- for testing +-- query by key from Namecoin -ask str = do +mainOne key = do cfg <- readConfig confFile mgr <- newManager def - queryNmc mgr cfg "askid" str >>= putStr . (pdnsOut 1 "askid" str RRTypeANY) + dom <- queryNmc mgr cfg "+" key + putStrLn $ ppShow dom + putStr $ pdnsOut 1 "+" key RRTypeANY dom + +-- using file backend for testing json domain data + +queryFile :: String -> IO (Either String ByteString) +queryFile key = catch (readFile key >>= return . Right) + (\e -> return (Left (show (e :: IOException)))) + +mainFile key = do + dom <- descendNmcDom queryFile [] (seedNmcDom key) + putStrLn $ ppShow dom + putStr $ pdnsOut 1 "+" key RRTypeANY dom + +-- Entry point + +main = do + args <- getArgs + case args of + [] -> mainNmc + [key] -> mainOne key + ["-f",key] -> mainFile key + _ -> error $ "usage: empty args, or \"\", or \"-f \"" diff --git a/test.hs b/test.hs deleted file mode 100644 index 3a9f8b4..0000000 --- a/test.hs +++ /dev/null @@ -1,23 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} - -module Main where - -import Prelude hiding (readFile) -import System.Environment -import Data.ByteString.Lazy (ByteString) -import Data.ByteString.Lazy.Char8 (readFile) -import System.IO.Error -import Control.Exception -import Text.Show.Pretty - -import NmcDom -import NmcTransform - -queryOp :: String -> IO (Either String ByteString) -queryOp key = catch (readFile key >>= return . Right) - (\e -> return (Left (show (e :: IOException)))) - -main = do - (d:_) <- getArgs - descendNmcDom queryOp [] (seedNmcDom d) >>= putStrLn . ppShow -