diff options
Diffstat (limited to 'test/Main.hs')
-rw-r--r-- | test/Main.hs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/test/Main.hs b/test/Main.hs new file mode 100644 index 0000000..fa6a3fb --- /dev/null +++ b/test/Main.hs @@ -0,0 +1,37 @@ +{-# LANGUAGE OverloadedLists #-} +{-# LANGUAGE OverloadedStrings #-} +module Main (main) where + +import Conftrack +import Conftrack.Value +import Conftrack.Source + +import qualified Data.Map.Strict as M +import Data.Text (Text) +import Control.Exception (assert) + +data TestType = TestType { testFoo :: Text, testBar :: Integer } + deriving (Show, Eq) + +instance Config TestType where + readConfig = TestType + <$> readValue (Key ["foo"]) + <*> readValue (Key ["bar"]) + +main :: IO () +main = do + let trivial = Trivial (M.fromList [(Key ["foo"], ConfigText "foo"), (Key ["bar"], ConfigInteger 10)]) + Right (config :: TestType, _, _) <- runFetchConfig [SomeSource (trivial, [])] + () <- assert (config == TestType "foo" 10) (pure ()) + + let trivial = Trivial (M.fromList [(Key ["fo"], ConfigText "foo"), (Key ["bar"], ConfigInteger 10)]) + Left [NotPresent] <- runFetchConfig @TestType [SomeSource (trivial, [])] + + let stack1 = Trivial (M.fromList [(Key ["foo"], ConfigText "foo")]) + let stack2 = Trivial (M.fromList [(Key ["bar"], ConfigInteger 10), (Key ["foo"], ConfigText "blub")]) + Right (config :: TestType, origins, warnings) <- runFetchConfig [SomeSource (stack1, []), SomeSource (stack2, [])] + () <- assert (config == TestType "foo" 11) (pure ()) + print origins + print warnings + + print config |