Commit 99928aca authored by Kamil Trzcinski's avatar Kamil Trzcinski

Enhance a pipeline event tests to analyse number of returned builds

parent ffa75a49
...@@ -3,11 +3,15 @@ require 'spec_helper' ...@@ -3,11 +3,15 @@ require 'spec_helper'
describe Gitlab::DataBuilder::PipelineDataBuilder do describe Gitlab::DataBuilder::PipelineDataBuilder do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project) } let(:project) { create(:project) }
let(:pipeline) do let(:pipeline) do
create(:ci_pipeline, create(:ci_pipeline,
project: project, status: 'success', project: project,
sha: project.commit.sha, ref: project.default_branch) status: 'success',
sha: project.commit.sha,
ref: project.default_branch)
end end
let!(:build) { create(:ci_build, pipeline: pipeline) } let!(:build) { create(:ci_build, pipeline: pipeline) }
describe '.build' do describe '.build' do
......
...@@ -2,7 +2,7 @@ require 'spec_helper' ...@@ -2,7 +2,7 @@ require 'spec_helper'
describe Ci::Pipeline, models: true do describe Ci::Pipeline, models: true do
let(:project) { FactoryGirl.create :empty_project } let(:project) { FactoryGirl.create :empty_project }
let(:pipeline) { FactoryGirl.create :ci_pipeline, project: project } let(:pipeline) { FactoryGirl.create :ci_empty_pipeline, project: project }
it { is_expected.to belong_to(:project) } it { is_expected.to belong_to(:project) }
it { is_expected.to belong_to(:user) } it { is_expected.to belong_to(:user) }
...@@ -18,6 +18,8 @@ describe Ci::Pipeline, models: true do ...@@ -18,6 +18,8 @@ describe Ci::Pipeline, models: true do
it { is_expected.to respond_to :git_author_email } it { is_expected.to respond_to :git_author_email }
it { is_expected.to respond_to :short_sha } it { is_expected.to respond_to :short_sha }
it { is_expected.to delegate_method(:stages).to(:statuses) }
describe '#valid_commit_sha' do describe '#valid_commit_sha' do
context 'commit.sha can not start with 00000000' do context 'commit.sha can not start with 00000000' do
before do before do
...@@ -261,43 +263,40 @@ describe Ci::Pipeline, models: true do ...@@ -261,43 +263,40 @@ describe Ci::Pipeline, models: true do
end end
before do before do
WebMock.stub_request(:post, hook.url)
pipeline.touch
ProjectWebHookWorker.drain ProjectWebHookWorker.drain
end end
context 'with pipeline hooks enabled' do context 'with pipeline hooks enabled' do
let(:enabled) { true } let(:enabled) { true }
it 'executes pipeline_hook after touched' do
expect(WebMock).to have_requested(:post, hook.url).once
end
context 'with multiple builds' do context 'with multiple builds' do
let(:build_a) { create_build('a') } let!(:build_a) { create_build('a') }
let(:build_b) { create_build('b') } let!(:build_b) { create_build('b') }
before do it 'fires exactly 3 hooks' do
stub_request('pending')
build_a.queue
build_b.queue
stub_request('running')
build_a.run build_a.run
build_b.run build_b.run
stub_request('success')
build_a.success build_a.success
build_b.success build_b.success
end end
it 'fires 3 hooks' do
%w(pending running success).each do |status|
expect(WebMock).to requested(status)
end
end
def create_build(name) def create_build(name)
create(:ci_build, :pending, pipeline: pipeline, name: name) create(:ci_build, :pending, pipeline: pipeline, name: name)
end end
def requested(status) def stub_request(status)
have_requested(:post, hook.url).with do |req| WebMock.stub_request(:post, hook.url).with do |req|
JSON.parse(req.body)['object_attributes']['status'] == status json_body = JSON.parse(req.body)
end.once json_body['object_attributes']['status'] == status &&
json_body['builds'].length == 2
end
end end
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