packages feed

conferer-warp (empty) → 0.1.0.1

raw patch · 7 files changed

+162/−0 lines, 7 filesdep +basedep +confererdep +conferer-warpsetup-changed

Dependencies added: base, conferer, conferer-warp, hspec, http-types, text, wai, warp

Files

+ LICENSE view
@@ -0,0 +1,21 @@+MIT License++Copyright (c) 2019 Lucas David Traverso++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all+copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+SOFTWARE.
+ README.md view
@@ -0,0 +1,1 @@+# conferer-warp
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ conferer-warp.cabal view
@@ -0,0 +1,61 @@+cabal-version: 1.18++-- This file has been generated from package.yaml by hpack version 0.31.2.+--+-- see: https://github.com/sol/hpack+--+-- hash: ef41490a4d86c25fd30d4fd05b5535d4f08119262a31d708ce72a05155d00725++name:           conferer-warp+version:        0.1.0.1+synopsis:       conferer's FromConfig instances for warp settings++description:    Library to abstract the parsing of many haskell config values from different config sources+category:       Configuration+homepage:       https://github.com/ludat/conferer#readme+author:         Lucas David Traverso+maintainer:     lucas6246@gmail.com+copyright:      MIT+license:        BSD3+license-file:   LICENSE+build-type:     Simple+extra-doc-files:+    README.md+    LICENSE++library+  exposed-modules:+      Conferer.FetchFromConfig.Warp+  other-modules:+      Paths_conferer_warp+  hs-source-dirs:+      src+  default-extensions: OverloadedStrings LambdaCase QuasiQuotes ScopedTypeVariables+  build-depends:+      base >=4.3 && <5+    , conferer ==0.1.0.1+    , http-types >=0.8.6 && <0.13+    , text >=1.1 && <1.3+    , wai >=3.0 && <4.0+    , warp >=3.0 && <4.0+  default-language: Haskell2010++test-suite conferer-warp-test+  type: exitcode-stdio-1.0+  main-is: Spec.hs+  other-modules:+      Conferer.FetchFromConfig.WarpSpec+      Paths_conferer_warp+  hs-source-dirs:+      test+  default-extensions: OverloadedStrings LambdaCase QuasiQuotes ScopedTypeVariables+  build-depends:+      base >=4.3 && <5+    , conferer ==0.1.0.1+    , conferer-warp+    , hspec+    , http-types >=0.8.6 && <0.13+    , text >=1.1 && <1.3+    , wai >=3.0 && <4.0+    , warp >=3.0 && <4.0+  default-language: Haskell2010
+ src/Conferer/FetchFromConfig/Warp.hs view
@@ -0,0 +1,40 @@+{-# LANGUAGE FlexibleInstances #-}+module Conferer.FetchFromConfig.Warp+  (+  -- * How to use this+  -- | FetchFromConfig instance for warp server settings+  --+  -- @+  -- import Conferer+  -- import Conferer.FetchFromConfig.Warp ()+  --+  -- main = do+  --   config <- 'defaultConfig' \"awesomeapp\"+  --   warpSettings <- 'getFromConfig' \"warp\" config+  -- @+  ) where++import Conferer.Core+import Conferer.Types+import Conferer.FetchFromConfig.Basics+import Data.Either (rights)+import Network.Wai.Handler.Warp+import Data.String (fromString)+import Data.Text (unpack)++instance FetchFromConfig HostPreference where+    fetch = fetchFromConfigWith (pure . fromString . unpack)++instance FetchFromConfig Settings where+    fetch k config = do+        port <- fetch (k /. "port") config+        timeout <- fetch (k /. "timeout") config+        host <- fetch (k /. "host") config+        serverName <- fetch (k /. "serverName") config+        let overriders = rights [+                          setTimeout <$> timeout,+                          setHost <$> host,+                          setPort <$> port,+                          setServerName <$> serverName+                        ]+        return . return $ foldr ($) defaultSettings overriders
+ test/Conferer/FetchFromConfig/WarpSpec.hs view
@@ -0,0 +1,36 @@+module Conferer.FetchFromConfig.WarpSpec where++import           Test.Hspec+import           Conferer.Types+import           Data.Text+import           Conferer+import           Conferer.FetchFromConfig.Warp ()+import           Network.Wai.Handler.Warp++configWith :: [(Key, Text)] -> IO Config+configWith keyValues = emptyConfig & addProvider (mkMapProvider keyValues)++portAndHostShouldBe :: Either Text Settings -> (Port, HostPreference) -> Expectation+portAndHostShouldBe fetchedSettings (port, host) = do+  getPort <$> fetchedSettings `shouldBe` Right port+  getHost <$> fetchedSettings `shouldBe` Right host++spec :: Spec+spec = do+  let defaultPort = getPort defaultSettings+      defaultHost = getHost defaultSettings+  describe "fetching a warp configuration without overriding anything" $ do+    it "returns warp default config" $ do+      let config = emptyConfig+      fetchedValue <- fetch "." config+      fetchedValue `portAndHostShouldBe` (defaultPort, defaultHost)+  describe "fetching a warp configuration overridnig its port" $ do+    it "returns a warp config with its port set to the overriden one" $ do+      config <- configWith [("warp.port", "9999")]+      fetchedValue <- fetch "warp" config+      fetchedValue `portAndHostShouldBe` (9999, defaultHost)+  describe "fetching a warp configuration overriding its host" $ do+    it "returns a warp config with its host set to the overriden one" $ do+      config <- configWith [("warp.host", "!6")]+      fetchedValue <- fetch "warp" config+      fetchedValue `portAndHostShouldBe` (defaultPort, "!6")
+ test/Spec.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF hspec-discover #-}