diff options
author | stuebinm | 2024-05-22 00:04:30 +0200 |
---|---|---|
committer | stuebinm | 2024-05-22 00:04:30 +0200 |
commit | d1446a8435a3cf06371eb6d4ebe25d6491612f4d (patch) | |
tree | 3384c966f21caf91cd0ba483b14d5835259029f4 /test |
a generic, multi-source config interface
Diffstat (limited to '')
-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 |