-- |
-- Copyright: (c) 2019 Lucas David Traverso
-- License: MPL-2.0
-- Maintainer: Lucas David Traverso <lucas6246@gmail.com>
-- Stability: stable
-- Portability: portable
--
-- Some testing utilities
module Conferer.Test
  ( configWith
  ) where

import Conferer.Config
import qualified Conferer.Source.InMemory as InMemory
import Data.Text (Text)
import Data.Dynamic

-- | Create a Config mostly used for testing 'Conferer.FromConfig.FromConfig'
--   instances without having to create a full config
configWith :: [(Key, Dynamic)] -> [(Key, Text)] -> IO Config
configWith :: [(Key, Dynamic)] -> [(Key, Text)] -> IO Config
configWith [(Key, Dynamic)]
defaults [(Key, Text)]
keyValues =
  Config
emptyConfig 
  Config -> (Config -> Config) -> Config
forall a b. a -> (a -> b) -> b
& [(Key, Dynamic)] -> Config -> Config
addDefaults [(Key, Dynamic)]
defaults
  Config -> (Config -> IO Config) -> IO Config
forall a b. a -> (a -> b) -> b
& SourceCreator -> Config -> IO Config
addSource ([(Key, Text)] -> SourceCreator
InMemory.fromConfig [(Key, Text)]
keyValues)