diff --git a/.circleci/config.yml b/.circleci/config.yml index c4f7105ab..a358b6b94 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -325,12 +325,6 @@ jobs: name: run memory usage tests command: | test/create_test_db "postgres://circleci@localhost" postgrest_test - psql "postgres:///postgrest_test" -f test/fixtures/database.sql - psql "postgres:///postgrest_test" -f test/fixtures/roles.sql - psql "postgres:///postgrest_test" -f test/fixtures/schema.sql - psql "postgres:///postgrest_test" -f test/fixtures/jwt.sql - psql "postgres:///postgrest_test" -f test/fixtures/jsonschema.sql - psql "postgres:///postgrest_test" -f test/fixtures/privileges.sql test/memory-tests.sh centos7: diff --git a/test/Main.hs b/test/Main.hs index d713942b4..2b4c6b95b 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -56,7 +56,6 @@ main = do getTime <- mkAutoUpdate defaultUpdateSettings { updateAction = getCurrentTime } testDbConn <- getEnvVarWithDefault "POSTGREST_TEST_CONNECTION" "postgres://postgrest_test@localhost/postgrest_test" - setupDb testDbConn pool <- P.acquire (3, 10, toS testDbConn) diff --git a/test/QueryCost.hs b/test/QueryCost.hs index 2ef2a756c..81a3619f6 100644 --- a/test/QueryCost.hs +++ b/test/QueryCost.hs @@ -23,7 +23,6 @@ import Test.Hspec main :: IO () main = do testDbConn <- getEnvVarWithDefault "POSTGREST_TEST_CONNECTION" "postgres://postgrest_test@localhost/postgrest_test" - -- To speed things up, assume setupDb has ben ran in the previous spec. pool <- P.acquire (3, 10, toS testDbConn) hspec $ describe "QueryCost" $ diff --git a/test/SpecHelper.hs b/test/SpecHelper.hs index 41ad4659e..1a12df623 100644 --- a/test/SpecHelper.hs +++ b/test/SpecHelper.hs @@ -145,16 +145,6 @@ testCfgResponseHeaders testDbConn = (testCfg testDbConn) { configReqCheck = Just testMultipleSchemaCfg :: Text -> AppConfig testMultipleSchemaCfg testDbConn = (testCfg testDbConn) { configSchemas = fromList ["v1", "v2"] } -setupDb :: Text -> IO () -setupDb dbConn = do - loadFixture dbConn "database" - loadFixture dbConn "roles" - loadFixture dbConn "schema" - loadFixture dbConn "jwt" - loadFixture dbConn "jsonschema" - loadFixture dbConn "privileges" - resetDb dbConn - resetDb :: Text -> IO () resetDb dbConn = loadFixture dbConn "data" diff --git a/test/create_test_db b/test/create_test_db index 2f447e4e9..b54708935 100755 --- a/test/create_test_db +++ b/test/create_test_db @@ -55,6 +55,8 @@ ALTER DATABASE $DB SET LC_MESSAGES = 'POSIX'; ALTER DATABASE $DB SET LC_MONETARY = 'POSIX'; ALTER DATABASE $DB SET LC_NUMERIC = 'POSIX'; ALTER DATABASE $DB SET LC_TIME = 'POSIX'; + +\i $BASEPATH/fixtures/load.sql EOF #Remove database path from the connection uri--prevents setting up the new database name with PGDATABASE diff --git a/test/fixtures/jsonschema.sql b/test/fixtures/jsonschema.sql index 9b3df794e..629d7e1e2 100644 --- a/test/fixtures/jsonschema.sql +++ b/test/fixtures/jsonschema.sql @@ -20,7 +20,7 @@ HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. */ -CREATE OR REPLACE FUNCTION _validate_json_schema_type(type text, data jsonb) RETURNS boolean AS $f$ +CREATE OR REPLACE FUNCTION public._validate_json_schema_type(type text, data jsonb) RETURNS boolean AS $f$ BEGIN IF type = 'integer' THEN IF jsonb_typeof(data) != 'number' THEN diff --git a/test/fixtures/jwt.sql b/test/fixtures/jwt.sql index 554034e1e..d75930a87 100644 --- a/test/fixtures/jwt.sql +++ b/test/fixtures/jwt.sql @@ -1,5 +1,8 @@ -- From michelp/pgjwt commit c02bbd3 BEGIN; + +set search_path to public; + set client_min_messages to warning; DROP SCHEMA IF EXISTS jwt CASCADE; CREATE SCHEMA jwt; diff --git a/test/fixtures/load.sql b/test/fixtures/load.sql new file mode 100644 index 000000000..c73f86b7b --- /dev/null +++ b/test/fixtures/load.sql @@ -0,0 +1,11 @@ +-- Loads all fixtures for the PostgREST tests + +\set ON_ERROR_STOP on + +\ir database.sql +\ir roles.sql +\ir schema.sql +\ir jwt.sql +\ir jsonschema.sql +\ir privileges.sql +\ir data.sql diff --git a/test/with_tmp_db b/test/with_tmp_db index 37bb285bb..f325ff8c2 100755 --- a/test/with_tmp_db +++ b/test/with_tmp_db @@ -35,7 +35,6 @@ if [ "$#" -lt 1 ]; then fi rootdir="$(git rev-parse --show-toplevel)" -fixturesdir="$rootdir/test/fixtures" # All data will be stored in a temporary directory. tmpdir="$(mktemp -d)" @@ -97,13 +96,7 @@ psql -v ON_ERROR_STOP=1 >> "$setuplog" << EOF create extension pgcrypto; alter database $PGDATABASE set request.jwt.claim.id = '-1'; alter role $PGUSER set default_text_search_config to english; - - \i $fixturesdir/database.sql - \i $fixturesdir/roles.sql - \i $fixturesdir/schema.sql - \i $fixturesdir/jwt.sql - \i $fixturesdir/jsonschema.sql - \i $fixturesdir/privileges.sql + \i $rootdir/test/fixtures/load.sql EOF log "Done. Running command..."