diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2018-02-28 20:36:55 +0100 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2018-02-28 20:36:55 +0100 |
commit | 965dc28691e2d70b7040e28d90ccbc3721a9e416 (patch) | |
tree | 84258f35b72f2e7ce6a7198db66032df4ad5aadb /spec/tasks | |
parent | e3fafa7632e038927085cf8c8228c93be44b36bd (diff) | |
parent | 7fabc892f251740dbd9a4755baede662e6854870 (diff) | |
download | gitlab-ce-965dc28691e2d70b7040e28d90ccbc3721a9e416.tar.gz |
Merge commit '7fabc892f251740dbd9a4755baede662e6854870' into object-storage-ee-to-ce-backport
Diffstat (limited to 'spec/tasks')
-rw-r--r-- | spec/tasks/gitlab/backup_rake_spec.rb | 2 | ||||
-rw-r--r-- | spec/tasks/gitlab/cleanup_rake_spec.rb | 67 | ||||
-rw-r--r-- | spec/tasks/gitlab/gitaly_rake_spec.rb | 17 |
3 files changed, 78 insertions, 8 deletions
diff --git a/spec/tasks/gitlab/backup_rake_spec.rb b/spec/tasks/gitlab/backup_rake_spec.rb index bf2e11bc360..b41c3b3958a 100644 --- a/spec/tasks/gitlab/backup_rake_spec.rb +++ b/spec/tasks/gitlab/backup_rake_spec.rb @@ -212,7 +212,7 @@ describe 'gitlab:app namespace rake task' do # Avoid asking gitaly about the root ref (which will fail beacuse of the # mocked storages) - allow_any_instance_of(Repository).to receive(:empty_repo?).and_return(false) + allow_any_instance_of(Repository).to receive(:empty?).and_return(false) end after do diff --git a/spec/tasks/gitlab/cleanup_rake_spec.rb b/spec/tasks/gitlab/cleanup_rake_spec.rb new file mode 100644 index 00000000000..9e746ceddd6 --- /dev/null +++ b/spec/tasks/gitlab/cleanup_rake_spec.rb @@ -0,0 +1,67 @@ +require 'rake_helper' + +describe 'gitlab:cleanup rake tasks' do + before do + Rake.application.rake_require 'tasks/gitlab/cleanup' + end + + describe 'cleanup' do + let(:gitaly_address) { Gitlab.config.repositories.storages.default.gitaly_address } + let(:storages) do + { + 'default' => { 'path' => Settings.absolute('tmp/tests/default_storage'), 'gitaly_address' => gitaly_address } + } + end + + before do + FileUtils.mkdir(Settings.absolute('tmp/tests/default_storage')) + allow(Gitlab.config.repositories).to receive(:storages).and_return(storages) + end + + after do + FileUtils.rm_rf(Settings.absolute('tmp/tests/default_storage')) + end + + describe 'cleanup:repos' do + before do + FileUtils.mkdir_p(Settings.absolute('tmp/tests/default_storage/broken/project.git')) + FileUtils.mkdir_p(Settings.absolute('tmp/tests/default_storage/@hashed/12/34/5678.git')) + end + + it 'moves it to an orphaned path' do + run_rake_task('gitlab:cleanup:repos') + repo_list = Dir['tmp/tests/default_storage/broken/*'] + + expect(repo_list.first).to include('+orphaned+') + end + + it 'ignores @hashed repos' do + run_rake_task('gitlab:cleanup:repos') + + expect(Dir.exist?(Settings.absolute('tmp/tests/default_storage/@hashed/12/34/5678.git'))).to be_truthy + end + end + + describe 'cleanup:dirs' do + it 'removes missing namespaces' do + FileUtils.mkdir_p(Settings.absolute("tmp/tests/default_storage/namespace_1/project.git")) + FileUtils.mkdir_p(Settings.absolute("tmp/tests/default_storage/namespace_2/project.git")) + allow(Namespace).to receive(:pluck).and_return('namespace_1') + + stub_env('REMOVE', 'true') + run_rake_task('gitlab:cleanup:dirs') + + expect(Dir.exist?(Settings.absolute('tmp/tests/default_storage/namespace_1'))).to be_truthy + expect(Dir.exist?(Settings.absolute('tmp/tests/default_storage/namespace_2'))).to be_falsey + end + + it 'ignores @hashed directory' do + FileUtils.mkdir_p(Settings.absolute('tmp/tests/default_storage/@hashed/12/34/5678.git')) + + run_rake_task('gitlab:cleanup:dirs') + + expect(Dir.exist?(Settings.absolute('tmp/tests/default_storage/@hashed/12/34/5678.git'))).to be_truthy + end + end + end +end diff --git a/spec/tasks/gitlab/gitaly_rake_spec.rb b/spec/tasks/gitlab/gitaly_rake_spec.rb index 5dd8fe8eaa5..6aba86fdc3c 100644 --- a/spec/tasks/gitlab/gitaly_rake_spec.rb +++ b/spec/tasks/gitlab/gitaly_rake_spec.rb @@ -47,7 +47,7 @@ describe 'gitlab:gitaly namespace rake task' do stub_env('CI', false) FileUtils.mkdir_p(clone_path) expect(Dir).to receive(:chdir).with(clone_path).and_call_original - allow(Bundler).to receive(:bundle_path).and_return('/fake/bundle_path') + allow(Rails.env).to receive(:test?).and_return(false) end context 'gmake is available' do @@ -57,7 +57,7 @@ describe 'gitlab:gitaly namespace rake task' do it 'calls gmake in the gitaly directory' do expect(Gitlab::Popen).to receive(:popen).with(%w[which gmake]).and_return(['/usr/bin/gmake', 0]) - expect(main_object).to receive(:run_command!).with(command_preamble + %w[gmake BUNDLE_PATH=/fake/bundle_path]).and_return(true) + expect(main_object).to receive(:run_command!).with(command_preamble + %w[gmake]).and_return(true) run_rake_task('gitlab:gitaly:install', clone_path) end @@ -70,18 +70,20 @@ describe 'gitlab:gitaly namespace rake task' do end it 'calls make in the gitaly directory' do - expect(main_object).to receive(:run_command!).with(command_preamble + %w[make BUNDLE_PATH=/fake/bundle_path]).and_return(true) + expect(main_object).to receive(:run_command!).with(command_preamble + %w[make]).and_return(true) run_rake_task('gitlab:gitaly:install', clone_path) end - context 'when Rails.env is not "test"' do + context 'when Rails.env is test' do + let(:command) { %w[make BUNDLE_FLAGS=--no-deployment] } + before do - allow(Rails.env).to receive(:test?).and_return(false) + allow(Rails.env).to receive(:test?).and_return(true) end - it 'calls make in the gitaly directory without BUNDLE_PATH' do - expect(main_object).to receive(:run_command!).with(command_preamble + ['make']).and_return(true) + it 'calls make in the gitaly directory with --no-deployment flag for bundle' do + expect(main_object).to receive(:run_command!).with(command_preamble + command).and_return(true) run_rake_task('gitlab:gitaly:install', clone_path) end @@ -110,6 +112,7 @@ describe 'gitlab:gitaly namespace rake task' do expected_output = <<~TOML # Gitaly storage configuration generated from #{Gitlab.config.source} on #{Time.current.to_s(:long)} # This is in TOML format suitable for use in Gitaly's config.toml file. + bin_dir = "tmp/tests/gitaly" socket_path = "/path/to/my.socket" [gitlab-shell] dir = "#{Gitlab.config.gitlab_shell.path}" |