packages feed

etc 0.4.0.1 → 0.4.0.2

raw patch · 7 files changed

+49/−23 lines, 7 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -1,3 +1,9 @@+0.4.0.2+----++* Improvement around unhelpful error being thrown when CLI Config Map didn't+  contain a value on a required (by code) field+ 0.4.0.1 ---- 
etc.cabal view
@@ -1,6 +1,6 @@ cabal-version: >=1.10 name: etc-version: 0.4.0.1+version: 0.4.0.2 license: MIT license-file: LICENSE copyright: 2017, 2018 Roman Gonzalez
src/System/Etc/Internal/Config.hs view
@@ -20,7 +20,7 @@ configValueToJsonObject :: ConfigValue -> JSON.Value configValueToJsonObject configValue = case configValue of   ConfigValue sources -> case Set.maxView sources of-    Nothing          -> error "this should not happen"+    Nothing          -> JSON.Null      Just (source, _) -> fromValue $ value source 
src/System/Etc/Internal/Extra/Printer.hs view
@@ -164,7 +164,7 @@               --   - Value 2               --   - Value 3               ---              return $ sourceDoc <$$> (indent 2 $ align (vsep multipleValues))+              return $ sourceDoc <$$> indent 2 (align (vsep multipleValues))       in  case eSourceDocs of             Left  err -> throwM $ InvalidConfiguration (Just keyPath) err @@ -207,7 +207,7 @@   in     do       result <- loop [] configMap-      return $ (hcat $ intersperse (linebreak <> linebreak) $ result) <> linebreak+      return $ hcat (intersperse (linebreak <> linebreak) result) <> linebreak   renderConfigColor :: MonadThrow m => Config -> m Doc
src/System/Etc/Internal/Resolver/Env.hs view
@@ -20,7 +20,7 @@   -> Spec.ConfigSources cmd   -> Maybe ConfigSource resolveEnvVarSource lookupEnv configValueType isSensitive specSources =-  let envTextToJSON envValue = Spec.parseBytesToConfigValueJSON configValueType envValue+  let envTextToJSON = Spec.parseBytesToConfigValueJSON configValueType        toEnvSource varname envValue =         Env varname . markAsSensitive isSensitive <$> envTextToJSON envValue
src/System/Etc/Internal/Spec/Types.hs view
@@ -273,7 +273,7 @@   (JSON.Bool{}  , CVTSingle CVTBool  ) -> True   (JSON.Object{}, CVTSingle CVTObject) -> True   (JSON.Array arr, CVTArray inner) ->-    if null arr then True else all (flip matchesConfigValueType (CVTSingle inner)) arr+    if null arr then True else all (`matchesConfigValueType` (CVTSingle inner)) arr   _ -> False  assertMatchingConfigValueType :: Monad m => JSON.Value -> ConfigValueType -> m ()
test/System/Etc/Resolver/Cli/PlainTest.hs view
@@ -6,6 +6,9 @@ import           RIO import qualified RIO.Set as Set +import           Data.Aeson ((.:))+import qualified Data.Aeson as JSON+ import Test.Tasty       (TestTree, testGroup) import Test.Tasty.HUnit (assertBool, assertEqual, assertFailure, testCase) @@ -15,25 +18,42 @@ resolver_tests = testGroup   "resolver"   [ testCase "throws an error when input type does not match with spec type" $ do-      let input = mconcat-            [ "{ \"etc/entries\": {"-            , "    \"greeting\": {"-            , "      \"etc/spec\": {"-            , "        \"type\": \"[number]\""-            , "        , \"cli\": {"-            , "            \"input\": \"option\""-            , "          , \"short\": \"g\""-            , "          , \"long\": \"greeting\""-            , "          , \"required\": true"-            , "}}}}}"-            ]-      (spec :: SUT.ConfigSpec ()) <- SUT.parseConfigSpec input-      eConfig <- try $ SUT.resolvePlainCliPure spec "program" ["-g", "hello world"]+    let input = mconcat+          [ "{ \"etc/entries\": {"+          , "    \"greeting\": {"+          , "      \"etc/spec\": {"+          , "        \"type\": \"[number]\""+          , "        , \"cli\": {"+          , "            \"input\": \"option\""+          , "          , \"short\": \"g\""+          , "          , \"long\": \"greeting\""+          , "          , \"required\": true"+          , "}}}}}"+          ]+    (spec :: SUT.ConfigSpec ()) <- SUT.parseConfigSpec input+    eConfig <- try $ SUT.resolvePlainCliPure spec "program" ["-g", "hello world"] -      case eConfig of-        Left SUT.CliEvalExited{} -> assertBool "" True+    case eConfig of+      Left SUT.CliEvalExited{} -> assertBool "" True+      _ ->+        assertFailure $ "Expecting CliEvalExited error; got this instead " <> show eConfig+  , testCase "throws an error when entry is not given and is requested" $ do+    let+      input+        = "{\"etc/entries\":{\"database\":{\"username\": {\"etc/spec\": {\"type\": \"string\", \"cli\": {\"input\": \"option\", \"long\": \"username\", \"required\": false}}}, \"password\": \"abc-123\"}}}"++    (spec :: SUT.ConfigSpec ()) <- SUT.parseConfigSpec input+    config                      <- SUT.resolvePlainCliPure spec "program" []+    let parseDb = JSON.withObject "Database"+          $ \obj -> (,) <$> obj .: "username" <*> obj .: "password"++    case SUT.getConfigValueWith parseDb ["database"] config of+      Left err -> case fromException err of+        Just (SUT.InvalidConfiguration key _) ->+          assertEqual "expecting key to be database, but wasn't" (Just "database") key         _ ->-          assertFailure $ "Expecting CliEvalExited error; got this instead " <> show eConfig+          assertFailure $ "expecting InvalidConfiguration; got something else: " <> show err+      Right (_ :: (Text, Text)) -> assertFailure "expecting error; got none"   ]  option_tests :: TestTree