Skip to content
Snippets Groups Projects
Commit 32fd4cd5 authored by GitLab Bot's avatar GitLab Bot
Browse files

Add latest changes from gitlab-org/gitlab@master

parent 951616a2
No related branches found
No related tags found
No related merge requests found
# frozen_string_literal: true
require 'fast_spec_helper'
require 'rspec-parameterized'
describe Gitlab::Tracing do
using RSpec::Parameterized::TableSyntax
describe '.enabled?' do
where(:connection_string, :enabled_state) do
nil | false
"" | false
"opentracing://jaeger" | true
end
with_them do
it 'returns the correct state for .enabled?' do
expect(described_class).to receive(:connection_string).and_return(connection_string)
expect(described_class.enabled?).to eq(enabled_state)
end
end
end
describe '.tracing_url_enabled?' do
where(:enabled?, :tracing_url_template, :tracing_url_enabled_state) do
false | nil | false
false | "" | false
false | "http://localhost" | false
true | nil | false
true | "" | false
true | "http://localhost" | true
end
with_them do
it 'returns the correct state for .tracing_url_enabled?' do
expect(described_class).to receive(:enabled?).and_return(enabled?)
allow(described_class).to receive(:tracing_url_template).and_return(tracing_url_template)
expect(described_class.tracing_url_enabled?).to eq(tracing_url_enabled_state)
end
end
end
describe '.tracing_url' do
where(:tracing_url_enabled?, :tracing_url_template, :correlation_id, :process_name, :tracing_url) do
false | "https://localhost" | "123" | "web" | nil
true | "https://localhost" | "123" | "web" | "https://localhost"
true | "https://localhost?service={{ service }}" | "123" | "web" | "https://localhost?service=web"
true | "https://localhost?c={{ correlation_id }}" | "123" | "web" | "https://localhost?c=123"
true | "https://localhost?c={{ correlation_id }}&s={{ service }}" | "123" | "web" | "https://localhost?c=123&s=web"
true | "https://localhost?c={{ correlation_id }}" | nil | "web" | "https://localhost?c="
true | "https://localhost?c={{ correlation_id }}&s=%22{{ service }}%22" | "123" | "web" | "https://localhost?c=123&s=%22web%22"
true | "https://localhost?c={{correlation_id}}&s={{service}}" | "123" | "web" | "https://localhost?c=123&s=web"
true | "https://localhost?c={{correlation_id }}&s={{ service}}" | "123" | "web" | "https://localhost?c=123&s=web"
end
with_them do
it 'returns the correct state for .tracing_url' do
expect(described_class).to receive(:tracing_url_enabled?).and_return(tracing_url_enabled?)
allow(described_class).to receive(:tracing_url_template).and_return(tracing_url_template)
allow(Labkit::Correlation::CorrelationId).to receive(:current_id).and_return(correlation_id)
allow(Gitlab).to receive(:process_name).and_return(process_name)
expect(described_class.tracing_url).to eq(tracing_url)
end
end
end
end
Loading
Loading
@@ -2509,6 +2509,64 @@ describe Ci::Build do
end
end
 
describe 'CHANGED_PAGES variables' do
let(:route_map_yaml) do
<<~ROUTEMAP
- source: 'bar/branch-test.txt'
public: '/bar/branches'
ROUTEMAP
end
before do
allow_any_instance_of(Project)
.to receive(:route_map_for).with(/.+/)
.and_return(Gitlab::RouteMap.new(route_map_yaml))
end
context 'with a deployment environment and a merge request' do
let(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
let(:environment) { create(:environment, project: merge_request.project, name: "foo-#{project.default_branch}") }
let(:build) { create(:ci_build, pipeline: pipeline, environment: environment.name) }
it 'populates CI_MERGE_REQUEST_CHANGED_PAGES_* variables' do
expect(subject).to include(
{ key: 'CI_MERGE_REQUEST_CHANGED_PAGE_PATHS', value: '/bar/branches', public: true, masked: false },
{ key: 'CI_MERGE_REQUEST_CHANGED_PAGE_URLS', value: File.join(environment.external_url, '/bar/branches'), public: true, masked: false }
)
end
context 'with a deployment environment and no merge request' do
let(:environment) { create(:environment, project: project, name: "foo-#{project.default_branch}") }
let(:build) { create(:ci_build, pipeline: pipeline, environment: environment.name) }
it 'does not append CHANGED_PAGES variables' do
ci_variables = subject.select { |var| var[:key] =~ /MERGE_REQUEST_CHANGED_PAGES/ }
expect(ci_variables).to be_empty
end
end
context 'with no deployment environment and a present merge request' do
let(:merge_request) { create(:merge_request, :with_detached_merge_request_pipeline, source_project: project, target_project: project) }
let(:build) { create(:ci_build, pipeline: merge_request.all_pipelines.take) }
it 'does not append CHANGED_PAGES variables' do
ci_variables = subject.select { |var| var[:key] =~ /MERGE_REQUEST_CHANGED_PAGES/ }
expect(ci_variables).to be_empty
end
end
context 'with no deployment environment and no merge request' do
it 'does not append CHANGED_PAGES variables' do
ci_variables = subject.select { |var| var[:key] =~ /MERGE_REQUEST_CHANGED_PAGES/ }
expect(ci_variables).to be_empty
end
end
end
end
context 'when build has user' do
let(:user_variables) do
[
Loading
Loading
Loading
Loading
@@ -51,8 +51,10 @@ describe EnvironmentStatus do
# - source: /files\/(.+)/
# public: '\1'
describe '#changes' do
subject { environment_status.changes }
it 'contains only added and modified public pages' do
expect(environment_status.changes).to contain_exactly(
expect(subject).to contain_exactly(
{
path: 'ruby-style-guide.html',
external_url: "#{environment.external_url}/ruby-style-guide.html"
Loading
Loading
@@ -64,6 +66,18 @@ describe EnvironmentStatus do
end
end
 
describe '#changed_paths' do
subject { environment_status.changed_urls }
it { is_expected.to contain_exactly("#{environment.external_url}/ruby-style-guide.html", "#{environment.external_url}/html/page.html") }
end
describe '#changed_urls' do
subject { environment_status.changed_paths }
it { is_expected.to contain_exactly('ruby-style-guide.html', 'html/page.html') }
end
describe '.for_merge_request' do
let(:admin) { create(:admin) }
let!(:pipeline) { create(:ci_pipeline, sha: sha, merge_requests_as_head_pipeline: [merge_request]) }
Loading
Loading
Loading
Loading
@@ -643,4 +643,12 @@ describe PagesDomain do
end
end
end
describe '.find_by_domain_case_insensitive' do
it 'lookup is case-insensitive' do
pages_domain = create(:pages_domain, domain: "Pages.IO")
expect(PagesDomain.find_by_domain_case_insensitive('pages.io')).to eq(pages_domain)
end
end
end
Loading
Loading
@@ -74,5 +74,28 @@ describe ChatNotificationService do
chat_service.execute(data)
end
end
shared_examples 'with channel specified' do |channel, expected_channels|
before do
allow(chat_service).to receive(:push_channel).and_return(channel)
end
it 'notifies all channels' do
expect(chat_service).to receive(:notify).with(any_args, hash_including(channel: expected_channels)).and_return(true)
expect(chat_service.execute(data)).to be(true)
end
end
context 'with single channel specified' do
it_behaves_like 'with channel specified', 'slack-integration', ['slack-integration']
end
context 'with multiple channel names specified' do
it_behaves_like 'with channel specified', 'slack-integration,#slack-test', ['slack-integration', '#slack-test']
end
context 'with multiple channel names with spaces specified' do
it_behaves_like 'with channel specified', 'slack-integration, #slack-test, @UDLP91W0A', ['slack-integration', '#slack-test', '@UDLP91W0A']
end
end
end
Loading
Loading
@@ -141,21 +141,29 @@ describe API::Internal::Pages do
context 'custom domain' do
let(:namespace) { create(:namespace, name: 'gitlab-org') }
let(:project) { create(:project, namespace: namespace, name: 'gitlab-ce') }
let!(:pages_domain) { create(:pages_domain, domain: 'pages.gitlab.io', project: project) }
let!(:pages_domain) { create(:pages_domain, domain: 'pages.io', project: project) }
 
context 'when there are no pages deployed for the related project' do
it 'responds with 204 No Content' do
query_host('pages.gitlab.io')
query_host('pages.io')
 
expect(response).to have_gitlab_http_status(:no_content)
end
end
 
context 'when there are pages deployed for the related project' do
it 'domain lookup is case insensitive' do
deploy_pages(project)
query_host('Pages.IO')
expect(response).to have_gitlab_http_status(:ok)
end
it 'responds with the correct domain configuration' do
deploy_pages(project)
 
query_host('pages.gitlab.io')
query_host('pages.io')
 
expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('internal/pages/virtual_domain')
Loading
Loading
Loading
Loading
@@ -151,22 +151,14 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name|
it 'uses the username as an option for slack when configured' do
allow(chat_service).to receive(:username).and_return(username)
 
expect(Slack::Notifier).to receive(:new)
.with(webhook_url, username: username, http_client: SlackService::Notifier::HTTPClient)
.and_return(
double(:slack_service).as_null_object
)
expect(Slack::Messenger).to execute_with_options(username: username)
 
chat_service.execute(data)
end
 
it 'uses the channel as an option when it is configured' do
allow(chat_service).to receive(:channel).and_return(channel)
expect(Slack::Notifier).to receive(:new)
.with(webhook_url, channel: channel, http_client: SlackService::Notifier::HTTPClient)
.and_return(
double(:slack_service).as_null_object
)
expect(Slack::Messenger).to execute_with_options(channel: [channel])
chat_service.execute(data)
end
 
Loading
Loading
@@ -174,11 +166,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name|
it "uses the right channel for push event" do
chat_service.update(push_channel: "random")
 
expect(Slack::Notifier).to receive(:new)
.with(webhook_url, channel: "random", http_client: SlackService::Notifier::HTTPClient)
.and_return(
double(:slack_service).as_null_object
)
expect(Slack::Messenger).to execute_with_options(channel: ['random'])
 
chat_service.execute(data)
end
Loading
Loading
@@ -186,11 +174,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name|
it "uses the right channel for merge request event" do
chat_service.update(merge_request_channel: "random")
 
expect(Slack::Notifier).to receive(:new)
.with(webhook_url, channel: "random", http_client: SlackService::Notifier::HTTPClient)
.and_return(
double(:slack_service).as_null_object
)
expect(Slack::Messenger).to execute_with_options(channel: ['random'])
 
chat_service.execute(@merge_sample_data)
end
Loading
Loading
@@ -198,11 +182,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name|
it "uses the right channel for issue event" do
chat_service.update(issue_channel: "random")
 
expect(Slack::Notifier).to receive(:new)
.with(webhook_url, channel: "random", http_client: SlackService::Notifier::HTTPClient)
.and_return(
double(:slack_service).as_null_object
)
expect(Slack::Messenger).to execute_with_options(channel: ['random'])
 
chat_service.execute(@issues_sample_data)
end
Loading
Loading
@@ -213,7 +193,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name|
it "uses confidential issue channel" do
chat_service.update(confidential_issue_channel: 'confidential')
 
expect(Slack::Notifier).to execute_with_options(channel: 'confidential')
expect(Slack::Messenger).to execute_with_options(channel: ['confidential'])
 
chat_service.execute(@issues_sample_data)
end
Loading
Loading
@@ -221,7 +201,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name|
it 'falls back to issue channel' do
chat_service.update(issue_channel: 'fallback_channel')
 
expect(Slack::Notifier).to execute_with_options(channel: 'fallback_channel')
expect(Slack::Messenger).to execute_with_options(channel: ['fallback_channel'])
 
chat_service.execute(@issues_sample_data)
end
Loading
Loading
@@ -230,11 +210,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name|
it "uses the right channel for wiki event" do
chat_service.update(wiki_page_channel: "random")
 
expect(Slack::Notifier).to receive(:new)
.with(webhook_url, channel: "random", http_client: SlackService::Notifier::HTTPClient)
.and_return(
double(:slack_service).as_null_object
)
expect(Slack::Messenger).to execute_with_options(channel: ['random'])
 
chat_service.execute(@wiki_page_sample_data)
end
Loading
Loading
@@ -249,11 +225,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name|
 
note_data = Gitlab::DataBuilder::Note.build(issue_note, user)
 
expect(Slack::Notifier).to receive(:new)
.with(webhook_url, channel: "random", http_client: SlackService::Notifier::HTTPClient)
.and_return(
double(:slack_service).as_null_object
)
expect(Slack::Messenger).to execute_with_options(channel: ['random'])
 
chat_service.execute(note_data)
end
Loading
Loading
@@ -268,7 +240,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name|
 
note_data = Gitlab::DataBuilder::Note.build(issue_note, user)
 
expect(Slack::Notifier).to execute_with_options(channel: 'confidential')
expect(Slack::Messenger).to execute_with_options(channel: ['confidential'])
 
chat_service.execute(note_data)
end
Loading
Loading
@@ -278,7 +250,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name|
 
note_data = Gitlab::DataBuilder::Note.build(issue_note, user)
 
expect(Slack::Notifier).to execute_with_options(channel: 'fallback_channel')
expect(Slack::Messenger).to execute_with_options(channel: ['fallback_channel'])
 
chat_service.execute(note_data)
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment