-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
name: Test | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- master | ||
|
||
concurrency: | ||
group: ${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
mongodb: | ||
- mongo:4.0 | ||
- mongo:5.0 | ||
- mongo:6.0 | ||
- mongo:7.0 | ||
- mongo_atlas | ||
ghc: | ||
- "8.10.4" | ||
- "9.4.7" # oldest version with HLS support | ||
- latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Setup Haskell tooling | ||
uses: haskell-actions/setup@v2 | ||
with: | ||
enable-stack: true | ||
ghc-version: ${{ matrix.ghc }} | ||
stack-version: latest | ||
|
||
- name: Setup container and run tests | ||
run: | | ||
# the job-level 'if' expression is evaluated before the matrix variable | ||
# so it cannot be used to configure this step | ||
if [[ ${{ matrix.mongodb }} = "mongo_atlas" ]] | ||
then | ||
export CONNECTION_STRING=${{ secrets.CONNECTION_STRING }} | ||
else | ||
docker run -d \ | ||
-p 27017:27017 \ | ||
-e MONGO_INITDB_ROOT_USERNAME=testadmin \ | ||
-e MONGO_INITDB_ROOT_PASSWORD=123 \ | ||
${{ matrix.mongodb }} | ||
fi | ||
# build & run tests | ||
export MONGO_VERSION=${{ matrix.mongodb }} | ||
stack test --fast |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
module Main where | ||
|
||
import Database.MongoDB.Admin (serverVersion) | ||
import Database.MongoDB.Connection (connect, host) | ||
import Database.MongoDB.Query (access, slaveOk) | ||
import Data.Text (unpack) | ||
import Control.Exception (assert) | ||
import Control.Monad (when) | ||
import Data.Maybe (isJust) | ||
import qualified Spec | ||
import System.Environment (getEnv, lookupEnv) | ||
import Test.Hspec.Runner | ||
import System.Environment (getEnv) | ||
import System.IO.Error (catchIOError) | ||
import TestImport | ||
Check warning on line 9 in test/Main.hs GitHub Actions / test (mongo_atlas, 8.10.4)
Check warning on line 9 in test/Main.hs GitHub Actions / test (mongo:4.0, latest)
Check warning on line 9 in test/Main.hs GitHub Actions / test (mongo:7.0, latest)
Check warning on line 9 in test/Main.hs GitHub Actions / test (mongo:4.0, 8.10.4)
Check warning on line 9 in test/Main.hs GitHub Actions / test (mongo:5.0, 8.10.4)
Check warning on line 9 in test/Main.hs GitHub Actions / test (mongo:4.0, 9.4.7)
Check warning on line 9 in test/Main.hs GitHub Actions / test (mongo:6.0, 9.4.7)
Check warning on line 9 in test/Main.hs GitHub Actions / test (mongo:5.0, latest)
Check warning on line 9 in test/Main.hs GitHub Actions / test (mongo:5.0, 9.4.7)
Check warning on line 9 in test/Main.hs GitHub Actions / test (mongo:6.0, latest)
Check warning on line 9 in test/Main.hs GitHub Actions / test (mongo:6.0, 8.10.4)
Check warning on line 9 in test/Main.hs GitHub Actions / test (mongo_atlas, 9.4.7)
Check warning on line 9 in test/Main.hs GitHub Actions / test (mongo:7.0, 8.10.4)
Check warning on line 9 in test/Main.hs GitHub Actions / test (mongo:7.0, 9.4.7)
|
||
import qualified Spec | ||
|
||
main :: IO () | ||
main = do | ||
mongodbHost <- getEnv mongodbHostEnvVariable `catchIOError` (\_ -> return "localhost") | ||
p <- connect $ host mongodbHost | ||
version <- access p slaveOk "admin" serverVersion | ||
putStrLn $ "Running tests with mongodb version: " ++ (unpack version) | ||
version <- getEnv "MONGO_VERSION" | ||
when (version == "mongo_atlas") $ do | ||
connection_string <- lookupEnv "CONNECTION_STRING" | ||
pure $ assert (isJust connection_string) () | ||
hspecWith defaultConfig Spec.spec |