1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
|