Commit 03ff7179 authored by Peter Leitzen's avatar Peter Leitzen

Speed up CI retry build service specs

parent 3934a31b
......@@ -3,25 +3,32 @@
require 'spec_helper'
RSpec.describe Ci::RetryBuildService do
let_it_be(:user) { create(:user) }
let_it_be(:reporter) { create(:user) }
let_it_be(:developer) { create(:user) }
let_it_be(:project) { create(:project, :repository) }
let_it_be(:pipeline) do
create(:ci_pipeline, project: project,
sha: 'b83d6e391c22777fca1ed3012fce84f633d7fed0')
end
let(:stage) do
let_it_be(:stage) do
create(:ci_stage_entity, project: project,
pipeline: pipeline,
name: 'test')
end
let(:build) { create(:ci_build, pipeline: pipeline, stage_id: stage.id) }
let_it_be_with_refind(:build) { create(:ci_build, pipeline: pipeline, stage_id: stage.id) }
let(:user) { developer }
let(:service) do
described_class.new(project, user)
end
before_all do
project.add_developer(developer)
project.add_reporter(reporter)
end
clone_accessors = described_class.clone_accessors
reject_accessors =
......@@ -53,9 +60,9 @@ RSpec.describe Ci::RetryBuildService do
pipeline_id report_results pending_state pages_deployments].freeze
shared_examples 'build duplication' do
let(:another_pipeline) { create(:ci_empty_pipeline, project: project) }
let_it_be(:another_pipeline) { create(:ci_empty_pipeline, project: project) }
let(:build) do
let_it_be(:build) do
create(:ci_build, :failed, :expired, :erased, :queued, :coverage, :tags,
:allowed_to_fail, :on_tag, :triggered, :teardown_environment, :resource_group,
description: 'my-job', stage: 'test', stage_id: stage.id,
......@@ -63,7 +70,7 @@ RSpec.describe Ci::RetryBuildService do
scheduled_at: 10.seconds.since)
end
before do
before_all do
# Test correctly behaviour of deprecated artifact because it can be still in use
stub_feature_flags(drop_license_management_artifact: false)
......@@ -81,8 +88,6 @@ RSpec.describe Ci::RetryBuildService do
create(:ci_job_variable, job: build)
create(:ci_build_need, build: build)
build.reload
end
describe 'clone accessors' do
......@@ -162,8 +167,6 @@ RSpec.describe Ci::RetryBuildService do
context 'when user has ability to execute build' do
before do
stub_not_protect_default_branch
project.add_developer(user)
end
it_behaves_like 'build duplication'
......@@ -235,7 +238,6 @@ RSpec.describe Ci::RetryBuildService do
context 'when the pipeline is a child pipeline and the bridge is depended' do
let!(:parent_pipeline) { create(:ci_pipeline, project: project) }
let!(:pipeline) { create(:ci_pipeline, project: project) }
let!(:bridge) { create(:ci_bridge, :strategy_depend, pipeline: parent_pipeline, status: 'success') }
let!(:source_pipeline) { create(:ci_sources_pipeline, pipeline: pipeline, source_job: bridge) }
......@@ -248,6 +250,8 @@ RSpec.describe Ci::RetryBuildService do
end
context 'when user does not have ability to execute build' do
let(:user) { reporter }
it 'raises an error' do
expect { service.execute(build) }
.to raise_error Gitlab::Access::AccessDeniedError
......@@ -265,8 +269,6 @@ RSpec.describe Ci::RetryBuildService do
context 'when user has ability to execute build' do
before do
stub_not_protect_default_branch
project.add_developer(user)
end
it_behaves_like 'build duplication'
......@@ -316,6 +318,8 @@ RSpec.describe Ci::RetryBuildService do
end
context 'when user does not have ability to execute build' do
let(:user) { reporter }
it 'raises an error' do
expect { service.reprocess!(build) }
.to raise_error Gitlab::Access::AccessDeniedError
......
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