2019-10-15 05:06:09 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-29 13:21:25 -05:00
|
|
|
require 'rake_helper'
|
2016-09-28 06:45:46 -04:00
|
|
|
|
2020-06-24 11:08:50 -04:00
|
|
|
RSpec.describe 'gitlab:workhorse namespace rake task' do
|
2016-09-28 06:45:46 -04:00
|
|
|
before :all do
|
|
|
|
Rake.application.rake_require 'tasks/gitlab/workhorse'
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'install' do
|
|
|
|
let(:repo) { 'https://gitlab.com/gitlab-org/gitlab-workhorse.git' }
|
2020-12-11 10:10:04 -05:00
|
|
|
let(:clone_path) { Dir.mktmpdir('gitlab:workhorse:install-rake-test') }
|
2020-12-09 04:09:47 -05:00
|
|
|
let(:workhorse_source) { Rails.root.join('workhorse').to_s }
|
2016-09-28 06:45:46 -04:00
|
|
|
|
2020-12-11 10:10:04 -05:00
|
|
|
after do
|
|
|
|
FileUtils.rm_rf(clone_path)
|
|
|
|
end
|
|
|
|
|
2016-09-28 06:45:46 -04:00
|
|
|
context 'no dir given' do
|
|
|
|
it 'aborts and display a help message' do
|
2016-11-29 13:21:25 -05:00
|
|
|
# avoid writing task output to spec progress
|
|
|
|
allow($stderr).to receive :write
|
2016-09-28 06:45:46 -04:00
|
|
|
expect { run_rake_task('gitlab:workhorse:install') }.to raise_error /Please specify the directory where you want to install gitlab-workhorse/
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-12-11 10:10:04 -05:00
|
|
|
context 'when an underlying Git command fails' do
|
2016-09-28 06:45:46 -04:00
|
|
|
it 'aborts and display a help message' do
|
2017-08-08 11:48:33 -04:00
|
|
|
expect(main_object)
|
2017-06-21 09:48:12 -04:00
|
|
|
.to receive(:checkout_or_clone_version).and_raise 'Git error'
|
2016-09-28 06:45:46 -04:00
|
|
|
|
|
|
|
expect { run_rake_task('gitlab:workhorse:install', clone_path) }.to raise_error 'Git error'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-12-11 10:10:04 -05:00
|
|
|
it 'clones the origin and creates a gitlab-workhorse binary' do
|
|
|
|
FileUtils.rm_rf(clone_path)
|
|
|
|
|
|
|
|
Dir.mktmpdir('fake-workhorse-origin') do |workhorse_origin|
|
|
|
|
[
|
|
|
|
%W[git init -q #{workhorse_origin}],
|
|
|
|
%W[git -C #{workhorse_origin} checkout -q -b workhorse-move-notice],
|
|
|
|
%W[touch #{workhorse_origin}/proof-that-repo-got-cloned],
|
|
|
|
%W[git -C #{workhorse_origin} add .],
|
|
|
|
%W[git -C #{workhorse_origin} commit -q -m init],
|
|
|
|
%W[git -C #{workhorse_origin} checkout -q -b master]
|
|
|
|
].each do |cmd|
|
|
|
|
raise "#{cmd.join(' ')} failed" unless system(*cmd)
|
2016-09-28 06:45:46 -04:00
|
|
|
end
|
|
|
|
|
2020-12-11 10:10:04 -05:00
|
|
|
run_rake_task('gitlab:workhorse:install', clone_path, File.join(workhorse_origin, '.git'))
|
2016-09-28 06:45:46 -04:00
|
|
|
end
|
|
|
|
|
2020-12-11 10:10:04 -05:00
|
|
|
expect(File.exist?(File.join(clone_path, 'proof-that-repo-got-cloned'))).to be true
|
|
|
|
expect(File.executable?(File.join(clone_path, 'gitlab-workhorse'))).to be true
|
2016-09-28 06:45:46 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|