diff options
Diffstat (limited to 'spec/lib/gitlab/data_builder')
-rw-r--r-- | spec/lib/gitlab/data_builder/build_spec.rb | 98 | ||||
-rw-r--r-- | spec/lib/gitlab/data_builder/pipeline_spec.rb | 1 |
2 files changed, 65 insertions, 34 deletions
diff --git a/spec/lib/gitlab/data_builder/build_spec.rb b/spec/lib/gitlab/data_builder/build_spec.rb index 2c239d5868a..544b210651b 100644 --- a/spec/lib/gitlab/data_builder/build_spec.rb +++ b/spec/lib/gitlab/data_builder/build_spec.rb @@ -3,10 +3,9 @@ require 'spec_helper' RSpec.describe Gitlab::DataBuilder::Build do - let!(:tag_names) { %w(tag-1 tag-2) } - let(:runner) { create(:ci_runner, :instance, tag_list: tag_names.map { |n| ActsAsTaggableOn::Tag.create!(name: n) }) } - let(:user) { create(:user, :public_email) } - let(:build) { create(:ci_build, :running, runner: runner, user: user) } + let_it_be(:runner) { create(:ci_runner, :instance, :tagged_only) } + let_it_be(:user) { create(:user, :public_email) } + let_it_be(:ci_build) { create(:ci_build, :running, runner: runner, user: user) } describe '.build' do around do |example| @@ -14,25 +13,26 @@ RSpec.describe Gitlab::DataBuilder::Build do end let(:data) do - described_class.build(build) + described_class.build(ci_build) end it { expect(data).to be_a(Hash) } - it { expect(data[:ref]).to eq(build.ref) } - it { expect(data[:sha]).to eq(build.sha) } - it { expect(data[:tag]).to eq(build.tag) } - it { expect(data[:build_id]).to eq(build.id) } - it { expect(data[:build_status]).to eq(build.status) } - it { expect(data[:build_created_at]).to eq(build.created_at) } - it { expect(data[:build_started_at]).to eq(build.started_at) } - it { expect(data[:build_finished_at]).to eq(build.finished_at) } - it { expect(data[:build_duration]).to eq(build.duration) } - it { expect(data[:build_queued_duration]).to eq(build.queued_duration) } + it { expect(data[:ref]).to eq(ci_build.ref) } + it { expect(data[:sha]).to eq(ci_build.sha) } + it { expect(data[:tag]).to eq(ci_build.tag) } + it { expect(data[:build_id]).to eq(ci_build.id) } + it { expect(data[:build_status]).to eq(ci_build.status) } + it { expect(data[:build_created_at]).to eq(ci_build.created_at) } + it { expect(data[:build_started_at]).to eq(ci_build.started_at) } + it { expect(data[:build_finished_at]).to eq(ci_build.finished_at) } + it { expect(data[:build_duration]).to eq(ci_build.duration) } + it { expect(data[:build_queued_duration]).to eq(ci_build.queued_duration) } it { expect(data[:build_allow_failure]).to eq(false) } - it { expect(data[:build_failure_reason]).to eq(build.failure_reason) } - it { expect(data[:project_id]).to eq(build.project.id) } - it { expect(data[:project_name]).to eq(build.project.full_name) } - it { expect(data[:pipeline_id]).to eq(build.pipeline.id) } + it { expect(data[:build_failure_reason]).to eq(ci_build.failure_reason) } + it { expect(data[:project_id]).to eq(ci_build.project.id) } + it { expect(data[:project_name]).to eq(ci_build.project.full_name) } + it { expect(data[:pipeline_id]).to eq(ci_build.pipeline.id) } + it { expect(data[:retries_count]).to eq(ci_build.retries_count) } it { expect(data[:user]).to eq( @@ -45,44 +45,74 @@ RSpec.describe Gitlab::DataBuilder::Build do }) } - it { expect(data[:commit][:id]).to eq(build.pipeline.id) } - it { expect(data[:runner][:id]).to eq(build.runner.id) } - it { expect(data[:runner][:tags]).to match_array(tag_names) } - it { expect(data[:runner][:description]).to eq(build.runner.description) } - it { expect(data[:runner][:runner_type]).to eq(build.runner.runner_type) } - it { expect(data[:runner][:is_shared]).to eq(build.runner.instance_type?) } + it { expect(data[:commit][:id]).to eq(ci_build.pipeline.id) } + it { expect(data[:runner][:id]).to eq(ci_build.runner.id) } + it { expect(data[:runner][:tags]).to match_array(%w(tag1 tag2)) } + it { expect(data[:runner][:description]).to eq(ci_build.runner.description) } + it { expect(data[:runner][:runner_type]).to eq(ci_build.runner.runner_type) } + it { expect(data[:runner][:is_shared]).to eq(ci_build.runner.instance_type?) } it { expect(data[:environment]).to be_nil } + it 'does not exceed number of expected queries' do + ci_build # Make sure the Ci::Build model is created before recording. + + control = ActiveRecord::QueryRecorder.new(skip_cached: false) do + b = Ci::Build.find(ci_build.id) + described_class.build(b) # Don't use ci_build variable here since it has all associations loaded into memory + end + + expect(control.count).to eq(13) + end + + context 'when feature flag is disabled' do + before do + stub_feature_flags(job_webhook_retries_count: false) + end + + it { expect(data).not_to have_key(:retries_count) } + + it 'does not exceed number of expected queries' do + ci_build # Make sure the Ci::Build model is created before recording. + + control = ActiveRecord::QueryRecorder.new(skip_cached: false) do + b = Ci::Build.find(ci_build.id) + described_class.build(b) # Don't use ci_build variable here since it has all associations loaded into memory + end + + expect(control.count).to eq(12) + end + end + context 'commit author_url' do context 'when no commit present' do - let(:build) { create(:ci_build) } + let(:build) { build(:ci_build) } it 'sets to mailing address of git_author_email' do - expect(data[:commit][:author_url]).to eq("mailto:#{build.pipeline.git_author_email}") + expect(data[:commit][:author_url]).to eq("mailto:#{ci_build.pipeline.git_author_email}") end end context 'when commit present but has no author' do - let(:build) { create(:ci_build, :with_commit) } + let(:ci_build) { build(:ci_build, :with_commit) } it 'sets to mailing address of git_author_email' do - expect(data[:commit][:author_url]).to eq("mailto:#{build.pipeline.git_author_email}") + expect(data[:commit][:author_url]).to eq("mailto:#{ci_build.pipeline.git_author_email}") end end context 'when commit and author are present' do - let(:build) { create(:ci_build, :with_commit_and_author) } + let(:ci_build) { build(:ci_build, :with_commit_and_author) } it 'sets to GitLab user url' do - expect(data[:commit][:author_url]).to eq(Gitlab::Routing.url_helpers.user_url(username: build.commit.author.username)) + expect(data[:commit][:author_url]).to eq(Gitlab::Routing.url_helpers.user_url(username: ci_build.commit.author.username)) end end context 'with environment' do - let(:build) { create(:ci_build, :teardown_environment) } + let(:ci_build) { build(:ci_build, :teardown_environment) } - it { expect(data[:environment][:name]).to eq(build.expanded_environment_name) } - it { expect(data[:environment][:action]).to eq(build.environment_action) } + it { expect(data[:environment][:name]).to eq(ci_build.expanded_environment_name) } + it { expect(data[:environment][:action]).to eq(ci_build.environment_action) } end end end diff --git a/spec/lib/gitlab/data_builder/pipeline_spec.rb b/spec/lib/gitlab/data_builder/pipeline_spec.rb index 46a12d8c6f6..eb348f5b497 100644 --- a/spec/lib/gitlab/data_builder/pipeline_spec.rb +++ b/spec/lib/gitlab/data_builder/pipeline_spec.rb @@ -103,6 +103,7 @@ RSpec.describe Gitlab::DataBuilder::Pipeline do expect(merge_request_attrs[:target_project_id]).to eq(merge_request.target_project_id) expect(merge_request_attrs[:state]).to eq(merge_request.state) expect(merge_request_attrs[:merge_status]).to eq(merge_request.public_merge_status) + expect(merge_request_attrs[:detailed_merge_status]).to eq("mergeable") expect(merge_request_attrs[:url]).to eq("http://localhost/#{merge_request.target_project.full_path}/-/merge_requests/#{merge_request.iid}") end end |