debian-mirror-gitlab/spec/tasks/gitlab/update_templates_rake_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
1.4 KiB
Ruby
Raw Permalink Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
require 'rake_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe 'gitlab:update_project_templates rake task', :silence_stdout, feature_category: :importers do
2019-10-12 21:52:04 +05:30
let!(:tmpdir) { Dir.mktmpdir }
2023-01-13 00:05:48 +05:30
let(:template) { Gitlab::ProjectTemplate.find(:rails) }
2019-10-12 21:52:04 +05:30
before do
Rake.application.rake_require 'tasks/gitlab/update_templates'
2023-03-04 22:38:38 +05:30
admin = create(:admin)
create(:key, user: admin)
2019-10-12 21:52:04 +05:30
allow(Gitlab::ProjectTemplate)
.to receive(:archive_directory)
.and_return(Pathname.new(tmpdir))
# Gitlab::HTTP resolves the domain to an IP prior to WebMock taking effect, hence the wildcard
2023-01-13 00:05:48 +05:30
stub_request(:get, %r{^https://.*/api/v4/projects/#{template.uri_encoded_project_path}/repository/commits\?page=1&per_page=1})
2019-10-12 21:52:04 +05:30
.to_return(
status: 200,
body: [{ id: '67812735b83cb42710f22dc98d73d42c8bf4d907' }].to_json,
headers: { 'Content-Type' => 'application/json' }
)
end
after do
FileUtils.rm_rf(tmpdir)
end
it 'updates valid project templates' do
2023-03-04 22:38:38 +05:30
expect(Gitlab::TaskHelpers).to receive(:run_command!).with(anything).exactly(6).times.and_call_original
expect(Gitlab::TaskHelpers).to receive(:run_command!).with(%w[git push -u origin master])
2023-01-13 00:05:48 +05:30
expect { run_rake_task('gitlab:update_project_templates', [template.name]) }
2019-10-12 21:52:04 +05:30
.to change { Dir.entries(tmpdir) }
2023-01-13 00:05:48 +05:30
.by(["#{template.name}.tar.gz"])
2019-10-12 21:52:04 +05:30
end
end