{-# 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