2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::DataBuilder::Build do
|
2021-03-11 19:13:27 +05:30
|
|
|
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)}) }
|
2020-03-13 15:44:24 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:build) { create(:ci_build, :running, runner: runner, user: user) }
|
2015-12-23 02:04:40 +05:30
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
describe '.build' do
|
2015-12-23 02:04:40 +05:30
|
|
|
let(:data) do
|
2016-09-13 17:45:13 +05:30
|
|
|
described_class.build(build)
|
2015-12-23 02:04:40 +05:30
|
|
|
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) }
|
2016-01-14 18:37:52 +05:30
|
|
|
it { expect(data[:build_allow_failure]).to eq(false) }
|
2018-11-20 20:47:30 +05:30
|
|
|
it { expect(data[:build_failure_reason]).to eq(build.failure_reason) }
|
2015-12-23 02:04:40 +05:30
|
|
|
it { expect(data[:project_id]).to eq(build.project.id) }
|
2018-03-27 19:54:05 +05:30
|
|
|
it { expect(data[:project_name]).to eq(build.project.full_name) }
|
2020-01-01 13:55:28 +05:30
|
|
|
it { expect(data[:pipeline_id]).to eq(build.pipeline.id) }
|
2020-03-13 15:44:24 +05:30
|
|
|
it {
|
|
|
|
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
|
|
|
|
})
|
|
|
|
}
|
2020-01-01 13:55:28 +05:30
|
|
|
it { expect(data[:commit][:id]).to eq(build.pipeline.id) }
|
|
|
|
it { expect(data[:runner][:id]).to eq(build.runner.id) }
|
2021-03-11 19:13:27 +05:30
|
|
|
it { expect(data[:runner][:tags]).to match_array(tag_names) }
|
2020-01-01 13:55:28 +05:30
|
|
|
it { expect(data[:runner][:description]).to eq(build.runner.description) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
context 'commit author_url' do
|
|
|
|
context 'when no commit present' do
|
|
|
|
let(:build) { create(: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}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when commit present but has no author' do
|
|
|
|
let(:build) { create(: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}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when commit and author are present' do
|
|
|
|
let(:build) { create(: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))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-12-23 02:04:40 +05:30
|
|
|
end
|
|
|
|
end
|