2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::DataBuilder::Pipeline do
|
2016-09-13 17:45:13 +05:30
|
|
|
let(:user) { create(:user) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:project) { create(:project, :repository) }
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
let(:pipeline) do
|
|
|
|
create(:ci_pipeline,
|
2018-12-05 23:21:45 +05:30
|
|
|
project: project,
|
|
|
|
status: 'success',
|
|
|
|
sha: project.commit.sha,
|
2020-03-13 15:44:24 +05:30
|
|
|
ref: project.default_branch,
|
|
|
|
user: user)
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
let!(:build) { create(:ci_build, pipeline: pipeline) }
|
|
|
|
|
|
|
|
describe '.build' do
|
|
|
|
let(:data) { described_class.build(pipeline) }
|
|
|
|
let(:attributes) { data[:object_attributes] }
|
|
|
|
let(:build_data) { data[:builds].first }
|
2021-02-22 17:27:13 +05:30
|
|
|
let(:runner_data) { build_data[:runner] }
|
2016-09-13 17:45:13 +05:30
|
|
|
let(:project_data) { data[:project] }
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
it 'has correct attributes', :aggregate_failures do
|
2018-12-05 23:21:45 +05:30
|
|
|
expect(attributes).to be_a(Hash)
|
|
|
|
expect(attributes[:ref]).to eq(pipeline.ref)
|
|
|
|
expect(attributes[:sha]).to eq(pipeline.sha)
|
|
|
|
expect(attributes[:tag]).to eq(pipeline.tag)
|
|
|
|
expect(attributes[:id]).to eq(pipeline.id)
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(attributes[:source]).to eq(pipeline.source)
|
2018-12-05 23:21:45 +05:30
|
|
|
expect(attributes[:status]).to eq(pipeline.status)
|
|
|
|
expect(attributes[:detailed_status]).to eq('passed')
|
|
|
|
expect(build_data).to be_a(Hash)
|
|
|
|
expect(build_data[:id]).to eq(build.id)
|
|
|
|
expect(build_data[:status]).to eq(build.status)
|
2020-01-01 13:55:28 +05:30
|
|
|
expect(build_data[:allow_failure]).to eq(build.allow_failure)
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(build_data[:environment]).to be_nil
|
2021-02-22 17:27:13 +05:30
|
|
|
expect(runner_data).to eq(nil)
|
2018-12-05 23:21:45 +05:30
|
|
|
expect(project_data).to eq(project.hook_attrs(backward: false))
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(data[:merge_request]).to be_nil
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(data[:user]).to eq({
|
2021-03-08 18:12:59 +05:30
|
|
|
id: user.id,
|
2020-03-13 15:44:24 +05:30
|
|
|
name: user.name,
|
|
|
|
username: user.username,
|
|
|
|
avatar_url: user.avatar_url(only_path: false),
|
|
|
|
email: user.email
|
|
|
|
})
|
2018-12-05 23:21:45 +05:30
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
context 'build with runner' do
|
|
|
|
let!(:build) { create(:ci_build, pipeline: pipeline, runner: ci_runner) }
|
2021-03-11 19:13:27 +05:30
|
|
|
let!(:tag_names) { %w(tag-1 tag-2) }
|
|
|
|
let(:ci_runner) { create(:ci_runner, tag_list: tag_names.map { |n| ActsAsTaggableOn::Tag.create!(name: n)}) }
|
2021-02-22 17:27:13 +05:30
|
|
|
|
|
|
|
it 'has runner attributes', :aggregate_failures do
|
|
|
|
expect(runner_data[:id]).to eq(ci_runner.id)
|
|
|
|
expect(runner_data[:description]).to eq(ci_runner.description)
|
2021-09-04 01:27:46 +05:30
|
|
|
expect(runner_data[:runner_type]).to eq(ci_runner.runner_type)
|
2021-02-22 17:27:13 +05:30
|
|
|
expect(runner_data[:active]).to eq(ci_runner.active)
|
2021-03-11 19:13:27 +05:30
|
|
|
expect(runner_data[:tags]).to match_array(tag_names)
|
2021-09-04 01:27:46 +05:30
|
|
|
expect(runner_data[:is_shared]).to eq(ci_runner.instance_type?)
|
2021-02-22 17:27:13 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
context 'pipeline without variables' do
|
|
|
|
it 'has empty variables hash' do
|
|
|
|
expect(attributes[:variables]).to be_a(Array)
|
2019-03-02 22:35:43 +05:30
|
|
|
expect(attributes[:variables]).to be_empty
|
2018-12-05 23:21:45 +05:30
|
|
|
end
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
context 'pipeline with variables' do
|
|
|
|
let(:build) { create(:ci_build, pipeline: pipeline) }
|
|
|
|
let(:data) { described_class.build(pipeline) }
|
|
|
|
let(:attributes) { data[:object_attributes] }
|
|
|
|
let!(:pipeline_variable) { create(:ci_pipeline_variable, pipeline: pipeline, key: 'TRIGGER_KEY_1', value: 'TRIGGER_VALUE_1') }
|
|
|
|
|
|
|
|
it { expect(attributes[:variables]).to be_a(Array) }
|
|
|
|
it { expect(attributes[:variables]).to contain_exactly({ key: 'TRIGGER_KEY_1', value: 'TRIGGER_VALUE_1' }) }
|
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
context 'when pipeline is a detached merge request pipeline' do
|
|
|
|
let(:merge_request) { create(:merge_request, :with_detached_merge_request_pipeline) }
|
|
|
|
let(:pipeline) { merge_request.all_pipelines.first }
|
|
|
|
|
|
|
|
it 'returns a source ref' do
|
|
|
|
expect(attributes[:ref]).to eq(merge_request.source_branch)
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
it 'returns merge request' do
|
|
|
|
merge_request_attrs = data[:merge_request]
|
|
|
|
|
|
|
|
expect(merge_request_attrs).to be_a(Hash)
|
|
|
|
expect(merge_request_attrs[:id]).to eq(merge_request.id)
|
|
|
|
expect(merge_request_attrs[:iid]).to eq(merge_request.iid)
|
|
|
|
expect(merge_request_attrs[:title]).to eq(merge_request.title)
|
|
|
|
expect(merge_request_attrs[:source_branch]).to eq(merge_request.source_branch)
|
|
|
|
expect(merge_request_attrs[:source_project_id]).to eq(merge_request.source_project_id)
|
|
|
|
expect(merge_request_attrs[:target_branch]).to eq(merge_request.target_branch)
|
|
|
|
expect(merge_request_attrs[:target_project_id]).to eq(merge_request.target_project_id)
|
|
|
|
expect(merge_request_attrs[:state]).to eq(merge_request.state)
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(merge_request_attrs[:merge_status]).to eq(merge_request.public_merge_status)
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(merge_request_attrs[:url]).to eq("http://localhost/#{merge_request.target_project.full_path}/-/merge_requests/#{merge_request.iid}")
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
2021-03-11 19:13:27 +05:30
|
|
|
|
|
|
|
context 'when pipeline has retried builds' do
|
|
|
|
before do
|
|
|
|
create(:ci_build, :retried, pipeline: pipeline)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not contain retried builds in payload' do
|
|
|
|
expect(data[:builds].count).to eq(1)
|
|
|
|
expect(build_data[:id]).to eq(build.id)
|
|
|
|
end
|
|
|
|
end
|
2021-04-17 20:07:23 +05:30
|
|
|
|
|
|
|
context 'build with environment' do
|
|
|
|
let!(:build) { create(:ci_build, :teardown_environment, pipeline: pipeline) }
|
|
|
|
|
|
|
|
it { expect(build_data[:environment][:name]).to eq(build.expanded_environment_name) }
|
|
|
|
it { expect(build_data[:environment][:action]).to eq(build.environment_action) }
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|