diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6e354b2b..60729ddd 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -85,7 +85,7 @@ jobs: run: .github/workflows/start-mysql.sh - name: Running Ruby tests - run: bundle exec ruby test/main.rb + run: bundle exec rake test build-debs: strategy: diff --git a/Gemfile b/Gemfile index b3cdbf46..2903d26b 100644 --- a/Gemfile +++ b/Gemfile @@ -2,6 +2,7 @@ source "https://rubygems.org" group :test do gem "minitest" + gem "rake" gem "mysql2" gem "webrick" diff --git a/Gemfile.lock b/Gemfile.lock index c83f95e1..fd69a5fa 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -25,6 +25,7 @@ GEM pry-byebug (3.10.1) byebug (~> 11.0) pry (>= 0.13, < 0.15) + rake (13.2.1) ruby-progressbar (1.13.0) tqdm (0.4.1) webrick (1.8.1) @@ -40,6 +41,7 @@ DEPENDENCIES minitest-retry mysql2 pry-byebug + rake tqdm webrick diff --git a/Makefile b/Makefile index e9480578..244f6bde 100644 --- a/Makefile +++ b/Makefile @@ -68,7 +68,7 @@ test-go: test-ruby: bundle install - bundle exec ruby test/main.rb + bundle exec rake test test: test-go test-ruby diff --git a/README.md b/README.md index 3febd576..74258aa8 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,20 @@ Kindly take note of following options: - `DEBUG=1`: To see more detailed debug output by `Ghostferry` live, as opposed to only when the test fails. This is helpful for debugging hanging test. -Example: +Examples: -`DEBUG=1 ruby test/main.rb -v -n "TrivialIntegrationTests#test_logged_query_omits_columns"` +Run all tests + +`rake test` + +Run a single file + +`rake test TEST=test/integration/trivial_test.rb` + +or + +`ruby -Itest test/integration/trivial_test.rb` + +Run a specific test + +`DEBUG=1 ruby -Itest test/integration/trivial_test.rb -n "TrivialIntegrationTest#test_logged_query_omits_columns"` diff --git a/test/integration/trivial_test.rb b/test/integration/trivial_test.rb index 246d31ba..59e95303 100644 --- a/test/integration/trivial_test.rb +++ b/test/integration/trivial_test.rb @@ -1,6 +1,6 @@ require "test_helper" -class TrivialIntegrationTests < GhostferryTestCase +class TrivialIntegrationTest < GhostferryTestCase def test_copy_data_without_any_writes_to_source seed_simple_database_with_single_table diff --git a/test/main.rb b/test/main.rb deleted file mode 100644 index eaad9d0c..00000000 --- a/test/main.rb +++ /dev/null @@ -1,36 +0,0 @@ -# frozen_string_literal: true -test_path = File.expand_path(File.dirname(__FILE__)) -test_lib_path = File.join(test_path, "lib") -lib_path = File.expand_path(File.join(test_path, "..", "lib")) -helpers_path = File.join(test_path, "helpers") -integration_path = File.join(test_path, "integration") -test_files = Dir.glob("#{integration_path}/**/*_test.rb") - -$LOAD_PATH.unshift(test_path) unless $LOAD_PATH.include?(test_path) -$LOAD_PATH.unshift(test_lib_path) unless $LOAD_PATH.include?(test_lib_path) -$LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path) -$LOAD_PATH.unshift(helpers_path) unless $LOAD_PATH.include?(helpers_path) - -require "ghostferry_helper" - -require "minitest" -require "minitest/reporters" -require "minitest/retry" -require "minitest/fail_fast" -require "minitest/hooks/test" - -Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new -Minitest::Retry.use!(exceptions_to_retry: [GhostferryHelper::Ghostferry::TimeoutError]) - -test_files.each do |f| - require f -end - -exit_code = 1 - -at_exit do - GhostferryHelper.remove_all_binaries - exit(exit_code) -end - -exit_code = Minitest.run(ARGV) diff --git a/test/test_helper.rb b/test/test_helper.rb index 9b9f8b4f..a3a5ba5a 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,15 +1,38 @@ require "stringio" require "logger" - +require "minitest" +require "minitest/autorun" +require "minitest/reporters" +require "minitest/retry" +require "minitest/fail_fast" +require "minitest/hooks/test" require "pry-byebug" unless ENV["CI"] GO_CODE_PATH = File.join(File.absolute_path(File.dirname(__FILE__)), "lib", "go") FIXTURE_PATH = File.join(File.absolute_path(File.dirname(__FILE__)), "fixtures") +def add_to_load_path(path) + $LOAD_PATH.unshift(path) unless $LOAD_PATH.include?(path) +end + +test_path = File.expand_path(File.dirname(__FILE__)) +test_lib_path = File.join(test_path, "lib") +lib_path = File.expand_path(File.join(test_path, "..", "lib")) +helpers_path = File.join(test_path, "helpers") + +[test_path, test_lib_path, lib_path, helpers_path].each { add_to_load_path(_1) } + require "db_helper" require "ghostferry_helper" require "data_writer_helper" +Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new +Minitest::Retry.use!(exceptions_to_retry: [GhostferryHelper::Ghostferry::TimeoutError]) + +at_exit do + GhostferryHelper.remove_all_binaries +end + class LogCapturer attr_reader :logger