2016-06-02 11:05:42 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
require 'fileutils'
|
|
|
|
|
|
|
|
describe RepositoryCheck::SingleRepositoryWorker do
|
|
|
|
subject { described_class.new }
|
|
|
|
|
2016-06-22 15:30:34 +05:30
|
|
|
it 'passes when the project has no push events' do
|
2017-08-17 22:00:37 +05:30
|
|
|
project = create(:project_empty_repo, :wiki_disabled)
|
2016-06-22 15:30:34 +05:30
|
|
|
project.events.destroy_all
|
|
|
|
break_repo(project)
|
|
|
|
|
|
|
|
subject.perform(project.id)
|
|
|
|
|
|
|
|
expect(project.reload.last_repository_check_failed).to eq(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'fails when the project has push events and a broken repository' do
|
|
|
|
project = create(:project_empty_repo)
|
|
|
|
create_push_event(project)
|
|
|
|
break_repo(project)
|
|
|
|
|
|
|
|
subject.perform(project.id)
|
|
|
|
|
|
|
|
expect(project.reload.last_repository_check_failed).to eq(true)
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
it 'fails if the wiki repository is broken' do
|
2017-08-17 22:00:37 +05:30
|
|
|
project = create(:project_empty_repo, :wiki_enabled)
|
2016-06-02 11:05:42 +05:30
|
|
|
project.create_wiki
|
|
|
|
|
|
|
|
# Test sanity: everything should be fine before the wiki repo is broken
|
|
|
|
subject.perform(project.id)
|
|
|
|
expect(project.reload.last_repository_check_failed).to eq(false)
|
|
|
|
|
|
|
|
break_wiki(project)
|
|
|
|
subject.perform(project.id)
|
|
|
|
|
|
|
|
expect(project.reload.last_repository_check_failed).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'skips wikis when disabled' do
|
2017-08-17 22:00:37 +05:30
|
|
|
project = create(:project_empty_repo, :wiki_disabled)
|
2016-06-02 11:05:42 +05:30
|
|
|
# Make sure the test would fail if the wiki repo was checked
|
|
|
|
break_wiki(project)
|
|
|
|
|
|
|
|
subject.perform(project.id)
|
|
|
|
|
|
|
|
expect(project.reload.last_repository_check_failed).to eq(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates missing wikis' do
|
2017-08-17 22:00:37 +05:30
|
|
|
project = create(:project_empty_repo, :wiki_enabled)
|
2016-06-02 11:05:42 +05:30
|
|
|
FileUtils.rm_rf(wiki_path(project))
|
|
|
|
|
|
|
|
subject.perform(project.id)
|
|
|
|
|
|
|
|
expect(project.reload.last_repository_check_failed).to eq(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not create a wiki if the main repo does not exist at all' do
|
|
|
|
project = create(:project_empty_repo)
|
2016-06-22 15:30:34 +05:30
|
|
|
create_push_event(project)
|
2016-06-02 11:05:42 +05:30
|
|
|
FileUtils.rm_rf(project.repository.path_to_repo)
|
|
|
|
FileUtils.rm_rf(wiki_path(project))
|
|
|
|
|
|
|
|
subject.perform(project.id)
|
|
|
|
|
|
|
|
expect(File.exist?(wiki_path(project))).to eq(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
def break_wiki(project)
|
2018-03-17 18:26:18 +05:30
|
|
|
objects_dir = wiki_path(project) + '/objects'
|
|
|
|
|
|
|
|
# Replace the /objects directory with a file so that the repo is
|
|
|
|
# invalid, _and_ 'git init' cannot fix it.
|
|
|
|
FileUtils.rm_rf(objects_dir)
|
|
|
|
FileUtils.touch(objects_dir) if File.directory?(wiki_path(project))
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def wiki_path(project)
|
|
|
|
project.wiki.repository.path_to_repo
|
|
|
|
end
|
2016-06-22 15:30:34 +05:30
|
|
|
|
|
|
|
def create_push_event(project)
|
|
|
|
project.events.create(action: Event::PUSHED, author_id: create(:user).id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def break_repo(project)
|
|
|
|
FileUtils.rm_rf(File.join(project.repository.path_to_repo, 'objects'))
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|