Commit eac01d4f authored by Matija Čupić's avatar Matija Čupić

Reorganize background_migration specs

This also adds specs for 3 distinct situations:

2. When there is an unknown pipeline with just a build
3. When there is an unknown pipeline with no statuses
1. When there is an unknown pipeline with a build and a status
parent c0716421
...@@ -6,39 +6,57 @@ describe Gitlab::BackgroundMigration::PopulateExternalPipelineSource, :migration ...@@ -6,39 +6,57 @@ describe Gitlab::BackgroundMigration::PopulateExternalPipelineSource, :migration
let(:migration) { described_class.new } let(:migration) { described_class.new }
let!(:internal_pipeline) { create(:ci_pipeline, source: :web) } let!(:internal_pipeline) { create(:ci_pipeline, source: :web) }
let(:pipelines) { [internal_pipeline, external_pipeline, second_external_pipeline].map(&:id) } let(:pipelines) { [internal_pipeline, unknown_pipeline].map(&:id) }
let!(:external_pipeline) do let!(:unknown_pipeline) do
build(:ci_pipeline, source: :unknown) build(:ci_pipeline, source: :unknown)
.tap { |pipeline| pipeline.save(validate: false) } .tap { |pipeline| pipeline.save(validate: false) }
end end
let!(:second_external_pipeline) do
build(:ci_pipeline, source: :unknown) subject { migration.perform(pipelines.min, pipelines.max) }
.tap { |pipeline| pipeline.save(validate: false) }
shared_examples 'no changes' do
it 'does not change the pipeline source' do
expect { subject }.not_to change { unknown_pipeline.reload.source }
end
end end
context 'when unknown pipeline is external' do
before do before do
create(:generic_commit_status, pipeline: external_pipeline) create(:generic_commit_status, pipeline: unknown_pipeline)
create(:ci_build, pipeline: internal_pipeline)
end end
subject { migration.perform(pipelines.min, pipelines.max) }
it 'populates the pipeline source' do it 'populates the pipeline source' do
subject subject
expect(external_pipeline.reload.source).to eq('external') expect(unknown_pipeline.reload.source).to eq('external')
end end
it 'only processes a single batch of links at a time' do it 'can be repeated without effect' do
subject subject
expect(second_external_pipeline.reload.source).to eq('unknown') expect { subject }.not_to change { unknown_pipeline.reload.source }
end
end end
it 'can be repeated without effect' do context 'when unknown pipeline has just a build' do
subject before do
create(:ci_build, pipeline: unknown_pipeline)
end
it_behaves_like 'no changes'
end
context 'when unknown pipeline has no statuses' do
it_behaves_like 'no changes'
end
context 'when unknown pipeline has a build and a status' do
before do
create(:generic_commit_status, pipeline: unknown_pipeline)
create(:ci_build, pipeline: unknown_pipeline)
end
expect { subject }.not_to change { external_pipeline.reload.source } it_behaves_like 'no changes'
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment