diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-11-16 13:39:08 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-11-16 14:32:03 +0300 |
commit | 0ae490dfa7899af26695a9ff0c8c4f090c9dc9dd (patch) | |
tree | ccd4d9a05ed25fcbfd976e765d0119da04df1573 | |
parent | 8f04e23b9f004d70635aaeecd30d837a584572f8 (diff) |
ruby: Create test data in temporary directory
Test data for our rspecs is currently created inside of the worktree in
"ruby/tmp". This is bad practice, and we have long since converted our
Go tests to use temporary directories instead.
Convert rspecs to do the same and remove the corresponding ignore rule.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | ruby/spec/lib/gitlab/git/remote_repository_client_spec.rb | 2 | ||||
-rw-r--r-- | ruby/spec/spec_helper.rb | 7 | ||||
-rw-r--r-- | ruby/spec/support/helpers/integration_helper.rb | 4 | ||||
-rw-r--r-- | ruby/spec/test_repo_helper.rb | 2 |
5 files changed, 9 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore index 8e0817d8f..3659a9723 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,6 @@ /.ruby-bundle /ruby/vendor/bundle /ruby/.bundle -/ruby/tmp /gitaly-*.gem # Configuration and runtime data diff --git a/ruby/spec/lib/gitlab/git/remote_repository_client_spec.rb b/ruby/spec/lib/gitlab/git/remote_repository_client_spec.rb index 8375a0187..a52d060c1 100644 --- a/ruby/spec/lib/gitlab/git/remote_repository_client_spec.rb +++ b/ruby/spec/lib/gitlab/git/remote_repository_client_spec.rb @@ -113,7 +113,7 @@ describe Gitlab::Git::GitalyRemoteRepository do end context 'unix' do - let(:client) { get_client("unix:#{File.join(TMP_DIR_NAME, SOCKET_PATH)}") } + let(:client) { get_client("unix:#{File.join(TMP_DIR, SOCKET_PATH)}") } it 'Should connect over unix' do expect(client).not_to be_empty diff --git a/ruby/spec/spec_helper.rb b/ruby/spec/spec_helper.rb index 631cb0a78..52296007e 100644 --- a/ruby/spec/spec_helper.rb +++ b/ruby/spec/spec_helper.rb @@ -7,8 +7,7 @@ require 'factory_bot' require 'pry' GITALY_RUBY_DIR = File.expand_path('..', __dir__).freeze -TMP_DIR_NAME = 'tmp'.freeze -TMP_DIR = File.join(GITALY_RUBY_DIR, TMP_DIR_NAME).freeze +TMP_DIR = Dir.mktmpdir('gitaly-ruby-tests-').freeze GITLAB_SHELL_DIR = File.join(TMP_DIR, 'gitlab-shell').freeze # overwrite HOME env variable so user global .gitconfig doesn't influence tests @@ -24,4 +23,8 @@ RSpec.configure do |config| config.before(:suite) do FactoryBot.find_definitions end + + config.after(:suite) do + FileUtils.rm_rf(TMP_DIR) + end end diff --git a/ruby/spec/support/helpers/integration_helper.rb b/ruby/spec/support/helpers/integration_helper.rb index bd2af3fd8..5d3a1ef7c 100644 --- a/ruby/spec/support/helpers/integration_helper.rb +++ b/ruby/spec/support/helpers/integration_helper.rb @@ -34,7 +34,7 @@ module IntegrationClient klass = Gitaly.const_get(service).const_get(:Stub) addr = case type when 'unix' - "unix:#{File.join(TMP_DIR_NAME, SOCKET_PATH)}" + "unix:#{File.join(TMP_DIR, SOCKET_PATH)}" when 'tcp', 'tls' "#{type}://localhost:#{GitalyConfig.dynamic_port(type)}" end @@ -101,7 +101,7 @@ def start_gitaly gitaly_pid = spawn(File.join(build_dir, 'bin/gitaly'), config_path, options) at_exit { Process.kill('KILL', gitaly_pid) } - wait_ready!(File.join(TMP_DIR_NAME, SOCKET_PATH)) + wait_ready!(File.join(TMP_DIR, SOCKET_PATH)) end def wait_ready!(socket) diff --git a/ruby/spec/test_repo_helper.rb b/ruby/spec/test_repo_helper.rb index 682476fad..8a0b25cb4 100644 --- a/ruby/spec/test_repo_helper.rb +++ b/ruby/spec/test_repo_helper.rb @@ -10,7 +10,7 @@ Gitlab.config.git.test_global_ivar_override(:bin_path, ENV.fetch('GITALY_TESTING Gitlab.config.git.test_global_ivar_override(:hooks_directory, File.join(GITALY_RUBY_DIR, "hooks")) Gitlab.config.gitaly.test_global_ivar_override(:bin_dir, __dir__) -DEFAULT_STORAGE_DIR = File.expand_path('../tmp/repositories', __dir__) +DEFAULT_STORAGE_DIR = File.join(TMP_DIR, 'repositories', __dir__) DEFAULT_STORAGE_NAME = 'default'.freeze TEST_REPO_PATH = File.join(DEFAULT_STORAGE_DIR, 'gitlab-test.git') TEST_REPO_ORIGIN = '../_build/testrepos/gitlab-test.git'.freeze |