Commit fe694ad2 authored by Justin Ho Tuan Duong's avatar Justin Ho Tuan Duong Committed by Bob Van Landuyt

Refactor test service to service object

Add ability to test with different events
parent c2fc5a4b
...@@ -57,11 +57,10 @@ class Projects::ServicesController < Projects::ApplicationController ...@@ -57,11 +57,10 @@ class Projects::ServicesController < Projects::ApplicationController
return { error: true, message: _('Validations failed.'), service_response: @service.errors.full_messages.join(','), test_failed: false } return { error: true, message: _('Validations failed.'), service_response: @service.errors.full_messages.join(','), test_failed: false }
end end
data = @service.test_data(project, current_user) result = Integrations::Test::ProjectService.new(@service, current_user, params[:event]).execute
outcome = @service.test(data)
unless outcome[:success] unless result[:success]
return { error: true, message: _('Test failed.'), service_response: outcome[:result].to_s, test_failed: true } return { error: true, message: _('Test failed.'), service_response: result[:message].to_s, test_failed: true }
end end
{} {}
......
...@@ -211,11 +211,6 @@ class JiraService < IssueTrackerService ...@@ -211,11 +211,6 @@ class JiraService < IssueTrackerService
{ success: success, result: result } { success: success, result: result }
end end
# Jira does not need test data.
def test_data(_, _)
nil
end
override :support_close_issue? override :support_close_issue?
def support_close_issue? def support_close_issue?
true true
......
...@@ -56,12 +56,6 @@ class PipelinesEmailService < Service ...@@ -56,12 +56,6 @@ class PipelinesEmailService < Service
project&.ci_pipelines&.any? project&.ci_pipelines&.any?
end end
def test_data(project, user)
data = Gitlab::DataBuilder::Pipeline.build(project.ci_pipelines.last)
data[:user] = user.hook_attrs
data
end
def fields def fields
[ [
{ type: 'textarea', { type: 'textarea',
......
...@@ -142,10 +142,6 @@ class Service < ApplicationRecord ...@@ -142,10 +142,6 @@ class Service < ApplicationRecord
data_fields.as_json(only: data_fields.class.column_names).except('id', 'service_id') data_fields.as_json(only: data_fields.class.column_names).except('id', 'service_id')
end end
def test_data(project, user)
Gitlab::DataBuilder::Push.build_sample(project, user)
end
def event_channel_names def event_channel_names
[] []
end end
......
# frozen_string_literal: true
module Integrations
module ProjectTestData
private
def push_events_data
Gitlab::DataBuilder::Push.build_sample(project, current_user)
end
def note_events_data
note = project.notes.first
return { error: s_('TestHooks|Ensure the project has notes.') } unless note.present?
Gitlab::DataBuilder::Note.build(note, current_user)
end
def issues_events_data
issue = project.issues.first
return { error: s_('TestHooks|Ensure the project has issues.') } unless issue.present?
issue.to_hook_data(current_user)
end
def merge_requests_events_data
merge_request = project.merge_requests.first
return { error: s_('TestHooks|Ensure the project has merge requests.') } unless merge_request.present?
merge_request.to_hook_data(current_user)
end
def job_events_data
build = project.builds.first
return { error: s_('TestHooks|Ensure the project has CI jobs.') } unless build.present?
Gitlab::DataBuilder::Build.build(build)
end
def pipeline_events_data
pipeline = project.ci_pipelines.newest_first.first
return { error: s_('TestHooks|Ensure the project has CI pipelines.') } unless pipeline.present?
Gitlab::DataBuilder::Pipeline.build(pipeline)
end
def wiki_page_events_data
page = project.wiki.list_pages(limit: 1).first
if !project.wiki_enabled? || page.blank?
return { error: s_('TestHooks|Ensure the wiki is enabled and has pages.') }
end
Gitlab::DataBuilder::WikiPage.build(page, current_user, 'create')
end
def deployment_events_data
deployment = project.deployments.first
return { error: s_('TestHooks|Ensure the project has deployments.') } unless deployment.present?
Gitlab::DataBuilder::Deployment.build(deployment)
end
end
end
# frozen_string_literal: true
module Integrations
module Test
class BaseService
include BaseServiceUtility
attr_accessor :integration, :current_user, :event
# @param integration [Service] The external service that will be called
# @param current_user [User] The user calling the service
# @param event [String/nil] The event that triggered this
def initialize(integration, current_user, event = nil)
@integration = integration
@current_user = current_user
@event = event
end
def execute
if event && (integration.supported_events.exclude?(event) || data.blank?)
return error('Testing not available for this event')
end
return error(data[:error]) if data[:error].present?
integration.test(data)
end
private
def data
raise NotImplementedError
end
end
end
end
# frozen_string_literal: true
module Integrations
module Test
class ProjectService < Integrations::Test::BaseService
include Integrations::ProjectTestData
include Gitlab::Utils::StrongMemoize
def project
strong_memoize(:project) do
integration.project
end
end
private
def data
strong_memoize(:data) do
next pipeline_events_data if integration.is_a?(::PipelinesEmailService)
case event
when 'push', 'tag_push'
push_events_data
when 'note', 'confidential_note'
note_events_data
when 'issue', 'confidential_issue'
issues_events_data
when 'merge_request'
merge_requests_events_data
when 'job'
job_events_data
when 'pipeline'
pipeline_events_data
when 'wiki_page'
wiki_page_events_data
when 'deployment'
deployment_events_data
else
push_events_data
end
end
end
end
end
end
Integrations::Test::ProjectService.prepend_if_ee('::EE::Integrations::Test::ProjectService')
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
module TestHooks module TestHooks
class BaseService class BaseService
include BaseServiceUtility
attr_accessor :hook, :current_user, :trigger attr_accessor :hook, :current_user, :trigger
def initialize(hook, current_user, trigger) def initialize(hook, current_user, trigger)
...@@ -12,31 +14,11 @@ module TestHooks ...@@ -12,31 +14,11 @@ module TestHooks
def execute def execute
trigger_key = hook.class.triggers.key(trigger.to_sym) trigger_key = hook.class.triggers.key(trigger.to_sym)
trigger_data_method = "#{trigger}_data"
if trigger_key.nil? || !self.respond_to?(trigger_data_method, true)
return error('Testing not available for this hook')
end
error_message = catch(:validation_error) do # rubocop:disable Cop/BanCatchThrow
sample_data = self.__send__(trigger_data_method) # rubocop:disable GitlabSecurity/PublicSend
return hook.execute(sample_data, trigger_key) # rubocop:disable Cop/AvoidReturnFromBlocks
end
error(error_message)
end
private
def error(message, http_status = nil) return error('Testing not available for this hook') if trigger_key.nil? || data.blank?
result = { return error(data[:error]) if data[:error].present?
message: message,
status: :error
}
result[:http_status] = http_status if http_status hook.execute(data, trigger_key)
result
end end
end end
end end
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
module TestHooks module TestHooks
class ProjectService < TestHooks::BaseService class ProjectService < TestHooks::BaseService
include Integrations::ProjectTestData
include Gitlab::Utils::StrongMemoize
attr_writer :project attr_writer :project
def project def project
...@@ -10,58 +13,25 @@ module TestHooks ...@@ -10,58 +13,25 @@ module TestHooks
private private
def push_events_data def data
throw(:validation_error, s_('TestHooks|Ensure the project has at least one commit.')) if project.empty_repo? # rubocop:disable Cop/BanCatchThrow strong_memoize(:data) do
case trigger
Gitlab::DataBuilder::Push.build_sample(project, current_user) when 'push_events', 'tag_push_events'
end push_events_data
when 'note_events'
alias_method :tag_push_events_data, :push_events_data note_events_data
when 'issues_events', 'confidential_issues_events'
def note_events_data issues_events_data
note = project.notes.first when 'merge_requests_events'
throw(:validation_error, s_('TestHooks|Ensure the project has notes.')) unless note.present? # rubocop:disable Cop/BanCatchThrow merge_requests_events_data
when 'job_events'
Gitlab::DataBuilder::Note.build(note, current_user) job_events_data
end when 'pipeline_events'
pipeline_events_data
def issues_events_data when 'wiki_page_events'
issue = project.issues.first wiki_page_events_data
throw(:validation_error, s_('TestHooks|Ensure the project has issues.')) unless issue.present? # rubocop:disable Cop/BanCatchThrow end
issue.to_hook_data(current_user)
end
alias_method :confidential_issues_events_data, :issues_events_data
def merge_requests_events_data
merge_request = project.merge_requests.first
throw(:validation_error, s_('TestHooks|Ensure the project has merge requests.')) unless merge_request.present? # rubocop:disable Cop/BanCatchThrow
merge_request.to_hook_data(current_user)
end
def job_events_data
build = project.builds.first
throw(:validation_error, s_('TestHooks|Ensure the project has CI jobs.')) unless build.present? # rubocop:disable Cop/BanCatchThrow
Gitlab::DataBuilder::Build.build(build)
end
def pipeline_events_data
pipeline = project.ci_pipelines.first
throw(:validation_error, s_('TestHooks|Ensure the project has CI pipelines.')) unless pipeline.present? # rubocop:disable Cop/BanCatchThrow
Gitlab::DataBuilder::Pipeline.build(pipeline)
end
def wiki_page_events_data
page = project.wiki.list_pages(limit: 1).first
if !project.wiki_enabled? || page.blank?
throw(:validation_error, s_('TestHooks|Ensure the wiki is enabled and has pages.')) # rubocop:disable Cop/BanCatchThrow
end end
Gitlab::DataBuilder::WikiPage.build(page, current_user, 'create')
end end
end end
end end
...@@ -2,23 +2,26 @@ ...@@ -2,23 +2,26 @@
module TestHooks module TestHooks
class SystemService < TestHooks::BaseService class SystemService < TestHooks::BaseService
private include Gitlab::Utils::StrongMemoize
def push_events_data
Gitlab::DataBuilder::Push.sample_data
end
def tag_push_events_data private
Gitlab::DataBuilder::Push.sample_data
end
def repository_update_events_data def data
Gitlab::DataBuilder::Repository.sample_data strong_memoize(:data) do
case trigger
when 'push_events', 'tag_push_events'
Gitlab::DataBuilder::Push.sample_data
when 'repository_update_events'
Gitlab::DataBuilder::Repository.sample_data
when 'merge_requests_events'
merge_requests_events_data
end
end
end end
def merge_requests_events_data def merge_requests_events_data
merge_request = MergeRequest.of_projects(current_user.projects.select(:id)).first merge_request = MergeRequest.of_projects(current_user.projects.select(:id)).first
throw(:validation_error, s_('TestHooks|Ensure one of your projects has merge requests.')) unless merge_request.present? # rubocop:disable Cop/BanCatchThrow return { error: s_('TestHooks|Ensure one of your projects has merge requests.') } unless merge_request.present?
merge_request.to_hook_data(current_user) merge_request.to_hook_data(current_user)
end end
......
...@@ -63,10 +63,6 @@ class GithubService < Service ...@@ -63,10 +63,6 @@ class GithubService < Service
project&.ci_pipelines&.any? project&.ci_pipelines&.any?
end end
def disabled_title
'Please set up a pipeline on your repository.'
end
def execute(data) def execute(data)
return if disabled? || invalid? || irrelevant_result?(data) return if disabled? || invalid? || irrelevant_result?(data)
...@@ -75,14 +71,6 @@ class GithubService < Service ...@@ -75,14 +71,6 @@ class GithubService < Service
update_status(status_message) update_status(status_message)
end end
def test_data(project, user)
pipeline = project.ci_pipelines.newest_first.first
raise disabled_title unless pipeline
Gitlab::DataBuilder::Pipeline.build(pipeline)
end
def test(data) def test(data)
begin begin
result = execute(data) result = execute(data)
......
# frozen_string_literal: true
module EE
module Integrations
module Test
module ProjectService
extend ::Gitlab::Utils::Override
include ::Gitlab::Utils::StrongMemoize
private
override :data
def data
strong_memoize(:data) do
next pipeline_events_data if integration.is_a?(::GithubService)
super
end
end
end
end
end
end
...@@ -7,13 +7,6 @@ FactoryBot.define do ...@@ -7,13 +7,6 @@ FactoryBot.define do
type { 'GitlabSlackApplicationService' } type { 'GitlabSlackApplicationService' }
end end
factory :github_service do
project
active { true }
token { 'github-token' }
type { 'GithubService' }
end
factory :slack_slash_commands_service do factory :slack_slash_commands_service do
project project
active { true } active { true }
......
...@@ -54,7 +54,6 @@ RSpec.describe 'User activates GitHub Service' do ...@@ -54,7 +54,6 @@ RSpec.describe 'User activates GitHub Service' do
) )
click_button 'Test settings and save changes' click_button 'Test settings and save changes'
wait_for_requests
expect(page).to have_content('GitHub activated.') expect(page).to have_content('GitHub activated.')
end end
......
...@@ -299,23 +299,6 @@ RSpec.describe GithubService do ...@@ -299,23 +299,6 @@ RSpec.describe GithubService do
end end
end end
describe '#test_data' do
let(:user) { project.owner }
let(:test_data) { subject.test_data(project, user) }
it 'raises error if no pipeline found' do
project.ci_pipelines.delete_all
expect { test_data }.to raise_error 'Please set up a pipeline on your repository.'
end
it 'generates data for latest pipeline' do
pipeline
expect(test_data[:object_kind]).to eq 'pipeline'
end
end
describe '#test' do describe '#test' do
it 'mentions creator in success message' do it 'mentions creator in success message' do
dummy_response = { context: "default", creator: { login: "YourUser" } } dummy_response = { context: "default", creator: { login: "YourUser" } }
......
# frozen_string_literal: true
require 'spec_helper'
describe ::Integrations::Test::ProjectService do
let(:user) { double('user') }
describe '#execute' do
let(:project) { create(:project) }
let(:event) { nil }
let(:sample_data) { { data: 'sample' } }
let(:success_result) { { success: true, result: {} } }
subject { described_class.new(integration, user, event).execute }
context 'without event specified' do
context 'GitHubService' do
let(:integration) { create(:github_service, project: project) }
it_behaves_like 'tests for integration with pipeline data'
end
end
end
end
...@@ -21665,7 +21665,7 @@ msgstr "" ...@@ -21665,7 +21665,7 @@ msgstr ""
msgid "TestHooks|Ensure the project has CI pipelines." msgid "TestHooks|Ensure the project has CI pipelines."
msgstr "" msgstr ""
msgid "TestHooks|Ensure the project has at least one commit." msgid "TestHooks|Ensure the project has deployments."
msgstr "" msgstr ""
msgid "TestHooks|Ensure the project has issues." msgid "TestHooks|Ensure the project has issues."
......
...@@ -165,6 +165,20 @@ FactoryBot.define do ...@@ -165,6 +165,20 @@ FactoryBot.define do
type { 'SlackService' } type { 'SlackService' }
end end
factory :github_service do
project
type { 'GithubService' }
active { true }
token { 'github-token' }
end
factory :pipelines_email_service do
project
active { true }
type { 'PipelinesEmailService' }
recipients { 'test@example.com' }
end
# this is for testing storing values inside properties, which is deprecated and will be removed in # this is for testing storing values inside properties, which is deprecated and will be removed in
# https://gitlab.com/gitlab-org/gitlab/issues/29404 # https://gitlab.com/gitlab-org/gitlab/issues/29404
trait :without_properties_callback do trait :without_properties_callback do
......
...@@ -37,22 +37,6 @@ describe PipelinesEmailService, :mailer do ...@@ -37,22 +37,6 @@ describe PipelinesEmailService, :mailer do
end end
end end
describe '#test_data' do
let(:build) { create(:ci_build) }
let(:project) { build.project }
let(:user) { create(:user) }
before do
project.add_developer(user)
end
it 'builds test data' do
data = subject.test_data(project, user)
expect(data[:object_kind]).to eq('pipeline')
end
end
shared_examples 'sending email' do |branches_to_be_notified: nil| shared_examples 'sending email' do |branches_to_be_notified: nil|
before do before do
subject.recipients = recipients subject.recipients = recipients
......
# frozen_string_literal: true
require 'spec_helper'
describe Integrations::Test::ProjectService do
let(:user) { double('user') }
describe '#execute' do
let(:project) { create(:project) }
let(:integration) { create(:slack_service, project: project) }
let(:event) { nil }
let(:sample_data) { { data: 'sample' } }
let(:success_result) { { success: true, result: {} } }
subject { described_class.new(integration, user, event).execute }
context 'without event specified' do
it 'tests the integration with default data' do
allow(Gitlab::DataBuilder::Push).to receive(:build_sample).and_return(sample_data)
expect(integration).to receive(:test).with(sample_data).and_return(success_result)
expect(subject).to eq(success_result)
end
context 'PipelinesEmailService' do
let(:integration) { create(:pipelines_email_service, project: project) }
it_behaves_like 'tests for integration with pipeline data'
end
end
context 'with event specified' do
context 'event not supported by integration' do
let(:integration) { create(:jira_service, project: project) }
let(:event) { 'push' }
it 'returns error message' do
expect(subject).to include({ status: :error, message: 'Testing not available for this event' })
end
end
context 'push' do
let(:event) { 'push' }
it 'executes integration' do
allow(Gitlab::DataBuilder::Push).to receive(:build_sample).and_return(sample_data)
expect(integration).to receive(:test).with(sample_data).and_return(success_result)
expect(subject).to eq(success_result)
end
end
context 'tag_push' do
let(:event) { 'tag_push' }
it 'executes integration' do
allow(Gitlab::DataBuilder::Push).to receive(:build_sample).and_return(sample_data)
expect(integration).to receive(:test).with(sample_data).and_return(success_result)
expect(subject).to eq(success_result)
end
end
context 'note' do
let(:event) { 'note' }
it 'returns error message if not enough data' do
expect(integration).not_to receive(:test)
expect(subject).to include({ status: :error, message: 'Ensure the project has notes.' })
end
it 'executes integration' do
allow(project).to receive(:notes).and_return([Note.new])
allow(Gitlab::DataBuilder::Note).to receive(:build).and_return(sample_data)
expect(integration).to receive(:test).with(sample_data).and_return(success_result)
expect(subject).to eq(success_result)
end
end
context 'issue' do
let(:event) { 'issue' }
let(:issue) { build(:issue) }
it 'returns error message if not enough data' do
expect(integration).not_to receive(:test)
expect(subject).to include({ status: :error, message: 'Ensure the project has issues.' })
end
it 'executes integration' do
allow(project).to receive(:issues).and_return([issue])
allow(issue).to receive(:to_hook_data).and_return(sample_data)
expect(integration).to receive(:test).with(sample_data).and_return(success_result)
expect(subject).to eq(success_result)
end
end
context 'confidential_issue' do
let(:event) { 'confidential_issue' }
let(:issue) { build(:issue) }
it 'returns error message if not enough data' do
expect(integration).not_to receive(:test)
expect(subject).to include({ status: :error, message: 'Ensure the project has issues.' })
end
it 'executes integration' do
allow(project).to receive(:issues).and_return([issue])
allow(issue).to receive(:to_hook_data).and_return(sample_data)
expect(integration).to receive(:test).with(sample_data).and_return(success_result)
expect(subject).to eq(success_result)
end
end
context 'merge_request' do
let(:event) { 'merge_request' }
it 'returns error message if not enough data' do
expect(integration).not_to receive(:test)
expect(subject).to include({ status: :error, message: 'Ensure the project has merge requests.' })
end
it 'executes integration' do
create(:merge_request, source_project: project)
allow_any_instance_of(MergeRequest).to receive(:to_hook_data).and_return(sample_data)
expect(integration).to receive(:test).with(sample_data).and_return(success_result)
expect(subject).to eq(success_result)
end
end
context 'deployment' do
let(:project) { create(:project, :test_repo) }
let(:event) { 'deployment' }
it 'returns error message if not enough data' do
expect(integration).not_to receive(:test)
expect(subject).to include({ status: :error, message: 'Ensure the project has deployments.' })
end
it 'executes integration' do
create(:deployment, project: project)
allow(Gitlab::DataBuilder::Deployment).to receive(:build).and_return(sample_data)
expect(integration).to receive(:test).with(sample_data).and_return(success_result)
expect(subject).to eq(success_result)
end
end
context 'pipeline' do
let(:event) { 'pipeline' }
it 'returns error message if not enough data' do
expect(integration).not_to receive(:test)
expect(subject).to include({ status: :error, message: 'Ensure the project has CI pipelines.' })
end
it 'executes integration' do
create(:ci_empty_pipeline, project: project)
allow(Gitlab::DataBuilder::Pipeline).to receive(:build).and_return(sample_data)
expect(integration).to receive(:test).with(sample_data).and_return(success_result)
expect(subject).to eq(success_result)
end
end
context 'wiki_page' do
let(:project) { create(:project, :wiki_repo) }
let(:event) { 'wiki_page' }
it 'returns error message if wiki disabled' do
allow(project).to receive(:wiki_enabled?).and_return(false)
expect(integration).not_to receive(:test)
expect(subject).to include({ status: :error, message: 'Ensure the wiki is enabled and has pages.' })
end
it 'returns error message if not enough data' do
expect(integration).not_to receive(:test)
expect(subject).to include({ status: :error, message: 'Ensure the wiki is enabled and has pages.' })
end
it 'executes integration' do
create(:wiki_page, wiki: project.wiki)
allow(Gitlab::DataBuilder::WikiPage).to receive(:build).and_return(sample_data)
expect(integration).to receive(:test).with(sample_data).and_return(success_result)
expect(subject).to eq(success_result)
end
end
end
end
end
...@@ -31,15 +31,7 @@ describe TestHooks::ProjectService do ...@@ -31,15 +31,7 @@ describe TestHooks::ProjectService do
let(:trigger) { 'push_events' } let(:trigger) { 'push_events' }
let(:trigger_key) { :push_hooks } let(:trigger_key) { :push_hooks }
it 'returns error message if not enough data' do
allow(project).to receive(:empty_repo?).and_return(true)
expect(hook).not_to receive(:execute)
expect(service.execute).to include({ status: :error, message: 'Ensure the project has at least one commit.' })
end
it 'executes hook' do it 'executes hook' do
allow(project).to receive(:empty_repo?).and_return(false)
allow(Gitlab::DataBuilder::Push).to receive(:build_sample).and_return(sample_data) allow(Gitlab::DataBuilder::Push).to receive(:build_sample).and_return(sample_data)
expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result) expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result)
...@@ -51,15 +43,7 @@ describe TestHooks::ProjectService do ...@@ -51,15 +43,7 @@ describe TestHooks::ProjectService do
let(:trigger) { 'tag_push_events' } let(:trigger) { 'tag_push_events' }
let(:trigger_key) { :tag_push_hooks } let(:trigger_key) { :tag_push_hooks }
it 'returns error message if not enough data' do
allow(project).to receive(:empty_repo?).and_return(true)
expect(hook).not_to receive(:execute)
expect(service.execute).to include({ status: :error, message: 'Ensure the project has at least one commit.' })
end
it 'executes hook' do it 'executes hook' do
allow(project).to receive(:empty_repo?).and_return(false)
allow(Gitlab::DataBuilder::Push).to receive(:build_sample).and_return(sample_data) allow(Gitlab::DataBuilder::Push).to receive(:build_sample).and_return(sample_data)
expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result) expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result)
......
...@@ -29,7 +29,6 @@ describe TestHooks::SystemService do ...@@ -29,7 +29,6 @@ describe TestHooks::SystemService do
let(:trigger_key) { :push_hooks } let(:trigger_key) { :push_hooks }
it 'executes hook' do it 'executes hook' do
allow(project).to receive(:empty_repo?).and_return(false)
expect(Gitlab::DataBuilder::Push).to receive(:sample_data).and_call_original expect(Gitlab::DataBuilder::Push).to receive(:sample_data).and_call_original
expect(hook).to receive(:execute).with(Gitlab::DataBuilder::Push::SAMPLE_DATA, trigger_key).and_return(success_result) expect(hook).to receive(:execute).with(Gitlab::DataBuilder::Push::SAMPLE_DATA, trigger_key).and_return(success_result)
...@@ -55,7 +54,6 @@ describe TestHooks::SystemService do ...@@ -55,7 +54,6 @@ describe TestHooks::SystemService do
let(:trigger_key) { :repository_update_hooks } let(:trigger_key) { :repository_update_hooks }
it 'executes hook' do it 'executes hook' do
allow(project).to receive(:empty_repo?).and_return(false)
expect(Gitlab::DataBuilder::Repository).to receive(:sample_data).and_call_original expect(Gitlab::DataBuilder::Repository).to receive(:sample_data).and_call_original
expect(hook).to receive(:execute).with(Gitlab::DataBuilder::Repository::SAMPLE_DATA, trigger_key).and_return(success_result) expect(hook).to receive(:execute).with(Gitlab::DataBuilder::Repository::SAMPLE_DATA, trigger_key).and_return(success_result)
......
# frozen_string_literal: true
RSpec.shared_examples 'tests for integration with pipeline data' do
it 'tests the integration with pipeline data' do
create(:ci_empty_pipeline, project: project)
allow(Gitlab::DataBuilder::Pipeline).to receive(:build).and_return(sample_data)
expect(integration).to receive(:test).with(sample_data).and_return(success_result)
expect(subject).to eq(success_result)
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