-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for running tests against different DB adapters (#120)
- Loading branch information
1 parent
ac27805
commit 5607d6b
Showing
18 changed files
with
238 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -222,6 +222,7 @@ GEM | |
zeitwerk (2.6.12) | ||
|
||
PLATFORMS | ||
arm64-darwin-22 | ||
arm64-darwin-23 | ||
x86_64-darwin-20 | ||
x86_64-darwin-22 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
version: '3.8' | ||
|
||
services: | ||
postgres: | ||
image: postgres:14 | ||
environment: | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: password | ||
POSTGRES_DB: actual_db_schema_test | ||
ports: | ||
- "5432:5432" | ||
volumes: | ||
- ./docker/postgres-init:/docker-entrypoint-initdb.d | ||
|
||
mysql: | ||
image: mysql:8.0 | ||
environment: | ||
MYSQL_ROOT_PASSWORD: password | ||
MYSQL_DATABASE: actual_db_schema_test | ||
ports: | ||
- "3306:3306" | ||
volumes: | ||
- ./docker/mysql-init:/docker-entrypoint-initdb.d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE DATABASE actual_db_schema_test_secondary; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE DATABASE actual_db_schema_test_secondary; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# frozen_string_literal: true | ||
|
||
namespace :test do # rubocop:disable Metrics/BlockLength | ||
desc "Run tests with SQLite3" | ||
task :sqlite3 do | ||
ENV["DB_ADAPTER"] = "sqlite3" | ||
Rake::Task["test"].invoke | ||
Rake::Task["test"].reenable | ||
end | ||
|
||
desc "Run tests with PostgreSQL" | ||
task :postgresql do | ||
sh "docker-compose up -d postgres" | ||
wait_for_postgres | ||
|
||
begin | ||
ENV["DB_ADAPTER"] = "postgresql" | ||
Rake::Task["test"].invoke | ||
Rake::Task["test"].reenable | ||
ensure | ||
sh "docker-compose down" | ||
end | ||
end | ||
|
||
desc "Run tests with MySQL" | ||
task :mysql2 do | ||
sh "docker-compose up -d mysql" | ||
wait_for_mysql | ||
|
||
begin | ||
ENV["DB_ADAPTER"] = "mysql2" | ||
Rake::Task["test"].invoke | ||
Rake::Task["test"].reenable | ||
ensure | ||
sh "docker-compose down" | ||
end | ||
end | ||
|
||
desc "Run tests with all adapters (SQLite3, PostgreSQL, MySQL)" | ||
task all: %i[sqlite3 postgresql mysql2] | ||
|
||
def wait_for_postgres | ||
retries = 10 | ||
begin | ||
sh "docker-compose exec -T postgres pg_isready -U postgres" | ||
rescue StandardError | ||
retries -= 1 | ||
|
||
raise "PostgreSQL is not ready after several attempts." if retries < 1 | ||
|
||
sleep 2 | ||
retry | ||
end | ||
end | ||
|
||
def wait_for_mysql | ||
retries = 10 | ||
begin | ||
sh "docker-compose exec -T mysql mysqladmin ping -h 127.0.0.1 --silent" | ||
rescue StandardError | ||
retries -= 1 | ||
|
||
raise "MySQL is not ready after several attempts." if retries < 1 | ||
|
||
sleep 2 | ||
retry | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.