diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 09:08:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 09:08:42 +0000 |
commit | b76ae638462ab0f673e5915986070518dd3f9ad3 (patch) | |
tree | bdab0533383b52873be0ec0eb4d3c66598ff8b91 /spec/models/integrations | |
parent | 434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff) | |
download | gitlab-ce-b76ae638462ab0f673e5915986070518dd3f9ad3.tar.gz |
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'spec/models/integrations')
-rw-r--r-- | spec/models/integrations/bamboo_spec.rb | 15 | ||||
-rw-r--r-- | spec/models/integrations/datadog_spec.rb | 49 | ||||
-rw-r--r-- | spec/models/integrations/jenkins_spec.rb | 16 | ||||
-rw-r--r-- | spec/models/integrations/jira_spec.rb | 62 | ||||
-rw-r--r-- | spec/models/integrations/teamcity_spec.rb | 14 |
5 files changed, 84 insertions, 72 deletions
diff --git a/spec/models/integrations/bamboo_spec.rb b/spec/models/integrations/bamboo_spec.rb index 73ebf404828..60ff6685c3d 100644 --- a/spec/models/integrations/bamboo_spec.rb +++ b/spec/models/integrations/bamboo_spec.rb @@ -12,6 +12,7 @@ RSpec.describe Integrations::Bamboo, :use_clean_rails_memory_store_caching do subject(:integration) do described_class.create!( + active: true, project: project, properties: { bamboo_url: bamboo_url, @@ -74,27 +75,27 @@ RSpec.describe Integrations::Bamboo, :use_clean_rails_memory_store_caching do end describe 'Callbacks' do - describe 'before_update :reset_password' do + describe 'before_validation :reset_password' do context 'when a password was previously set' do it 'resets password if url changed' do integration.bamboo_url = 'http://gitlab1.com' - integration.save! + expect(integration).not_to be_valid expect(integration.password).to be_nil end it 'does not reset password if username changed' do integration.username = 'some_name' - integration.save! + expect(integration).to be_valid expect(integration.password).to eq('password') end it "does not reset password if new url is set together with password, even if it's the same password" do integration.bamboo_url = 'http://gitlab_edited.com' integration.password = 'password' - integration.save! + expect(integration).to be_valid expect(integration.password).to eq('password') expect(integration.bamboo_url).to eq('http://gitlab_edited.com') end @@ -107,8 +108,10 @@ RSpec.describe Integrations::Bamboo, :use_clean_rails_memory_store_caching do integration.password = 'password' integration.save! - expect(integration.password).to eq('password') - expect(integration.bamboo_url).to eq('http://gitlab_edited.com') + expect(integration.reload).to have_attributes( + bamboo_url: 'http://gitlab_edited.com', + password: 'password' + ) end end end diff --git a/spec/models/integrations/datadog_spec.rb b/spec/models/integrations/datadog_spec.rb index e2749ab1bc1..677bd4c5e48 100644 --- a/spec/models/integrations/datadog_spec.rb +++ b/spec/models/integrations/datadog_spec.rb @@ -6,7 +6,8 @@ require 'spec_helper' RSpec.describe Integrations::Datadog do let_it_be(:project) { create(:project) } let_it_be(:pipeline) { create(:ci_pipeline, project: project) } - let_it_be(:build) { create(:ci_build, project: project) } + let_it_be(:build) { create(:ci_build, pipeline: pipeline) } + let_it_be(:retried_build) { create(:ci_build, :retried, pipeline: pipeline) } let(:active) { true } let(:dd_site) { 'datadoghq.com' } @@ -139,26 +140,38 @@ RSpec.describe Integrations::Datadog do end describe '#test' do - context 'when request is succesful' do - subject { saved_instance.test(pipeline_data) } + subject(:result) { saved_instance.test(pipeline_data) } - before do - stub_request(:post, expected_hook_url).to_return(body: 'OK') - end + let(:body) { 'OK' } + let(:status) { 200 } + + before do + stub_request(:post, expected_hook_url).to_return(body: body, status: status) + end + + context 'when request is successful with a HTTP 200 status' do it { is_expected.to eq({ success: true, result: 'OK' }) } end - context 'when request fails' do - subject { saved_instance.test(pipeline_data) } + context 'when request is successful with a HTTP 202 status' do + let(:status) { 202 } + + it { is_expected.to eq({ success: true, result: 'OK' }) } + end + + context 'when request fails with a HTTP 500 status' do + let(:status) { 500 } + let(:body) { 'CRASH!!!' } - before do - stub_request(:post, expected_hook_url).to_return(body: 'CRASH!!!', status: 500) - end it { is_expected.to eq({ success: false, result: 'CRASH!!!' }) } end end describe '#execute' do + around do |example| + freeze_time { example.run } + end + before do stub_request(:post, expected_hook_url) saved_instance.execute(data) @@ -166,20 +179,18 @@ RSpec.describe Integrations::Datadog do context 'with pipeline data' do let(:data) { pipeline_data } - let(:expected_headers) do - { WebHookService::GITLAB_EVENT_HEADER => 'Pipeline Hook' } - end + let(:expected_headers) { { WebHookService::GITLAB_EVENT_HEADER => 'Pipeline Hook' } } + let(:expected_body) { data.with_retried_builds.to_json } - it { expect(a_request(:post, expected_hook_url).with(headers: expected_headers)).to have_been_made } + it { expect(a_request(:post, expected_hook_url).with(headers: expected_headers, body: expected_body)).to have_been_made } end context 'with job data' do let(:data) { build_data } - let(:expected_headers) do - { WebHookService::GITLAB_EVENT_HEADER => 'Job Hook' } - end + let(:expected_headers) { { WebHookService::GITLAB_EVENT_HEADER => 'Job Hook' } } + let(:expected_body) { data.to_json } - it { expect(a_request(:post, expected_hook_url).with(headers: expected_headers)).to have_been_made } + it { expect(a_request(:post, expected_hook_url).with(headers: expected_headers, body: expected_body)).to have_been_made } end end end diff --git a/spec/models/integrations/jenkins_spec.rb b/spec/models/integrations/jenkins_spec.rb index 9eb2a7fc098..9286d026290 100644 --- a/spec/models/integrations/jenkins_spec.rb +++ b/spec/models/integrations/jenkins_spec.rb @@ -200,21 +200,21 @@ RSpec.describe Integrations::Jenkins do it 'resets password if url changed' do jenkins_integration.jenkins_url = 'http://jenkins-edited.example.com/' - jenkins_integration.save! + jenkins_integration.valid? expect(jenkins_integration.password).to be_nil end it 'resets password if username is blank' do jenkins_integration.username = '' - jenkins_integration.save! + jenkins_integration.valid? expect(jenkins_integration.password).to be_nil end it 'does not reset password if username changed' do jenkins_integration.username = 'some_name' - jenkins_integration.save! + jenkins_integration.valid? expect(jenkins_integration.password).to eq('password') end @@ -222,7 +222,7 @@ RSpec.describe Integrations::Jenkins do it 'does not reset password if new url is set together with password, even if it\'s the same password' do jenkins_integration.jenkins_url = 'http://jenkins_edited.example.com/' jenkins_integration.password = 'password' - jenkins_integration.save! + jenkins_integration.valid? expect(jenkins_integration.password).to eq('password') expect(jenkins_integration.jenkins_url).to eq('http://jenkins_edited.example.com/') @@ -231,7 +231,7 @@ RSpec.describe Integrations::Jenkins do it 'resets password if url changed, even if setter called multiple times' do jenkins_integration.jenkins_url = 'http://jenkins1.example.com/' jenkins_integration.jenkins_url = 'http://jenkins1.example.com/' - jenkins_integration.save! + jenkins_integration.valid? expect(jenkins_integration.password).to be_nil end @@ -253,8 +253,10 @@ RSpec.describe Integrations::Jenkins do jenkins_integration.password = 'password' jenkins_integration.save! - expect(jenkins_integration.password).to eq('password') - expect(jenkins_integration.jenkins_url).to eq('http://jenkins_edited.example.com/') + expect(jenkins_integration.reload).to have_attributes( + jenkins_url: 'http://jenkins_edited.example.com/', + password: 'password' + ) end end end diff --git a/spec/models/integrations/jira_spec.rb b/spec/models/integrations/jira_spec.rb index 6ca72d68bbb..0321b151633 100644 --- a/spec/models/integrations/jira_spec.rb +++ b/spec/models/integrations/jira_spec.rb @@ -280,7 +280,7 @@ RSpec.describe Integrations::Jira do expect(integration.jira_tracker_data.deployment_server?).to be_truthy - integration.update!(api_url: 'http://another.url') + integration.update!(api_url: 'http://another.url', password: password) integration.jira_tracker_data.reload expect(integration.jira_tracker_data.deployment_cloud?).to be_truthy @@ -301,13 +301,13 @@ RSpec.describe Integrations::Jira do end it 'calls serverInfo for url' do - integration.update!(url: 'http://first.url') + integration.update!(url: 'http://first.url', password: password) expect(WebMock).to have_requested(:get, /serverInfo/) end it 'calls serverInfo for api_url' do - integration.update!(api_url: 'http://another.url') + integration.update!(api_url: 'http://another.url', password: password) expect(WebMock).to have_requested(:get, /serverInfo/) end @@ -334,16 +334,6 @@ RSpec.describe Integrations::Jira do end end - context 'when not allowed to test an instance or group' do - it 'does not update deployment type' do - allow(integration).to receive(:testable?).and_return(false) - - integration.update!(url: 'http://first.url') - - expect(WebMock).not_to have_requested(:get, /serverInfo/) - end - end - context 'stored password invalidation' do context 'when a password was previously set' do context 'when only web url present' do @@ -358,33 +348,33 @@ RSpec.describe Integrations::Jira do it 'resets password if url changed' do integration integration.url = 'http://jira_edited.example.com' - integration.save! - expect(integration.reload.url).to eq('http://jira_edited.example.com') + expect(integration).not_to be_valid + expect(integration.url).to eq('http://jira_edited.example.com') expect(integration.password).to be_nil end it 'does not reset password if url "changed" to the same url as before' do integration.url = 'http://jira.example.com' - integration.save! - expect(integration.reload.url).to eq('http://jira.example.com') + expect(integration).to be_valid + expect(integration.url).to eq('http://jira.example.com') expect(integration.password).not_to be_nil end it 'resets password if url not changed but api url added' do integration.api_url = 'http://jira_edited.example.com/rest/api/2' - integration.save! - expect(integration.reload.api_url).to eq('http://jira_edited.example.com/rest/api/2') + expect(integration).not_to be_valid + expect(integration.api_url).to eq('http://jira_edited.example.com/rest/api/2') expect(integration.password).to be_nil end it 'does not reset password if new url is set together with password, even if it\'s the same password' do integration.url = 'http://jira_edited.example.com' integration.password = password - integration.save! + expect(integration).to be_valid expect(integration.password).to eq(password) expect(integration.url).to eq('http://jira_edited.example.com') end @@ -392,32 +382,32 @@ RSpec.describe Integrations::Jira do it 'resets password if url changed, even if setter called multiple times' do integration.url = 'http://jira1.example.com/rest/api/2' integration.url = 'http://jira1.example.com/rest/api/2' - integration.save! + expect(integration).not_to be_valid expect(integration.password).to be_nil end it 'does not reset password if username changed' do integration.username = 'some_name' - integration.save! - expect(integration.reload.password).to eq(password) + expect(integration).to be_valid + expect(integration.password).to eq(password) end it 'does not reset password if password changed' do integration.url = 'http://jira_edited.example.com' integration.password = 'new_password' - integration.save! - expect(integration.reload.password).to eq('new_password') + expect(integration).to be_valid + expect(integration.password).to eq('new_password') end it 'does not reset password if the password is touched and same as before' do integration.url = 'http://jira_edited.example.com' integration.password = password - integration.save! - expect(integration.reload.password).to eq(password) + expect(integration).to be_valid + expect(integration.password).to eq(password) end end @@ -432,22 +422,23 @@ RSpec.describe Integrations::Jira do it 'resets password if api url changed' do integration.api_url = 'http://jira_edited.example.com/rest/api/2' - integration.save! + expect(integration).not_to be_valid expect(integration.password).to be_nil end it 'does not reset password if url changed' do integration.url = 'http://jira_edited.example.com' - integration.save! + expect(integration).to be_valid expect(integration.password).to eq(password) end it 'resets password if api url set to empty' do - integration.update!(api_url: '') + integration.api_url = '' - expect(integration.reload.password).to be_nil + expect(integration).not_to be_valid + expect(integration.password).to be_nil end end end @@ -463,8 +454,11 @@ RSpec.describe Integrations::Jira do integration.url = 'http://jira_edited.example.com/rest/api/2' integration.password = 'password' integration.save! - expect(integration.reload.password).to eq('password') - expect(integration.reload.url).to eq('http://jira_edited.example.com/rest/api/2') + + expect(integration.reload).to have_attributes( + url: 'http://jira_edited.example.com/rest/api/2', + password: 'password' + ) end end end @@ -492,7 +486,7 @@ RSpec.describe Integrations::Jira do context 'when data are stored in both properties and separated fields' do let(:properties) { data_params } let(:integration) do - create(:jira_integration, :without_properties_callback, active: false, properties: properties).tap do |integration| + create(:jira_integration, :without_properties_callback, properties: properties).tap do |integration| create(:jira_tracker_data, data_params.merge(integration: integration)) end end diff --git a/spec/models/integrations/teamcity_spec.rb b/spec/models/integrations/teamcity_spec.rb index d425357aef0..0713141ea08 100644 --- a/spec/models/integrations/teamcity_spec.rb +++ b/spec/models/integrations/teamcity_spec.rb @@ -76,18 +76,18 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do describe 'Callbacks' do let(:teamcity_integration) { integration } - describe 'before_update :reset_password' do + describe 'before_validation :reset_password' do context 'when a password was previously set' do it 'resets password if url changed' do teamcity_integration.teamcity_url = 'http://gitlab1.com' - teamcity_integration.save! + teamcity_integration.valid? expect(teamcity_integration.password).to be_nil end it 'does not reset password if username changed' do teamcity_integration.username = 'some_name' - teamcity_integration.save! + teamcity_integration.valid? expect(teamcity_integration.password).to eq('password') end @@ -95,7 +95,7 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do it "does not reset password if new url is set together with password, even if it's the same password" do teamcity_integration.teamcity_url = 'http://gitlab_edited.com' teamcity_integration.password = 'password' - teamcity_integration.save! + teamcity_integration.valid? expect(teamcity_integration.password).to eq('password') expect(teamcity_integration.teamcity_url).to eq('http://gitlab_edited.com') @@ -109,8 +109,10 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do teamcity_integration.password = 'password' teamcity_integration.save! - expect(teamcity_integration.password).to eq('password') - expect(teamcity_integration.teamcity_url).to eq('http://gitlab_edited.com') + expect(teamcity_integration.reload).to have_attributes( + teamcity_url: 'http://gitlab_edited.com', + password: 'password' + ) end end end |