Skip to content

Commit 9118912

Browse files
authored
Merge pull request #375 from Shopify/grodowski/reorganise-tests-vscode
Reorganise Ruby tests
2 parents 24001d1 + b45dcda commit 9118912

File tree

8 files changed

+46
-42
lines changed

8 files changed

+46
-42
lines changed

.github/workflows/tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ jobs:
8585
run: .github/workflows/start-mysql.sh
8686

8787
- name: Running Ruby tests
88-
run: bundle exec ruby test/main.rb
88+
run: bundle exec rake test
8989

9090
build-debs:
9191
strategy:

Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ source "https://rubygems.org"
22

33
group :test do
44
gem "minitest"
5+
gem "rake"
56
gem "mysql2"
67
gem "webrick"
78

Gemfile.lock

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ GEM
2525
pry-byebug (3.10.1)
2626
byebug (~> 11.0)
2727
pry (>= 0.13, < 0.15)
28+
rake (13.2.1)
2829
ruby-progressbar (1.13.0)
2930
tqdm (0.4.1)
3031
webrick (1.8.1)
@@ -40,6 +41,7 @@ DEPENDENCIES
4041
minitest-retry
4142
mysql2
4243
pry-byebug
44+
rake
4345
tqdm
4446
webrick
4547

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ test-go:
6868

6969
test-ruby:
7070
bundle install
71-
bundle exec ruby test/main.rb
71+
bundle exec rake test
7272

7373
test: test-go test-ruby
7474

README.md

+16-2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ Kindly take note of following options:
6565
- `DEBUG=1`: To see more detailed debug output by `Ghostferry` live, as opposed
6666
to only when the test fails. This is helpful for debugging hanging test.
6767

68-
Example:
68+
Examples:
6969

70-
`DEBUG=1 ruby test/main.rb -v -n "TrivialIntegrationTests#test_logged_query_omits_columns"`
70+
Run all tests
71+
72+
`rake test`
73+
74+
Run a single file
75+
76+
`rake test TEST=test/integration/trivial_test.rb`
77+
78+
or
79+
80+
`ruby -Itest test/integration/trivial_test.rb`
81+
82+
Run a specific test
83+
84+
`DEBUG=1 ruby -Itest test/integration/trivial_test.rb -n "TrivialIntegrationTest#test_logged_query_omits_columns"`

test/integration/trivial_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require "test_helper"
22

3-
class TrivialIntegrationTests < GhostferryTestCase
3+
class TrivialIntegrationTest < GhostferryTestCase
44
def test_copy_data_without_any_writes_to_source
55
seed_simple_database_with_single_table
66

test/main.rb

-36
This file was deleted.

test/test_helper.rb

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,38 @@
11
require "stringio"
22
require "logger"
3-
3+
require "minitest"
4+
require "minitest/autorun"
5+
require "minitest/reporters"
6+
require "minitest/retry"
7+
require "minitest/fail_fast"
8+
require "minitest/hooks/test"
49
require "pry-byebug" unless ENV["CI"]
510

611
GO_CODE_PATH = File.join(File.absolute_path(File.dirname(__FILE__)), "lib", "go")
712
FIXTURE_PATH = File.join(File.absolute_path(File.dirname(__FILE__)), "fixtures")
813

14+
def add_to_load_path(path)
15+
$LOAD_PATH.unshift(path) unless $LOAD_PATH.include?(path)
16+
end
17+
18+
test_path = File.expand_path(File.dirname(__FILE__))
19+
test_lib_path = File.join(test_path, "lib")
20+
lib_path = File.expand_path(File.join(test_path, "..", "lib"))
21+
helpers_path = File.join(test_path, "helpers")
22+
23+
[test_path, test_lib_path, lib_path, helpers_path].each { add_to_load_path(_1) }
24+
925
require "db_helper"
1026
require "ghostferry_helper"
1127
require "data_writer_helper"
1228

29+
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
30+
Minitest::Retry.use!(exceptions_to_retry: [GhostferryHelper::Ghostferry::TimeoutError])
31+
32+
at_exit do
33+
GhostferryHelper.remove_all_binaries
34+
end
35+
1336
class LogCapturer
1437
attr_reader :logger
1538

0 commit comments

Comments
 (0)