Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-07-20 18:40:28 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-07-20 18:40:28 +0300
commitb595cb0c1dec83de5bdee18284abe86614bed33b (patch)
tree8c3d4540f193c5ff98019352f554e921b3a41a72 /spec/models/integrations
parent2f9104a328fc8a4bddeaa4627b595166d24671d0 (diff)
Add latest changes from gitlab-org/gitlab@15-2-stable-eev15.2.0-rc42
Diffstat (limited to 'spec/models/integrations')
-rw-r--r--spec/models/integrations/base_chat_notification_spec.rb18
-rw-r--r--spec/models/integrations/chat_message/deployment_message_spec.rb2
-rw-r--r--spec/models/integrations/datadog_spec.rb16
-rw-r--r--spec/models/integrations/field_spec.rb73
-rw-r--r--spec/models/integrations/harbor_spec.rb8
-rw-r--r--spec/models/integrations/irker_spec.rb14
-rw-r--r--spec/models/integrations/jira_spec.rb2
-rw-r--r--spec/models/integrations/prometheus_spec.rb43
-rw-r--r--spec/models/integrations/slack_spec.rb2
-rw-r--r--spec/models/integrations/youtrack_spec.rb6
10 files changed, 120 insertions, 64 deletions
diff --git a/spec/models/integrations/base_chat_notification_spec.rb b/spec/models/integrations/base_chat_notification_spec.rb
index 672d8de1e14..eb503e501d6 100644
--- a/spec/models/integrations/base_chat_notification_spec.rb
+++ b/spec/models/integrations/base_chat_notification_spec.rb
@@ -285,4 +285,22 @@ RSpec.describe Integrations::BaseChatNotification do
expect { subject.webhook_placeholder }.to raise_error(NotImplementedError)
end
end
+
+ describe '#event_channel_name' do
+ it 'returns the channel field name for the given event' do
+ expect(subject.event_channel_name(:event)).to eq('event_channel')
+ end
+ end
+
+ describe '#event_channel_value' do
+ it 'returns the channel field value for the given event' do
+ subject.push_channel = '#pushes'
+
+ expect(subject.event_channel_value(:push)).to eq('#pushes')
+ end
+
+ it 'raises an error for unsupported events' do
+ expect { subject.event_channel_value(:foo) }.to raise_error(NoMethodError)
+ end
+ end
end
diff --git a/spec/models/integrations/chat_message/deployment_message_spec.rb b/spec/models/integrations/chat_message/deployment_message_spec.rb
index 6bcd29c0a00..8da27ef5aa0 100644
--- a/spec/models/integrations/chat_message/deployment_message_spec.rb
+++ b/spec/models/integrations/chat_message/deployment_message_spec.rb
@@ -14,7 +14,7 @@ RSpec.describe Integrations::ChatMessage::DeploymentMessage do
let_it_be(:deployment) { create(:deployment, status: :success, deployable: ci_build, environment: environment, project: project, user: user, sha: commit.sha) }
let(:args) do
- Gitlab::DataBuilder::Deployment.build(deployment, Time.current)
+ Gitlab::DataBuilder::Deployment.build(deployment, 'success', Time.current)
end
it_behaves_like Integrations::ChatMessage
diff --git a/spec/models/integrations/datadog_spec.rb b/spec/models/integrations/datadog_spec.rb
index cfc44b22a84..47f916e8457 100644
--- a/spec/models/integrations/datadog_spec.rb
+++ b/spec/models/integrations/datadog_spec.rb
@@ -240,4 +240,20 @@ RSpec.describe Integrations::Datadog do
end
end
end
+
+ describe '#fields' do
+ it 'includes the archive_trace_events field' do
+ expect(instance.fields).to include(have_attributes(name: 'archive_trace_events'))
+ end
+
+ context 'when the FF :datadog_integration_logs_collection is disabled' do
+ before do
+ stub_feature_flags(datadog_integration_logs_collection: false)
+ end
+
+ it 'does not include the archive_trace_events field' do
+ expect(instance.fields).not_to include(have_attributes(name: 'archive_trace_events'))
+ end
+ end
+ end
end
diff --git a/spec/models/integrations/field_spec.rb b/spec/models/integrations/field_spec.rb
index 6b1ce7fcbde..642fb1fbf7f 100644
--- a/spec/models/integrations/field_spec.rb
+++ b/spec/models/integrations/field_spec.rb
@@ -14,6 +14,37 @@ RSpec.describe ::Integrations::Field do
end
end
+ describe '#initialize' do
+ it 'sets type password for secret names' do
+ attrs[:name] = 'token'
+ attrs[:type] = 'text'
+
+ expect(field[:type]).to eq('password')
+ end
+
+ it 'uses the given type for other names' do
+ attrs[:name] = 'field'
+ attrs[:type] = 'select'
+
+ expect(field[:type]).to eq('select')
+ end
+
+ it 'raises an error if an invalid attribute is given' do
+ attrs[:foo] = 'foo'
+ attrs[:bar] = 'bar'
+ attrs[:name] = 'name'
+ attrs[:type] = 'text'
+
+ expect { field }.to raise_error(ArgumentError, "Invalid attributes [:foo, :bar]")
+ end
+
+ it 'raises an error if an invalid type is given' do
+ attrs[:type] = 'other'
+
+ expect { field }.to raise_error(ArgumentError, 'Invalid type "other"')
+ end
+ end
+
describe '#name' do
before do
attrs[:name] = :foo
@@ -59,7 +90,7 @@ RSpec.describe ::Integrations::Field do
it 'has the correct default' do
expect(field[name]).to have_correct_default
- expect(field.send(name)).to have_correct_default
+ expect(field.public_send(name)).to have_correct_default
end
end
@@ -69,32 +100,66 @@ RSpec.describe ::Integrations::Field do
end
it 'is known' do
+ next if name == :type
+
expect(field[name]).to eq(:known)
- expect(field.send(name)).to eq(:known)
+ expect(field.public_send(name)).to eq(:known)
end
end
context 'when set to a dynamic value' do
it 'is computed' do
+ next if name == :type
+
attrs[name] = -> { Time.current }
start = Time.current
travel_to(start + 1.minute) do
expect(field[name]).to be_after(start)
- expect(field.send(name)).to be_after(start)
+ expect(field.public_send(name)).to be_after(start)
end
end
it 'is executed in the class scope' do
+ next if name == :type
+
attrs[name] = -> { default_placeholder }
expect(field[name]).to eq('my placeholder')
- expect(field.send(name)).to eq('my placeholder')
+ expect(field.public_send(name)).to eq('my placeholder')
end
end
end
end
+ described_class::BOOLEAN_ATTRIBUTES.each do |name|
+ describe "##{name}?" do
+ it 'returns true if the value is truthy' do
+ attrs[name] = ''
+ expect(field.public_send("#{name}?")).to be(true)
+ end
+
+ it 'returns false if the value is falsey' do
+ attrs[name] = nil
+ expect(field.public_send("#{name}?")).to be(false)
+ end
+ end
+ end
+
+ described_class::TYPES.each do |type|
+ describe "##{type}?" do
+ it 'returns true if the type matches' do
+ attrs[:type] = type
+ expect(field.public_send("#{type}?")).to be(true)
+ end
+
+ it 'returns false if the type does not match' do
+ attrs[:type] = (described_class::TYPES - [type]).first
+ expect(field.public_send("#{type}?")).to be(false)
+ end
+ end
+ end
+
describe '#secret?' do
context 'when empty' do
it { is_expected.not_to be_secret }
diff --git a/spec/models/integrations/harbor_spec.rb b/spec/models/integrations/harbor_spec.rb
index 9e3d4b524a6..5d8597969a1 100644
--- a/spec/models/integrations/harbor_spec.rb
+++ b/spec/models/integrations/harbor_spec.rb
@@ -19,6 +19,14 @@ RSpec.describe Integrations::Harbor do
it { is_expected.to allow_value('helloworld').for(:password) }
end
+ describe 'url' do
+ subject { build(:harbor_integration) }
+
+ it { is_expected.not_to allow_value('https://192.168.1.1').for(:url) }
+ it { is_expected.not_to allow_value('https://127.0.0.1').for(:url) }
+ it { is_expected.to allow_value('https://demo.goharbor.io').for(:url)}
+ end
+
describe '#fields' do
it 'returns custom fields' do
expect(harbor_integration.fields.pluck(:name)).to eq(%w[url project_name username password])
diff --git a/spec/models/integrations/irker_spec.rb b/spec/models/integrations/irker_spec.rb
index 16487aa36e7..e98b8b54e03 100644
--- a/spec/models/integrations/irker_spec.rb
+++ b/spec/models/integrations/irker_spec.rb
@@ -76,19 +76,5 @@ RSpec.describe Integrations::Irker do
ensure
conn.close if conn
end
-
- context 'when the FF :rename_integrations_workers is disabled' do
- before do
- stub_feature_flags(rename_integrations_workers: false)
- end
-
- it 'queues a IrkerWorker' do
- expect(::IrkerWorker).to receive(:perform_async)
- .with(project.id, irker.channels, colorize_messages, sample_data, irker.settings)
- expect(Integrations::IrkerWorker).not_to receive(:perform_async)
-
- irker.execute(sample_data)
- end
- end
end
end
diff --git a/spec/models/integrations/jira_spec.rb b/spec/models/integrations/jira_spec.rb
index 28d97b74adb..2a994540bd3 100644
--- a/spec/models/integrations/jira_spec.rb
+++ b/spec/models/integrations/jira_spec.rb
@@ -164,7 +164,7 @@ RSpec.describe Integrations::Jira do
subject(:fields) { integration.fields }
it 'returns custom fields' do
- expect(fields.pluck(:name)).to eq(%w[url api_url username password])
+ expect(fields.pluck(:name)).to eq(%w[url api_url username password jira_issue_transition_id])
end
end
diff --git a/spec/models/integrations/prometheus_spec.rb b/spec/models/integrations/prometheus_spec.rb
index fbeaebfd807..ae965ed78d1 100644
--- a/spec/models/integrations/prometheus_spec.rb
+++ b/spec/models/integrations/prometheus_spec.rb
@@ -475,47 +475,4 @@ RSpec.describe Integrations::Prometheus, :use_clean_rails_memory_store_caching,
end
end
end
-
- describe '#fields' do
- let(:expected_fields) do
- [
- {
- type: 'checkbox',
- name: 'manual_configuration',
- title: s_('PrometheusService|Active'),
- help: s_('PrometheusService|Select this checkbox to override the auto configuration settings with your own settings.'),
- required: true
- },
- {
- type: 'text',
- name: 'api_url',
- title: 'API URL',
- placeholder: s_('PrometheusService|https://prometheus.example.com/'),
- help: s_('PrometheusService|The Prometheus API base URL.'),
- required: true
- },
- {
- type: 'text',
- name: 'google_iap_audience_client_id',
- title: 'Google IAP Audience Client ID',
- placeholder: s_('PrometheusService|IAP_CLIENT_ID.apps.googleusercontent.com'),
- help: s_('PrometheusService|The ID of the IAP-secured resource.'),
- autocomplete: 'off',
- required: false
- },
- {
- type: 'textarea',
- name: 'google_iap_service_account_json',
- title: 'Google IAP Service Account JSON',
- placeholder: s_('PrometheusService|{ "type": "service_account", "project_id": ... }'),
- help: s_('PrometheusService|The contents of the credentials.json file of your service account.'),
- required: false
- }
- ]
- end
-
- it 'returns fields' do
- expect(integration.fields).to eq(expected_fields)
- end
- end
end
diff --git a/spec/models/integrations/slack_spec.rb b/spec/models/integrations/slack_spec.rb
index 3997d69f947..5801a4c3749 100644
--- a/spec/models/integrations/slack_spec.rb
+++ b/spec/models/integrations/slack_spec.rb
@@ -59,7 +59,7 @@ RSpec.describe Integrations::Slack do
context 'deployment notification' do
let_it_be(:deployment) { create(:deployment, user: user) }
- let(:data) { Gitlab::DataBuilder::Deployment.build(deployment, Time.current) }
+ let(:data) { Gitlab::DataBuilder::Deployment.build(deployment, deployment.status, Time.current) }
it_behaves_like 'increases the usage data counter', 'i_ecosystem_slack_service_deployment_notification'
end
diff --git a/spec/models/integrations/youtrack_spec.rb b/spec/models/integrations/youtrack_spec.rb
index f6a9dd8ef37..618ebcbb76a 100644
--- a/spec/models/integrations/youtrack_spec.rb
+++ b/spec/models/integrations/youtrack_spec.rb
@@ -37,4 +37,10 @@ RSpec.describe Integrations::Youtrack do
expect(described_class.reference_pattern.match('yt-123')[:issue]).to eq('yt-123')
end
end
+
+ describe '#fields' do
+ it 'only returns the project_url and issues_url fields' do
+ expect(subject.fields.pluck(:name)).to eq(%w[project_url issues_url])
+ end
+ end
end