diff options
author | Tiago Botelho <tiagonbotelho@hotmail.com> | 2018-11-27 09:41:27 +0000 |
---|---|---|
committer | Tiago Botelho <tiagonbotelho@hotmail.com> | 2018-11-27 12:58:13 +0000 |
commit | 4bd8a427d4e8127f1badc7365b35702472918956 (patch) | |
tree | d8e64bd046f35b64ad6f88bdd062e1e8f364c327 /spec/workers | |
parent | d3f033d69cec33e8058ee9f029718882990175b0 (diff) | |
download | gitlab-ce-4bd8a427d4e8127f1badc7365b35702472918956.tar.gz |
Removes all the irrelevant import related code and columns
Clears the import related columns and code from the Project
model over to the ProjectImportState model
Diffstat (limited to 'spec/workers')
7 files changed, 60 insertions, 49 deletions
diff --git a/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb b/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb index 241e8a2b6d3..d85a87f2cb0 100644 --- a/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb +++ b/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb @@ -58,14 +58,16 @@ describe Gitlab::GithubImport::StageMethods do end describe '#find_project' do + let(:import_state) { create(:import_state, project: project) } + it 'returns a Project for an existing ID' do - project.update_column(:import_status, 'started') + import_state.update_column(:status, 'started') expect(worker.find_project(project.id)).to eq(project) end it 'returns nil for a project that failed importing' do - project.update_column(:import_status, 'failed') + import_state.update_column(:status, 'failed') expect(worker.find_project(project.id)).to be_nil end diff --git a/spec/workers/concerns/project_import_options_spec.rb b/spec/workers/concerns/project_import_options_spec.rb index b6c111df8b9..3699fd83a9a 100644 --- a/spec/workers/concerns/project_import_options_spec.rb +++ b/spec/workers/concerns/project_import_options_spec.rb @@ -28,13 +28,23 @@ describe ProjectImportOptions do worker_class.sidekiq_retries_exhausted_block.call(job) - expect(project.reload.import_error).to include("fork") + expect(project.import_state.reload.last_error).to include("fork") end it 'logs the appropriate error message for forked projects' do worker_class.sidekiq_retries_exhausted_block.call(job) - expect(project.reload.import_error).to include("import") + expect(project.import_state.reload.last_error).to include("import") + end + + context 'when project does not have import_state' do + let(:project) { create(:project) } + + it 'raises an error' do + expect do + worker_class.sidekiq_retries_exhausted_block.call(job) + end.to raise_error(NoMethodError) + end end end end diff --git a/spec/workers/gitlab/github_import/advance_stage_worker_spec.rb b/spec/workers/gitlab/github_import/advance_stage_worker_spec.rb index 0f78c5cc644..fc7aafbc0c9 100644 --- a/spec/workers/gitlab/github_import/advance_stage_worker_spec.rb +++ b/spec/workers/gitlab/github_import/advance_stage_worker_spec.rb @@ -17,8 +17,8 @@ describe Gitlab::GithubImport::AdvanceStageWorker, :clean_gitlab_redis_shared_st context 'when there are remaining jobs' do before do allow(worker) - .to receive(:find_project) - .and_return(project) + .to receive(:find_import_state) + .and_return(import_state) end it 'reschedules itself' do @@ -38,8 +38,8 @@ describe Gitlab::GithubImport::AdvanceStageWorker, :clean_gitlab_redis_shared_st context 'when there are no remaining jobs' do before do allow(worker) - .to receive(:find_project) - .and_return(project) + .to receive(:find_import_state) + .and_return(import_state) allow(worker) .to receive(:wait_for_jobs) @@ -48,8 +48,8 @@ describe Gitlab::GithubImport::AdvanceStageWorker, :clean_gitlab_redis_shared_st end it 'schedules the next stage' do - expect(project) - .to receive(:refresh_import_jid_expiration) + expect(import_state) + .to receive(:refresh_jid_expiration) expect(Gitlab::GithubImport::Stage::FinishImportWorker) .to receive(:perform_async) @@ -96,22 +96,18 @@ describe Gitlab::GithubImport::AdvanceStageWorker, :clean_gitlab_redis_shared_st end end - describe '#find_project' do - it 'returns a Project' do - project.update_column(:import_status, 'started') + describe '#find_import_state' do + it 'returns a ProjectImportState' do + import_state.update_column(:status, 'started') - found = worker.find_project(project.id) + found = worker.find_import_state(project.id) - expect(found).to be_an_instance_of(Project) - - # This test is there to make sure we only select the columns we care - # about. - # TODO: enable this assertion back again - # expect(found.attributes).to include({ 'id' => nil, 'import_jid' => '123' }) + expect(found).to be_an_instance_of(ProjectImportState) + expect(found.attributes.keys).to match_array(%w(id jid)) end it 'returns nil if the project import is not running' do - expect(worker.find_project(project.id)).to be_nil + expect(worker.find_import_state(project.id)).to be_nil end end end diff --git a/spec/workers/gitlab/github_import/refresh_import_jid_worker_spec.rb b/spec/workers/gitlab/github_import/refresh_import_jid_worker_spec.rb index 25ada575a44..7ff133f1049 100644 --- a/spec/workers/gitlab/github_import/refresh_import_jid_worker_spec.rb +++ b/spec/workers/gitlab/github_import/refresh_import_jid_worker_spec.rb @@ -29,7 +29,7 @@ describe Gitlab::GithubImport::RefreshImportJidWorker do context 'when the job is running' do it 'refreshes the import JID and reschedules itself' do allow(worker) - .to receive(:find_project) + .to receive(:find_import_state) .with(project.id) .and_return(project) @@ -39,7 +39,7 @@ describe Gitlab::GithubImport::RefreshImportJidWorker do .and_return(true) expect(project) - .to receive(:refresh_import_jid_expiration) + .to receive(:refresh_jid_expiration) expect(worker.class) .to receive(:perform_in_the_future) @@ -52,7 +52,7 @@ describe Gitlab::GithubImport::RefreshImportJidWorker do context 'when the job is no longer running' do it 'returns' do allow(worker) - .to receive(:find_project) + .to receive(:find_import_state) .with(project.id) .and_return(project) @@ -62,18 +62,18 @@ describe Gitlab::GithubImport::RefreshImportJidWorker do .and_return(false) expect(project) - .not_to receive(:refresh_import_jid_expiration) + .not_to receive(:refresh_jid_expiration) worker.perform(project.id, '123') end end end - describe '#find_project' do - it 'returns a Project' do + describe '#find_import_state' do + it 'returns a ProjectImportState' do project = create(:project, :import_started) - expect(worker.find_project(project.id)).to be_an_instance_of(Project) + expect(worker.find_import_state(project.id)).to be_an_instance_of(ProjectImportState) end # it 'only selects the import JID field' do @@ -84,14 +84,14 @@ describe Gitlab::GithubImport::RefreshImportJidWorker do # .to eq({ 'id' => nil, 'import_jid' => '123abc' }) # end - it 'returns nil for a project for which the import process failed' do + it 'returns nil for a import state for which the import process failed' do project = create(:project, :import_failed) - expect(worker.find_project(project.id)).to be_nil + expect(worker.find_import_state(project.id)).to be_nil end - it 'returns nil for a non-existing project' do - expect(worker.find_project(-1)).to be_nil + it 'returns nil for a non-existing find_import_state' do + expect(worker.find_import_state(-1)).to be_nil end end end diff --git a/spec/workers/gitlab/github_import/stage/import_base_data_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_base_data_worker_spec.rb index 8c80d660287..ad6154cc4a4 100644 --- a/spec/workers/gitlab/github_import/stage/import_base_data_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_base_data_worker_spec.rb @@ -2,6 +2,7 @@ require 'spec_helper' describe Gitlab::GithubImport::Stage::ImportBaseDataWorker do let(:project) { create(:project) } + let(:import_state) { create(:import_state, project: project) } let(:worker) { described_class.new } describe '#import' do @@ -18,7 +19,7 @@ describe Gitlab::GithubImport::Stage::ImportBaseDataWorker do expect(importer).to receive(:execute) end - expect(project).to receive(:refresh_import_jid_expiration) + expect(import_state).to receive(:refresh_jid_expiration) expect(Gitlab::GithubImport::Stage::ImportPullRequestsWorker) .to receive(:perform_async) diff --git a/spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb index 2fc91a3e80a..1fbb073a34a 100644 --- a/spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb @@ -2,6 +2,7 @@ require 'spec_helper' describe Gitlab::GithubImport::Stage::ImportPullRequestsWorker do let(:project) { create(:project) } + let(:import_state) { create(:import_state, project: project) } let(:worker) { described_class.new } describe '#import' do @@ -19,8 +20,8 @@ describe Gitlab::GithubImport::Stage::ImportPullRequestsWorker do .to receive(:execute) .and_return(waiter) - expect(project) - .to receive(:refresh_import_jid_expiration) + expect(import_state) + .to receive(:refresh_jid_expiration) expect(Gitlab::GithubImport::AdvanceStageWorker) .to receive(:perform_async) diff --git a/spec/workers/repository_import_worker_spec.rb b/spec/workers/repository_import_worker_spec.rb index d07e40377d4..87ac4bc05c1 100644 --- a/spec/workers/repository_import_worker_spec.rb +++ b/spec/workers/repository_import_worker_spec.rb @@ -9,13 +9,13 @@ describe RepositoryImportWorker do describe '#perform' do let(:project) { create(:project, :import_scheduled) } + let(:import_state) { project.import_state } context 'when worker was reset without cleanup' do it 'imports the project successfully' do jid = '12345678' started_project = create(:project) - - create(:import_state, :started, project: started_project, jid: jid) + started_import_state = create(:import_state, :started, project: started_project, jid: jid) allow(subject).to receive(:jid).and_return(jid) @@ -23,12 +23,12 @@ describe RepositoryImportWorker do .and_return({ status: :ok }) # Works around https://github.com/rspec/rspec-mocks/issues/910 - expect(Project).to receive(:find).with(project.id).and_return(project) - expect(project.repository).to receive(:expire_emptiness_caches) - expect(project.wiki.repository).to receive(:expire_emptiness_caches) - expect(project).to receive(:import_finish) + expect(Project).to receive(:find).with(started_project.id).and_return(started_project) + expect(started_project.repository).to receive(:expire_emptiness_caches) + expect(started_project.wiki.repository).to receive(:expire_emptiness_caches) + expect(started_import_state).to receive(:finish) - subject.perform(project.id) + subject.perform(started_project.id) end end @@ -41,7 +41,7 @@ describe RepositoryImportWorker do expect(Project).to receive(:find).with(project.id).and_return(project) expect(project.repository).to receive(:expire_emptiness_caches) expect(project.wiki.repository).to receive(:expire_emptiness_caches) - expect(project).to receive(:import_finish) + expect(import_state).to receive(:finish) subject.perform(project.id) end @@ -51,26 +51,27 @@ describe RepositoryImportWorker do it 'hide the credentials that were used in the import URL' do error = %q{remote: Not Found fatal: repository 'https://user:pass@test.com/root/repoC.git/' not found } - project.update(import_jid: '123') + import_state.update(jid: '123') expect_any_instance_of(Projects::ImportService).to receive(:execute).and_return({ status: :error, message: error }) expect do subject.perform(project.id) end.to raise_error(RuntimeError, error) - expect(project.reload.import_jid).not_to be_nil + expect(import_state.reload.jid).not_to be_nil end it 'updates the error on Import/Export' do error = %q{remote: Not Found fatal: repository 'https://user:pass@test.com/root/repoC.git/' not found } - project.update(import_jid: '123', import_type: 'gitlab_project') + project.update(import_type: 'gitlab_project') + import_state.update(jid: '123') expect_any_instance_of(Projects::ImportService).to receive(:execute).and_return({ status: :error, message: error }) expect do subject.perform(project.id) end.to raise_error(RuntimeError, error) - expect(project.reload.import_error).not_to be_nil + expect(import_state.reload.last_error).not_to be_nil end end @@ -90,8 +91,8 @@ describe RepositoryImportWorker do .to receive(:async?) .and_return(true) - expect_any_instance_of(Project) - .not_to receive(:import_finish) + expect_any_instance_of(ProjectImportState) + .not_to receive(:finish) subject.perform(project.id) end |