From e0a0033116e4b2d06773cd480f87cee715520412 Mon Sep 17 00:00:00 2001 From: Kyle Fazzari Date: Tue, 24 Jan 2023 11:10:06 -0800 Subject: [PATCH] spec/support/database: support running postgres in docker Add a docker-compose.yml file that sets up a PostgreSQL image configured to run pg_search's test suite. Add support to `spec/support/database` for using that container's PostgreSQL instance to run the test suite by simply checking if the `DOCKER` environment variable is set. Signed-off-by: Kyle Fazzari --- docker-compose.yml | 11 +++++++++++ spec/support/database.rb | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..da4c0af9 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +version: '3.2' + +services: + postgres: + image: postgres:12 + ports: + - 5432:5432 + restart: on-failure + environment: + POSTGRES_PASSWORD: postgres + POSTGRES_DB: pg_search_test diff --git a/spec/support/database.rb b/spec/support/database.rb index ea31b63f..b5e0034e 100644 --- a/spec/support/database.rb +++ b/spec/support/database.rb @@ -11,10 +11,11 @@ begin connection_options = { adapter: 'postgresql', database: 'pg_search_test', min_messages: 'warning' } - if ENV["CI"] + if ENV["CI"] || ENV["DOCKER"] connection_options[:username] = 'postgres' connection_options[:password] = 'postgres' end + connection_options[:host] = 'localhost' if ENV["DOCKER"] ActiveRecord::Base.establish_connection(connection_options) connection = ActiveRecord::Base.connection connection.execute("SELECT 1")