-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Localstack annd rds testing support (#14)
* New runReaderAwsEnvDiscover function * Export runFileSystem * Testcontainers for loccalstack support * New logEntryToJson and logMessageToJson functions * New putJsonStdout function * Export hedgehog Failure type * Modify Log effect to coonvey the severity and message together in the LogMessage * New runReaderM function * New Effectful.Zoo.Environment exporting lookupEnv that throws on error and lookupEnvMaybe that doesn't, both using Text as the type * New lookupParseMaybeEnv and lookupParseEitherEnv functions * New lookupMapEnv function * New functions: failMessage, failWithCustom, byDurationM, and byDeadlineM * New rds-data-test and testcontainers-localstack components
- Loading branch information
Showing
25 changed files
with
892 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
module Effectful.Zoo.Environment | ||
( -- * Effect | ||
Environment, | ||
|
||
-- ** Handlers | ||
E.runEnvironment, | ||
|
||
-- * Querying the environment | ||
E.getArgs, | ||
E.getProgName, | ||
E.getExecutablePath, | ||
E.getEnv, | ||
E.getEnvironment, | ||
lookupEnv, | ||
lookupEnvMaybe, | ||
lookupMapEnv, | ||
lookupParseMaybeEnv, | ||
lookupParseEitherEnv, | ||
|
||
-- * Modifying the environment | ||
E.setEnv, | ||
E.unsetEnv, | ||
E.withArgs, | ||
E.withProgName, | ||
) | ||
where | ||
|
||
import Data.Text qualified as T | ||
import Effectful | ||
import Effectful.Environment (Environment) | ||
import Effectful.Environment qualified as E | ||
import Effectful.Zoo.Core | ||
import Effectful.Zoo.Error.Static | ||
import Effectful.Zoo.Errors.EnvironmentVariableInvalid | ||
import Effectful.Zoo.Errors.EnvironmentVariableMissing | ||
import HaskellWorks.Prelude | ||
|
||
lookupEnv :: () | ||
=> r <: Environment | ||
=> r <: Error EnvironmentVariableMissing | ||
=> Text | ||
-> Eff r Text | ||
lookupEnv envName = | ||
lookupEnvMaybe envName | ||
& onNothingM (throw $ EnvironmentVariableMissing envName) | ||
|
||
lookupMapEnv :: () | ||
=> r <: Environment | ||
=> r <: Error EnvironmentVariableMissing | ||
=> Text | ||
-> (Text -> a) | ||
-> Eff r a | ||
lookupMapEnv envName f = | ||
f <$> lookupEnv envName | ||
|
||
lookupParseMaybeEnv :: () | ||
=> r <: Environment | ||
=> r <: Error EnvironmentVariableInvalid | ||
=> r <: Error EnvironmentVariableMissing | ||
=> Text | ||
-> (Text -> Maybe a) | ||
-> Eff r a | ||
lookupParseMaybeEnv envName parse = do | ||
text <- lookupEnv envName | ||
|
||
parse text | ||
& onNothing (throw $ EnvironmentVariableInvalid envName text Nothing) | ||
|
||
lookupParseEitherEnv :: () | ||
=> r <: Environment | ||
=> r <: Error EnvironmentVariableInvalid | ||
=> r <: Error EnvironmentVariableMissing | ||
=> Text | ||
-> (Text -> Either Text a) | ||
-> Eff r a | ||
lookupParseEitherEnv envName parse = do | ||
text <- lookupEnv envName | ||
|
||
parse text | ||
& onLeft (throw . EnvironmentVariableInvalid envName text . Just) | ||
|
||
lookupEnvMaybe :: () | ||
=> r <: Environment | ||
=> Text | ||
-> Eff r (Maybe Text) | ||
lookupEnvMaybe envName = do | ||
value <- E.lookupEnv $ T.unpack envName | ||
pure $ T.pack <$> value |
24 changes: 24 additions & 0 deletions
24
components/core/Effectful/Zoo/Errors/EnvironmentVariableInvalid.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module Effectful.Zoo.Errors.EnvironmentVariableInvalid | ||
( EnvironmentVariableInvalid (..), | ||
) where | ||
|
||
import Data.Aeson (ToJSON (..), (.=)) | ||
import Data.Aeson qualified as J | ||
import GHC.Generics | ||
import HaskellWorks.Prelude | ||
|
||
data EnvironmentVariableInvalid = EnvironmentVariableInvalid | ||
{ variable :: Text | ||
, text :: Text | ||
, reason :: Maybe Text | ||
} | ||
deriving stock (Eq, Show, Generic) | ||
|
||
instance ToJSON EnvironmentVariableInvalid where | ||
toJSON e = | ||
J.object | ||
[ "error" .= id @Text "EnvironmentVariableInvalid" | ||
, "variable" .= e.variable | ||
, "text" .= e.text | ||
, "reason" .= e.reason | ||
] |
20 changes: 20 additions & 0 deletions
20
components/core/Effectful/Zoo/Errors/EnvironmentVariableMissing.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Effectful.Zoo.Errors.EnvironmentVariableMissing | ||
( EnvironmentVariableMissing (..), | ||
) where | ||
|
||
import Data.Aeson (ToJSON (..), (.=)) | ||
import Data.Aeson qualified as J | ||
import GHC.Generics | ||
import HaskellWorks.Prelude | ||
|
||
newtype EnvironmentVariableMissing = EnvironmentVariableMissing | ||
{ variable :: Text | ||
} | ||
deriving stock (Eq, Show, Generic) | ||
|
||
instance ToJSON EnvironmentVariableMissing where | ||
toJSON e = | ||
J.object | ||
[ "error" .= id @Text "EnvironmentVariableMissing" | ||
, "variable" .= e.variable | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.