diff options
author | Toon Claes <toon@gitlab.com> | 2018-05-07 15:21:44 +0300 |
---|---|---|
committer | Toon Claes <toon@gitlab.com> | 2018-05-07 15:24:07 +0300 |
commit | 049080263684f2763b0abdbe310bb742253eca53 (patch) | |
tree | 96cebd04a0b00291e887cf8ae6ee10fe8016a2f0 /spec/workers/repository_check | |
parent | ca29aa114b200da81b2805dbe45fdc18a13400f9 (diff) |
Use push events again to determine if repo needs checking
Diffstat (limited to 'spec/workers/repository_check')
-rw-r--r-- | spec/workers/repository_check/single_repository_worker_spec.rb | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/spec/workers/repository_check/single_repository_worker_spec.rb b/spec/workers/repository_check/single_repository_worker_spec.rb index 1c9663bbab5..58227abc2b5 100644 --- a/spec/workers/repository_check/single_repository_worker_spec.rb +++ b/spec/workers/repository_check/single_repository_worker_spec.rb @@ -4,8 +4,10 @@ require 'fileutils' describe RepositoryCheck::SingleRepositoryWorker do subject(:worker) { described_class.new } - it 'skips when the project repo is empty' do - project = create(:project, :wiki_disabled) + it 'skips when the project has no push events' do + project = create(:project, :repository, :wiki_disabled) + project.events.destroy_all + break_project(project) expect(worker).not_to receive(:git_fsck) @@ -14,8 +16,19 @@ describe RepositoryCheck::SingleRepositoryWorker do 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, :repository) + create_push_event(project) + break_project(project) + + worker.perform(project.id) + + expect(project.reload.last_repository_check_failed).to eq(true) + end + it 'succeeds when the project repo is valid' do project = create(:project, :repository, :wiki_disabled) + create_push_event(project) expect(worker).to receive(:git_fsck).and_call_original @@ -26,18 +39,10 @@ describe RepositoryCheck::SingleRepositoryWorker do expect(project.reload.last_repository_check_failed).to eq(false) end - it 'fails when the project is not empty and a broken repository' do - project = create(:project, :repository) - break_project(project) - - worker.perform(project.id) - - expect(project.reload.last_repository_check_failed).to eq(true) - end - it 'fails if the wiki repository is broken' do - project = create(:project, :wiki_enabled) + project = create(:project, :repository, :wiki_enabled) project.create_wiki + create_push_event(project) # Test sanity: everything should be fine before the wiki repo is broken worker.perform(project.id) @@ -78,6 +83,10 @@ describe RepositoryCheck::SingleRepositoryWorker do expect(Gitlab::Shell.new.exists?(project.repository_storage, project.wiki.path)).to eq(false) end + def create_push_event(project) + project.events.create(action: Event::PUSHED, author_id: create(:user).id) + end + def break_wiki(project) break_repo(wiki_path(project)) end @@ -90,6 +99,7 @@ describe RepositoryCheck::SingleRepositoryWorker do break_repo(project.repository.path_to_repo) end + def break_repo(repo) # Create or replace blob ffffffffffffffffffffffffffffffffffffffff with an empty file # This will make the repo invalid, _and_ 'git init' cannot fix it. |