Commit 5c99ba03 authored by Balasankar "Balu" C's avatar Balasankar "Balu" C

Modify specs to match backend code

Signed-off-by: default avatarBalasankar "Balu" C <balasankar@gitlab.com>
parent 2a86722a
...@@ -216,7 +216,7 @@ describe 'Admin updates settings' do ...@@ -216,7 +216,7 @@ describe 'Admin updates settings' do
fill_in 'Username', with: 'test_user' fill_in 'Username', with: 'test_user'
fill_in 'service_push_channel', with: '#test_channel' fill_in 'service_push_channel', with: '#test_channel'
page.check('Notify only broken pipelines') page.check('Notify only broken pipelines')
page.check('Notify only default branch') page.select 'All branches', from: 'Branches to be notified'
check_all_events check_all_events
click_on 'Save' click_on 'Save'
......
...@@ -272,14 +272,61 @@ describe MicrosoftTeamsService do ...@@ -272,14 +272,61 @@ describe MicrosoftTeamsService do
end end
end end
context 'with default branch' do
let(:pipeline) do
create(:ci_pipeline, project: project, status: 'failed', sha: project.commit.sha, ref: project.default_branch)
end
context 'only notify for the default branch' do context 'only notify for the default branch' do
context 'when enabled' do before do
chat_service.branches_to_be_notified = "default"
end
it_behaves_like 'call Microsoft Teams API'
end
context 'notify for only protected branches' do
before do
chat_service.branches_to_be_notified = "protected"
end
it 'does not call the Microsoft Teams API for pipeline events' do
data = Gitlab::DataBuilder::Pipeline.build(pipeline)
result = chat_service.execute(data)
expect(result).to be_falsy
end
end
context 'notify for only default and protected branches' do
before do
chat_service.branches_to_be_notified = "default_and_protected"
end
it_behaves_like 'call Microsoft Teams API'
end
context 'notify for all branches' do
before do
chat_service.branches_to_be_notified = "all"
end
it_behaves_like 'call Microsoft Teams API'
end
end
context 'with protected branch' do
before do
create(:protected_branch, project: project, name: 'a-protected-branch')
end
let(:pipeline) do let(:pipeline) do
create(:ci_pipeline, project: project, status: 'failed', ref: 'not-the-default-branch') create(:ci_pipeline, project: project, status: 'failed', sha: project.commit.sha, ref: 'a-protected-branch')
end end
context 'only notify for the default branch' do
before do before do
chat_service.notify_only_default_branch = true chat_service.branches_to_be_notified = "default"
end end
it 'does not call the Microsoft Teams API for pipeline events' do it 'does not call the Microsoft Teams API for pipeline events' do
...@@ -290,14 +337,78 @@ describe MicrosoftTeamsService do ...@@ -290,14 +337,78 @@ describe MicrosoftTeamsService do
end end
end end
context 'when disabled' do context 'notify for only protected branches' do
before do
chat_service.branches_to_be_notified = "protected"
end
it_behaves_like 'call Microsoft Teams API'
end
context 'notify for only default and protected branches' do
before do
chat_service.branches_to_be_notified = "default_and_protected"
end
it_behaves_like 'call Microsoft Teams API'
end
context 'notify for all branches' do
before do
chat_service.branches_to_be_notified = "all"
end
it_behaves_like 'call Microsoft Teams API'
end
end
context 'with neither protected nor default branch' do
let(:pipeline) do let(:pipeline) do
create(:ci_pipeline, :failed, project: project, create(:ci_pipeline, project: project, status: 'failed', sha: project.commit.sha, ref: 'a-random-branch')
sha: project.commit.sha, ref: 'not-the-default-branch') end
context 'only notify for the default branch' do
before do
chat_service.branches_to_be_notified = "default"
end
it 'does not call the Microsoft Teams API for pipeline events' do
data = Gitlab::DataBuilder::Pipeline.build(pipeline)
result = chat_service.execute(data)
expect(result).to be_falsy
end
end
context 'notify for only protected branches' do
before do
chat_service.branches_to_be_notified = "protected"
end
it 'does not call the Microsoft Teams API for pipeline events' do
data = Gitlab::DataBuilder::Pipeline.build(pipeline)
result = chat_service.execute(data)
expect(result).to be_falsy
end
end
context 'notify for only default and protected branches' do
before do
chat_service.branches_to_be_notified = "default_and_protected"
end
it 'does not call the Microsoft Teams API for pipeline events' do
data = Gitlab::DataBuilder::Pipeline.build(pipeline)
result = chat_service.execute(data)
expect(result).to be_falsy
end
end end
context 'notify for all branches' do
before do before do
chat_service.notify_only_default_branch = false chat_service.branches_to_be_notified = "all"
end end
it_behaves_like 'call Microsoft Teams API' it_behaves_like 'call Microsoft Teams API'
......
...@@ -101,27 +101,132 @@ describe PipelinesEmailService, :mailer do ...@@ -101,27 +101,132 @@ describe PipelinesEmailService, :mailer do
it_behaves_like 'sending email' it_behaves_like 'sending email'
end end
context 'when pipeline is failed and on a non-default branch' do context 'when the pipeline failed' do
context 'on default branch' do
before do before do
data[:object_attributes][:ref] = 'not-the-default-branch' data[:object_attributes][:ref] = project.default_branch
pipeline.update(ref: 'not-the-default-branch') pipeline.update(ref: project.default_branch)
end end
context 'with notify_only_default branch on' do context 'notifications are enabled only for default branch' do
before do before do
subject.notify_only_default_branch = true subject.branches_to_be_notified = "default"
end end
it_behaves_like 'sending email' it_behaves_like 'sending email'
end end
context 'with notify_only_default_branch off' do context 'notifications are enabled only for protected branch' do
before do
subject.branches_to_be_notified = "protected"
end
it_behaves_like 'sending email'
end
context 'notifications are enabled only for default and protected branches ' do
before do
subject.branches_to_be_notified = "default_and_protected"
end
it_behaves_like 'sending email' it_behaves_like 'sending email'
end end
context 'notifications are enabled only for all branches' do
before do
subject.branches_to_be_notified = "all"
end
it_behaves_like 'sending email'
end
end
context 'on a protected branch' do
before do
create(:protected_branch, project: project, name: 'a-protected-branch')
data[:object_attributes][:ref] = 'a-protected-branch'
pipeline.update(ref: 'a-protected-branch')
end
context 'notifications are enabled only for default branch' do
before do
subject.branches_to_be_notified = "default"
end
it_behaves_like 'sending email'
end
context 'notifications are enabled only for protected branch' do
before do
subject.branches_to_be_notified = "protected"
end
it_behaves_like 'sending email'
end
context 'notifications are enabled only for default and protected branches ' do
before do
subject.branches_to_be_notified = "default_and_protected"
end
it_behaves_like 'sending email'
end
context 'notifications are enabled only for all branches' do
before do
subject.branches_to_be_notified = "all"
end
it_behaves_like 'sending email'
end
end
context 'on a neither protected nor default branch' do
before do
data[:object_attributes][:ref] = 'a-random-branch'
pipeline.update(ref: 'a-random-branch')
end
context 'notifications are enabled only for default branch' do
before do
subject.branches_to_be_notified = "default"
end
it_behaves_like 'sending email'
end
context 'notifications are enabled only for protected branch' do
before do
subject.branches_to_be_notified = "protected"
end
it_behaves_like 'sending email'
end
context 'notifications are enabled only for default and protected branches ' do
before do
subject.branches_to_be_notified = "default_and_protected"
end
it_behaves_like 'sending email'
end
context 'notifications are enabled only for all branches' do
before do
subject.branches_to_be_notified = "all"
end
it_behaves_like 'sending email'
end
end
end end
end end
describe '#execute' do describe '#execute' do
before do
subject.project = project
end
def run def run
subject.execute(data) subject.execute(data)
end end
...@@ -159,38 +264,124 @@ describe PipelinesEmailService, :mailer do ...@@ -159,38 +264,124 @@ describe PipelinesEmailService, :mailer do
end end
end end
context 'with notify_only_default_branch off' do context 'when the pipeline failed' do
context 'with default branch' do context 'on a default branch' do
before do
data[:object_attributes][:ref] = project.default_branch
pipeline.update(ref: project.default_branch)
end
context 'notifications are enabled only for default branch' do
before do
subject.branches_to_be_notified = "default"
end
it_behaves_like 'sending email'
end
context 'notifications are enabled only for protected branch' do
before do
subject.branches_to_be_notified = "protected"
end
it_behaves_like 'not sending email'
end
context 'notifications are enabled only for default and protected branches ' do
before do
subject.branches_to_be_notified = "default_and_protected"
end
it_behaves_like 'sending email' it_behaves_like 'sending email'
end end
context 'with non default branch' do context 'notifications are enabled only for all branches' do
before do
subject.branches_to_be_notified = "all"
end
it_behaves_like 'sending email'
end
end
context 'on a protected branch' do
before do
create(:protected_branch, project: project, name: 'a-protected-branch')
data[:object_attributes][:ref] = 'a-protected-branch'
pipeline.update(ref: 'a-protected-branch')
end
context 'notifications are enabled only for default branch' do
before do before do
data[:object_attributes][:ref] = 'not-the-default-branch' subject.branches_to_be_notified = "default"
pipeline.update(ref: 'not-the-default-branch') end
it_behaves_like 'not sending email'
end
context 'notifications are enabled only for protected branch' do
before do
subject.branches_to_be_notified = "protected"
end end
it_behaves_like 'sending email' it_behaves_like 'sending email'
end end
context 'notifications are enabled only for default and protected branches ' do
before do
subject.branches_to_be_notified = "default_and_protected"
end end
context 'with notify_only_default_branch on' do it_behaves_like 'sending email'
end
context 'notifications are enabled only for all branches' do
before do before do
subject.notify_only_default_branch = true subject.branches_to_be_notified = "all"
end end
context 'with default branch' do
it_behaves_like 'sending email' it_behaves_like 'sending email'
end end
end
context 'on a neither protected nor default branch' do
before do
data[:object_attributes][:ref] = 'a-random-branch'
pipeline.update(ref: 'a-random-branch')
end
context 'notifications are enabled only for default branch' do
before do
subject.branches_to_be_notified = "default"
end
context 'with non default branch' do it_behaves_like 'not sending email'
end
context 'notifications are enabled only for protected branch' do
before do before do
data[:object_attributes][:ref] = 'not-the-default-branch' subject.branches_to_be_notified = "protected"
pipeline.update(ref: 'not-the-default-branch')
end end
it_behaves_like 'not sending email' it_behaves_like 'not sending email'
end end
context 'notifications are enabled only for default and protected branches ' do
before do
subject.branches_to_be_notified = "default_and_protected"
end
it_behaves_like 'not sending email'
end
context 'notifications are enabled only for all branches' do
before do
subject.branches_to_be_notified = "all"
end
it_behaves_like 'sending email'
end
end
end end
end end
......
...@@ -70,14 +70,60 @@ shared_examples_for "chat service" do |service_name| ...@@ -70,14 +70,60 @@ shared_examples_for "chat service" do |service_name|
subject.execute(sample_data) subject.execute(sample_data)
end end
context "with not default branch" do context "with default branch" do
let(:sample_data) do let(:sample_data) do
Gitlab::DataBuilder::Push.build(project: project, user: user, ref: "not-the-default-branch") Gitlab::DataBuilder::Push.build(project: project, user: user, ref: project.default_branch)
end end
context "when notify_only_default_branch enabled" do context "when only default branch are to be notified" do
before do before do
subject.notify_only_default_branch = true subject.branches_to_be_notified = "default"
end
it_behaves_like "#{service_name} service"
end
context "when only protected branches are to be notified" do
before do
subject.branches_to_be_notified = "protected"
end
it "does not call the Discord Webhooks API" do
result = subject.execute(sample_data)
expect(result).to be_falsy
end
end
context "when default and protected branches are to be notified" do
before do
subject.branches_to_be_notified = "default_and_protected"
end
it_behaves_like "#{service_name} service"
end
context "when all branches are to be notified" do
before do
subject.branches_to_be_notified = "all"
end
it_behaves_like "#{service_name} service"
end
end
context "with protected branch" do
before do
create(:protected_branch, project: project, name: "a-protected-branch")
end
let(:sample_data) do
Gitlab::DataBuilder::Push.build(project: project, user: user, ref: "a-protected-branch")
end
context "when only default branch are to be notified" do
before do
subject.branches_to_be_notified = "default"
end end
it "does not call the Discord Webhooks API" do it "does not call the Discord Webhooks API" do
...@@ -87,9 +133,75 @@ shared_examples_for "chat service" do |service_name| ...@@ -87,9 +133,75 @@ shared_examples_for "chat service" do |service_name|
end end
end end
context "when notify_only_default_branch disabled" do context "when only protected branches are to be notified" do
before do
subject.branches_to_be_notified = "protected"
end
it_behaves_like "#{service_name} service"
end
context "when default and protected branches are to be notified" do
before do
subject.branches_to_be_notified = "default_and_protected"
end
it_behaves_like "#{service_name} service"
end
context "when all branches are to be notified" do
before do before do
subject.notify_only_default_branch = false subject.branches_to_be_notified = "all"
end
it_behaves_like "#{service_name} service"
end
end
context "with neither default nor protected branch" do
let(:sample_data) do
Gitlab::DataBuilder::Push.build(project: project, user: user, ref: "a-random-branch")
end
context "when only default branch are to be notified" do
before do
subject.branches_to_be_notified = "default"
end
it "does not call the Discord Webhooks API" do
result = subject.execute(sample_data)
expect(result).to be_falsy
end
end
context "when only protected branches are to be notified" do
before do
subject.branches_to_be_notified = "protected"
end
it "does not call the Discord Webhooks API" do
result = subject.execute(sample_data)
expect(result).to be_falsy
end
end
context "when default and protected branches are to be notified" do
before do
subject.branches_to_be_notified = "default_and_protected"
end
it "does not call the Discord Webhooks API" do
result = subject.execute(sample_data)
expect(result).to be_falsy
end
end
context "when all branches are to be notified" do
before do
subject.branches_to_be_notified = "all"
end end
it_behaves_like "#{service_name} service" it_behaves_like "#{service_name} service"
...@@ -220,15 +332,86 @@ shared_examples_for "chat service" do |service_name| ...@@ -220,15 +332,86 @@ shared_examples_for "chat service" do |service_name|
end end
end end
context "with not default branch" do context "with protected branch" do
before do
create(:protected_branch, project: project, name: 'a-protected-branch')
end
let(:pipeline) do let(:pipeline) do
create(:ci_pipeline, :failed, project: project, create(:ci_pipeline, :failed, project: project,
sha: project.commit.sha, ref: "not-the-default-branch") sha: project.commit.sha, ref: 'a-protected-branch')
end
context "when only default branch are to be notified" do
before do
subject.branches_to_be_notified = "default"
end
it "does not call the Discord Webhooks API" do
result = subject.execute(sample_data)
expect(result).to be_falsy
end
end
context "when only protected branches are to be notified" do
before do
subject.branches_to_be_notified = "protected"
end
it_behaves_like "#{service_name} service"
end
context "when default and protected branches are to be notified" do
before do
subject.branches_to_be_notified = "default_and_protected"
end
it_behaves_like "#{service_name} service"
end
context "when all branches are to be notified" do
before do
subject.branches_to_be_notified = "all"
end
it_behaves_like "#{service_name} service"
end
end
context "with neither default nor protected branch" do
let(:pipeline) do
create(:ci_pipeline, :failed, project: project,
sha: project.commit.sha, ref: "a-random-branch")
end
context "when only default branch are to be notified" do
before do
subject.branches_to_be_notified = "default"
end
it "does not call the Discord Webhooks API" do
result = subject.execute(sample_data)
expect(result).to be_falsy
end
end
context "when only protected branches are to be notified" do
before do
subject.branches_to_be_notified = "protected"
end
it "does not call the Discord Webhooks API" do
result = subject.execute(sample_data)
expect(result).to be_falsy
end
end end
context "when notify_only_default_branch enabled" do context "when default and protected branches are to be notified" do
before do before do
subject.notify_only_default_branch = true subject.branches_to_be_notified = "default_and_protected"
end end
it "does not call the Discord Webhooks API" do it "does not call the Discord Webhooks API" do
...@@ -238,9 +421,9 @@ shared_examples_for "chat service" do |service_name| ...@@ -238,9 +421,9 @@ shared_examples_for "chat service" do |service_name|
end end
end end
context "when notify_only_default_branch disabled" do context "when all branches are to be notified" do
before do before do
subject.notify_only_default_branch = false subject.branches_to_be_notified = "all"
end end
it_behaves_like "#{service_name} service" it_behaves_like "#{service_name} service"
......
...@@ -269,29 +269,176 @@ RSpec.shared_examples 'slack or mattermost notifications' do ...@@ -269,29 +269,176 @@ RSpec.shared_examples 'slack or mattermost notifications' do
WebMock.stub_request(:post, webhook_url) WebMock.stub_request(:post, webhook_url)
end end
context 'only notify for the default branch' do context 'on default branch' do
context 'when enabled' do it 'still notifies about pushed tags' do
ref = "#{Gitlab::Git::TAG_REF_PREFIX}test"
push_sample_data = Gitlab::DataBuilder::Push.build(project: project, user: user, ref: ref)
chat_service.execute(push_sample_data)
expect(WebMock).to have_requested(:post, webhook_url).once
end
context 'notification enabled only for default branch' do
before do before do
chat_service.notify_only_default_branch = true chat_service.branches_to_be_notified = "default"
end end
it 'does not notify push events if they are not for the default branch' do it 'notifies about push events' do
ref = "#{Gitlab::Git::BRANCH_REF_PREFIX}test" push_sample_data = Gitlab::DataBuilder::Push.build(
project: project,
user: user,
ref: project.default_branch
)
chat_service.execute(push_sample_data)
expect(WebMock).to have_requested(:post, webhook_url)
end
end
context 'notification enabled only for protected branches' do
before do
chat_service.branches_to_be_notified = "protected"
end
it 'does not notify about push events' do
push_sample_data = Gitlab::DataBuilder::Push.build(
project: project,
user: user,
ref: project.default_branch
)
chat_service.execute(push_sample_data)
expect(WebMock).not_to have_requested(:post, webhook_url).once
end
end
context 'notification enabled only for default and protected branches' do
before do
chat_service.branches_to_be_notified = "default_and_protected"
end
it 'notifies about push events' do
push_sample_data = Gitlab::DataBuilder::Push.build(
project: project,
user: user,
ref: project.default_branch
)
chat_service.execute(push_sample_data)
expect(WebMock).to have_requested(:post, webhook_url).once
end
end
context 'notification enabled for all branches' do
before do
chat_service.branches_to_be_notified = "all"
end
it 'notifies about push events' do
push_sample_data = Gitlab::DataBuilder::Push.build(
project: project,
user: user,
ref: project.default_branch
)
chat_service.execute(push_sample_data)
expect(WebMock).to have_requested(:post, webhook_url).once
end
end
end
context 'on a protected branch' do
before do
create(:protected_branch, project: project, name: 'a-protected-branch')
end
it 'still notifies about pushed tags' do
ref = "#{Gitlab::Git::TAG_REF_PREFIX}test"
push_sample_data = Gitlab::DataBuilder::Push.build(project: project, user: user, ref: ref) push_sample_data = Gitlab::DataBuilder::Push.build(project: project, user: user, ref: ref)
chat_service.execute(push_sample_data) chat_service.execute(push_sample_data)
expect(WebMock).to have_requested(:post, webhook_url).once
end
context 'notification enabled only for default branch' do
before do
chat_service.branches_to_be_notified = "default"
end
it 'does not notify about push events' do
push_sample_data = Gitlab::DataBuilder::Push.build(
project: project,
user: user,
ref: 'a-protected-branch'
)
chat_service.execute(push_sample_data)
expect(WebMock).not_to have_requested(:post, webhook_url) expect(WebMock).not_to have_requested(:post, webhook_url)
end end
end
context 'notification enabled only for protected branches' do
before do
chat_service.branches_to_be_notified = "protected"
end
it 'notifies about push events' do
push_sample_data = Gitlab::DataBuilder::Push.build(
project: project,
user: user,
ref: 'a-protected-branch'
)
chat_service.execute(push_sample_data)
expect(WebMock).to have_requested(:post, webhook_url).once
end
end
context 'notification enabled only for default and protected branches' do
before do
chat_service.branches_to_be_notified = "default_and_protected"
end
it 'notifies about push events' do
push_sample_data = Gitlab::DataBuilder::Push.build(
project: project,
user: user,
ref: 'a-protected-branch'
)
chat_service.execute(push_sample_data)
expect(WebMock).to have_requested(:post, webhook_url).once
end
end
it 'notifies about push events for the default branch' do context 'notification enabled for all branches' do
push_sample_data = Gitlab::DataBuilder::Push.build_sample(project, user) before do
chat_service.branches_to_be_notified = "all"
end
it 'notifies about push events' do
push_sample_data = Gitlab::DataBuilder::Push.build(
project: project,
user: user,
ref: 'a-protected-branch'
)
chat_service.execute(push_sample_data) chat_service.execute(push_sample_data)
expect(WebMock).to have_requested(:post, webhook_url).once expect(WebMock).to have_requested(:post, webhook_url).once
end end
end
end
context 'on a neither protected nor default branch' do
it 'still notifies about pushed tags' do it 'still notifies about pushed tags' do
ref = "#{Gitlab::Git::TAG_REF_PREFIX}test" ref = "#{Gitlab::Git::TAG_REF_PREFIX}test"
push_sample_data = Gitlab::DataBuilder::Push.build(project: project, user: user, ref: ref) push_sample_data = Gitlab::DataBuilder::Push.build(project: project, user: user, ref: ref)
...@@ -300,16 +447,72 @@ RSpec.shared_examples 'slack or mattermost notifications' do ...@@ -300,16 +447,72 @@ RSpec.shared_examples 'slack or mattermost notifications' do
expect(WebMock).to have_requested(:post, webhook_url).once expect(WebMock).to have_requested(:post, webhook_url).once
end end
context 'notification enabled only for default branch' do
before do
chat_service.branches_to_be_notified = "default"
end
it 'does not notify about push events' do
push_sample_data = Gitlab::DataBuilder::Push.build(
project: project,
user: user,
ref: 'a-random-branch'
)
chat_service.execute(push_sample_data)
expect(WebMock).not_to have_requested(:post, webhook_url)
end
end end
context 'when disabled' do context 'notification enabled only for protected branches' do
before do before do
chat_service.notify_only_default_branch = false chat_service.branches_to_be_notified = "protected"
end end
it 'notifies about all push events' do it 'does not notify about push events' do
ref = "#{Gitlab::Git::BRANCH_REF_PREFIX}test" push_sample_data = Gitlab::DataBuilder::Push.build(
push_sample_data = Gitlab::DataBuilder::Push.build(project: project, user: user, ref: ref) project: project,
user: user,
ref: 'a-random-branch'
)
chat_service.execute(push_sample_data)
expect(WebMock).not_to have_requested(:post, webhook_url).once
end
end
context 'notification enabled only for default and protected branches' do
before do
chat_service.branches_to_be_notified = "default_and_protected"
end
it 'does not notify about push events' do
push_sample_data = Gitlab::DataBuilder::Push.build(
project: project,
user: user,
ref: 'a-random-branch'
)
chat_service.execute(push_sample_data)
expect(WebMock).not_to have_requested(:post, webhook_url).once
end
end
context 'notification enabled for all branches' do
before do
chat_service.branches_to_be_notified = "all"
end
it 'notifies about push events' do
push_sample_data = Gitlab::DataBuilder::Push.build(
project: project,
user: user,
ref: 'a-random-branch'
)
chat_service.execute(push_sample_data) chat_service.execute(push_sample_data)
...@@ -451,15 +654,61 @@ RSpec.shared_examples 'slack or mattermost notifications' do ...@@ -451,15 +654,61 @@ RSpec.shared_examples 'slack or mattermost notifications' do
end end
end end
context 'only notify for the default branch' do context 'on a default branch' do
context 'when enabled' do
let(:pipeline) do let(:pipeline) do
create(:ci_pipeline, :failed, project: project, sha: project.commit.sha, ref: 'not-the-default-branch') create(:ci_pipeline, :failed, project: project, sha: project.commit.sha, ref: project.default_branch)
end end
context 'notification enabled only for default branch' do
before do before do
chat_service.notify_only_default_branch = true chat_service.branches_to_be_notified = 'default'
WebMock.stub_request(:post, webhook_url) end
it_behaves_like 'call Slack/Mattermost API'
end
context 'notification enabled only for protected branch' do
before do
chat_service.branches_to_be_notified = 'protected'
end
it 'does not call the Slack/Mattermost API for pipeline events' do
data = Gitlab::DataBuilder::Pipeline.build(pipeline)
result = chat_service.execute(data)
expect(result).to be_falsy
end
end
context 'notification enabled only for default and protected branches' do
before do
chat_service.branches_to_be_notified = 'default_and_protected'
end
it_behaves_like 'call Slack/Mattermost API'
end
context 'notification enabled for all branches' do
before do
chat_service.branches_to_be_notified = 'all'
end
it_behaves_like 'call Slack/Mattermost API'
end
end
context 'on a protected branch' do
before do
create(:protected_branch, project: project, name: 'a-protected-branch')
end
let(:pipeline) do
create(:ci_pipeline, :failed, project: project, sha: project.commit.sha, ref: 'a-protected-branch')
end
context 'notification enabled only for default branch' do
before do
chat_service.branches_to_be_notified = 'default'
end end
it 'does not call the Slack/Mattermost API for pipeline events' do it 'does not call the Slack/Mattermost API for pipeline events' do
...@@ -470,13 +719,78 @@ RSpec.shared_examples 'slack or mattermost notifications' do ...@@ -470,13 +719,78 @@ RSpec.shared_examples 'slack or mattermost notifications' do
end end
end end
context 'when disabled' do context 'notification enabled only for protected branch' do
before do
chat_service.branches_to_be_notified = 'protected'
end
it_behaves_like 'call Slack/Mattermost API'
end
context 'notification enabled only for default and protected branches' do
before do
chat_service.branches_to_be_notified = 'default_and_protected'
end
it_behaves_like 'call Slack/Mattermost API'
end
context 'notification enabled for all branches' do
before do
chat_service.branches_to_be_notified = 'all'
end
it_behaves_like 'call Slack/Mattermost API'
end
end
context 'on a neithuer protected nor default branch' do
let(:pipeline) do let(:pipeline) do
create(:ci_pipeline, :failed, project: project, sha: project.commit.sha, ref: 'not-the-default-branch') create(:ci_pipeline, :failed, project: project, sha: project.commit.sha, ref: 'a-random-branch')
end
context 'notification enabled only for default branch' do
before do
chat_service.branches_to_be_notified = 'default'
end
it 'does not call the Slack/Mattermost API for pipeline events' do
data = Gitlab::DataBuilder::Pipeline.build(pipeline)
result = chat_service.execute(data)
expect(result).to be_falsy
end
end
context 'notification enabled only for protected branch' do
before do
chat_service.branches_to_be_notified = 'protected'
end
it 'does not call the Slack/Mattermost API for pipeline events' do
data = Gitlab::DataBuilder::Pipeline.build(pipeline)
result = chat_service.execute(data)
expect(result).to be_falsy
end
end
context 'notification enabled only for default and protected branches' do
before do
chat_service.branches_to_be_notified = 'default_and_protected'
end
it 'does not call the Slack/Mattermost API for pipeline events' do
data = Gitlab::DataBuilder::Pipeline.build(pipeline)
result = chat_service.execute(data)
expect(result).to be_falsy
end
end end
context 'notification enabled for all branches' do
before do before do
chat_service.notify_only_default_branch = false chat_service.branches_to_be_notified = 'all'
end end
it_behaves_like 'call Slack/Mattermost API' it_behaves_like 'call Slack/Mattermost API'
......
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