aboutsummaryrefslogtreecommitdiff
path: root/tests/Helper.hs
diff options
context:
space:
mode:
authorJoris2016-03-13 21:26:03 +0100
committerJoris2016-03-13 21:26:03 +0100
commit47623ec732ec19c765c0a1ebffd9b234f81e0d01 (patch)
treea52969d730e64d1303e62efa8c36b03a7be7f1a5 /tests/Helper.hs
Initial commit
Diffstat (limited to 'tests/Helper.hs')
-rw-r--r--tests/Helper.hs34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/Helper.hs b/tests/Helper.hs
new file mode 100644
index 0000000..5979ae2
--- /dev/null
+++ b/tests/Helper.hs
@@ -0,0 +1,34 @@
+module Helper
+ ( forceGetConfig
+ , getConfig
+ ) where
+
+
+import System.IO (hClose)
+import System.IO.Temp (withSystemTempFile)
+import System.Directory (removeFile)
+
+import Data.Text (Text)
+import qualified Data.Text.IO as T
+import Data.Maybe (fromJust)
+
+import Data.ConfigManager
+import Data.ConfigManager.Config
+
+forceGetConfig :: Text -> IO Config
+forceGetConfig = (fmap fromJust) . getConfig
+
+getConfig :: Text -> IO (Maybe Config)
+getConfig input =
+ withSystemTempFile "config-manager-test" (\filePath handle -> do
+ hClose handle
+ T.writeFile filePath input
+ config <- readConfig filePath
+ removeFile filePath
+ putStrLn . show $ config
+ return $ eitherToMaybe config
+ )
+
+eitherToMaybe :: Either a b -> Maybe b
+eitherToMaybe (Left _) = Nothing
+eitherToMaybe (Right x) = Just x