From e4cca88cceb690a3d0a89d639481e7c091d94cb2 Mon Sep 17 00:00:00 2001 From: Saurabh Nanda Date: Tue, 10 Oct 2023 03:42:54 +0000 Subject: [PATCH] optionally using PGxxx environment variables for DB connection during tests --- stack-lts-18.28.yaml | 21 ++++++++ stack-lts-18.28.yaml.lock | 110 ++++++++++++++++++++++++++++++++++++++ test/Test.hs | 42 ++++++++------- 3 files changed, 155 insertions(+), 18 deletions(-) create mode 100644 stack-lts-18.28.yaml create mode 100644 stack-lts-18.28.yaml.lock diff --git a/stack-lts-18.28.yaml b/stack-lts-18.28.yaml new file mode 100644 index 0000000..d46e965 --- /dev/null +++ b/stack-lts-18.28.yaml @@ -0,0 +1,21 @@ +resolver: lts-18.28 + +packages: + - . +extra-deps: + - aeson-2.2.0.0 + - timing-convenience-0.1@sha256:7ff807a9a9e5596f2b18d45c5a01aefb91d4a98f6a1008d183b5c550f68f7cb7,2092 + - resource-pool-0.4.0.0@sha256:9c1e448a159875e21a7e68697feee2b61a4e584720974fa465a2fa1bc0776c73,1342 + - integer-conversion-0.1@sha256:9f77cc7711d3100a4483f2dd1a22f4be5b59d235a556d910d0e6c5e90a967551,2208 + - text-iso8601-0.1@sha256:fc10d8de72fc094d0d299644f17421b9430d1c1092a1355c7f0c02d8b6edf6a7,2371 + - th-abstraction-0.5.0.0@sha256:4351cadf6bf0ca80c90225bae0b12f4cfdd550f30c333b050186af5a8bc19457,2236 + - servant-0.20.1 + - servant-server-0.20 + - postgresql-simple-0.6.5.1 + - generically-0.1.1 + - servant-lucid-0.9.0.6 + - servant-static-th-1.0.0.0 + - semialign-1.3 + - OneTuple-0.3.1 + +allow-newer: true diff --git a/stack-lts-18.28.yaml.lock b/stack-lts-18.28.yaml.lock new file mode 100644 index 0000000..7b48d4c --- /dev/null +++ b/stack-lts-18.28.yaml.lock @@ -0,0 +1,110 @@ +# This file was autogenerated by Stack. +# You should not edit this file by hand. +# For more information, please see the documentation at: +# https://docs.haskellstack.org/en/stable/lock_files + +packages: +- completed: + hackage: aeson-2.2.0.0@sha256:deeab33f7f2a235c9e9ea76168f27a3669ad51bbdb363e830015352a3b2874ec,6217 + pantry-tree: + sha256: 2c65659ff9ab19047728c8cc2f20869ba7ca78a09fe03cecf826f5857f3d4c95 + size: 83036 + original: + hackage: aeson-2.2.0.0 +- completed: + hackage: timing-convenience-0.1@sha256:7ff807a9a9e5596f2b18d45c5a01aefb91d4a98f6a1008d183b5c550f68f7cb7,2092 + pantry-tree: + sha256: fbcb00f5b8a4f7b8fd94b034b7f507ffdd7579848de782ce60ad2b661dcb2b42 + size: 469 + original: + hackage: timing-convenience-0.1@sha256:7ff807a9a9e5596f2b18d45c5a01aefb91d4a98f6a1008d183b5c550f68f7cb7,2092 +- completed: + hackage: resource-pool-0.4.0.0@sha256:9c1e448a159875e21a7e68697feee2b61a4e584720974fa465a2fa1bc0776c73,1342 + pantry-tree: + sha256: 1008fbb9b6bd9d12925989f2708af612daa3a8ebf3a56763016231461d9e314f + size: 406 + original: + hackage: resource-pool-0.4.0.0@sha256:9c1e448a159875e21a7e68697feee2b61a4e584720974fa465a2fa1bc0776c73,1342 +- completed: + hackage: integer-conversion-0.1@sha256:9f77cc7711d3100a4483f2dd1a22f4be5b59d235a556d910d0e6c5e90a967551,2208 + pantry-tree: + sha256: 17063e15091711b54f9a4a9ccb032f3c2ed68bb4ba097243333469ad8462b748 + size: 509 + original: + hackage: integer-conversion-0.1@sha256:9f77cc7711d3100a4483f2dd1a22f4be5b59d235a556d910d0e6c5e90a967551,2208 +- completed: + hackage: text-iso8601-0.1@sha256:fc10d8de72fc094d0d299644f17421b9430d1c1092a1355c7f0c02d8b6edf6a7,2371 + pantry-tree: + sha256: f72aa62f5f4d1155b3d3f35e8227548a27cee83fb5d0742564b5ef26597f1431 + size: 427 + original: + hackage: text-iso8601-0.1@sha256:fc10d8de72fc094d0d299644f17421b9430d1c1092a1355c7f0c02d8b6edf6a7,2371 +- completed: + hackage: th-abstraction-0.5.0.0@sha256:4351cadf6bf0ca80c90225bae0b12f4cfdd550f30c333b050186af5a8bc19457,2236 + pantry-tree: + sha256: f1e547789ee75cf1d880c2dd6498254e9a37de052842b573b43c4b4a1ebcfd6d + size: 670 + original: + hackage: th-abstraction-0.5.0.0@sha256:4351cadf6bf0ca80c90225bae0b12f4cfdd550f30c333b050186af5a8bc19457,2236 +- completed: + hackage: servant-0.20.1@sha256:ec6b11132f3448a0f7daa6b3d0daf2634062017df89855c6b9d8268944c72243,5436 + pantry-tree: + sha256: 1d165bc7ebf50280ba39191112eba0368bb9af55b7345bc17318fdcf803efdba + size: 2873 + original: + hackage: servant-0.20.1 +- completed: + hackage: servant-server-0.20@sha256:1bb179f028b0b2b28222f04bd589f9fbc6f855194e73a7cbc692e097f3b30574,5739 + pantry-tree: + sha256: 8ae235fc825018111ecfeb74fe63753010ed4585a1fc391422b8083ce3ba3ae8 + size: 2615 + original: + hackage: servant-server-0.20 +- completed: + hackage: postgresql-simple-0.6.5.1@sha256:527939755637c1ea3fdad2819a7725e63d0a01931678e631549367c9faedc620,5280 + pantry-tree: + sha256: b945116ff80da1f0638914d900459a8eb64b675c238d7ab87b81f16cf01d75c1 + size: 4197 + original: + hackage: postgresql-simple-0.6.5.1 +- completed: + hackage: generically-0.1.1@sha256:378ec049bc2853b8011df116647fbd34bb9f00edce9840e4957f98abc097597c,1169 + pantry-tree: + sha256: 9f30503d1fe709f3849c5dd8b9751697a8db4d66105d7ba9c3b98bf4e36bb232 + size: 233 + original: + hackage: generically-0.1.1 +- completed: + hackage: servant-lucid-0.9.0.6@sha256:4a557ab3c535f9e267b0f614375aa2d9db070997ac566d5ffde8d8cb47a51376,1804 + pantry-tree: + sha256: d1c55089c3d69efb3ebf0ddd913eb2e3582e58d849d78116cc0b417a049b0a9f + size: 392 + original: + hackage: servant-lucid-0.9.0.6 +- completed: + hackage: servant-static-th-1.0.0.0@sha256:7dc46a426d8c78ee0386729159e8bbc18ff98e0dd700a2c723c87901b204fa6c,3883 + pantry-tree: + sha256: 13269fcc1c871ee1548d31010f0278484318bffbd9b8e0c0bfdfab4e27d6c3d5 + size: 1493 + original: + hackage: servant-static-th-1.0.0.0 +- completed: + hackage: semialign-1.3@sha256:7be9ef5ca1d6b052991f68c053aab68b9d1ab3b1938c9557ac84c97937815223,2888 + pantry-tree: + sha256: e5daa7e0023dabb1b21a04bf084364b94e45e81b380e950b90f51294a1990b87 + size: 537 + original: + hackage: semialign-1.3 +- completed: + hackage: OneTuple-0.3.1@sha256:fc32cb744477befa450a538ea4975cc523f0a2f1585cb5a36e9936a3d18e9a3c,2276 + pantry-tree: + sha256: a45de98364d5a128ffcc07a05f2f3dd0befee311c7e106bc86dc87548288bc6b + size: 506 + original: + hackage: OneTuple-0.3.1 +snapshots: +- completed: + sha256: 428ec8d5ce932190d3cbe266b9eb3c175cd81e984babf876b64019e2cbe4ea68 + size: 590100 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/18/28.yaml + original: lts-18.28 diff --git a/test/Test.hs b/test/Test.hs index de27912..4e5261b 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -48,6 +48,7 @@ import qualified OddJobs.ConfigBuilder as Job import UnliftIO import Control.Exception (ArithException) import Data.Bifunctor(first) +import System.Environment (lookupEnv) $(Aeson.deriveJSON Aeson.defaultOptions ''Seconds) @@ -57,24 +58,29 @@ main = do bracket createJobPool destroyAllResources $ \jobPool -> do defaultMain $ tests appPool jobPool where - connInfo = ConnectInfo - { connectHost = "localhost" - , connectPort = fromIntegral (5432 :: Int) - , connectUser = "jobs_test" - , connectPassword = "jobs_test" - , connectDatabase = "jobs_test" - } - - createAppPool = Pool.newPool $ Pool.defaultPoolConfig - (PGS.connect connInfo) -- create a new resource - PGS.close -- destroy resource - (fromRational 10) -- number of seconds unused resources are kept around - 45 - createJobPool = Pool.newPool $ Pool.defaultPoolConfig - (PGS.connect connInfo) -- create a new resource - PGS.close -- destroy resource - (fromRational 10) -- number of seconds unused resources are kept around - 45 + getConnInfo = do + connectHost <- fromMaybe "localhost" <$> lookupEnv "PGHOST" + connectUser <- fromMaybe "jobs_test" <$> lookupEnv "PGUSER" + connectPassword <- fromMaybe "jobs_test" <$> lookupEnv "PGPASSWORD" + connectDatabase <- fromMaybe "jobs_test" <$> lookupEnv "PGDATABASE" + connectPort <- maybe (fromIntegral (5432 :: Int)) read <$> lookupEnv "PGPORT" + pure ConnectInfo{..} + + createAppPool = do + connInfo <- getConnInfo + Pool.newPool $ Pool.defaultPoolConfig + (PGS.connect connInfo) -- create a new resource + PGS.close -- destroy resource + (fromRational 10) -- number of seconds unused resources are kept around + 45 + + createJobPool = do + connInfo <- getConnInfo + Pool.newPool $ Pool.defaultPoolConfig + (PGS.connect connInfo) -- create a new resource + PGS.close -- destroy resource + (fromRational 10) -- number of seconds unused resources are kept around + 45 tests appPool jobPool = testGroup "All tests" [