summaryrefslogtreecommitdiff
path: root/spec/presenters
diff options
context:
space:
mode:
Diffstat (limited to 'spec/presenters')
-rw-r--r--spec/presenters/ci/build_presenter_spec.rb26
-rw-r--r--spec/presenters/ci/build_runner_presenter_spec.rb142
-rw-r--r--spec/presenters/clusterable_presenter_spec.rb16
-rw-r--r--spec/presenters/pages_domain_presenter_spec.rb8
-rw-r--r--spec/presenters/projects/prometheus/alert_presenter_spec.rb142
5 files changed, 223 insertions, 111 deletions
diff --git a/spec/presenters/ci/build_presenter_spec.rb b/spec/presenters/ci/build_presenter_spec.rb
index b6c47f40ceb..9cf6eb45c63 100644
--- a/spec/presenters/ci/build_presenter_spec.rb
+++ b/spec/presenters/ci/build_presenter_spec.rb
@@ -264,30 +264,4 @@ describe Ci::BuildPresenter do
expect(description).to eq('There has been an API failure, please try again')
end
end
-
- describe '#recoverable?' do
- let(:build) { create(:ci_build, :failed, :script_failure) }
-
- context 'when is a script or missing dependency failure' do
- let(:failure_reasons) { %w(script_failure missing_dependency_failure archived_failure scheduler_failure data_integrity_failure) }
-
- it 'returns false' do
- failure_reasons.each do |failure_reason|
- build.update_attribute(:failure_reason, failure_reason)
- expect(presenter.recoverable?).to be_falsy
- end
- end
- end
-
- context 'when is any other failure type' do
- let(:failure_reasons) { %w(unknown_failure api_failure stuck_or_timeout_failure runner_system_failure) }
-
- it 'returns true' do
- failure_reasons.each do |failure_reason|
- build.update_attribute(:failure_reason, failure_reason)
- expect(presenter.recoverable?).to be_truthy
- end
- end
- end
- end
end
diff --git a/spec/presenters/ci/build_runner_presenter_spec.rb b/spec/presenters/ci/build_runner_presenter_spec.rb
index 0635c318942..de199d2bff9 100644
--- a/spec/presenters/ci/build_runner_presenter_spec.rb
+++ b/spec/presenters/ci/build_runner_presenter_spec.rb
@@ -38,6 +38,47 @@ describe Ci::BuildRunnerPresenter do
expect(presenter.artifacts).to be_empty
end
end
+
+ context 'when artifacts exclude is defined' do
+ let(:build) do
+ create(:ci_build, options: { artifacts: { paths: %w[abc], exclude: %w[cde] } })
+ end
+
+ context 'when the feature is enabled' do
+ before do
+ stub_feature_flags(ci_artifacts_exclude: true)
+ end
+
+ it 'includes the list of excluded paths' do
+ expect(presenter.artifacts.first).to include(
+ artifact_type: :archive,
+ artifact_format: :zip,
+ paths: %w[abc],
+ exclude: %w[cde]
+ )
+ end
+ end
+
+ context 'when the feature is disabled' do
+ before do
+ stub_feature_flags(ci_artifacts_exclude: false)
+ end
+
+ it 'does not include the list of excluded paths' do
+ expect(presenter.artifacts.first).not_to have_key(:exclude)
+ end
+ end
+ end
+
+ context 'when artifacts exclude is not defined' do
+ let(:build) do
+ create(:ci_build, options: { artifacts: { paths: %w[abc] } })
+ end
+
+ it 'does not include an empty list of excluded paths' do
+ expect(presenter.artifacts.first).not_to have_key(:exclude)
+ end
+ end
end
context "with reports" do
@@ -138,32 +179,25 @@ describe Ci::BuildRunnerPresenter do
it 'defaults to git depth setting for the project' do
expect(git_depth).to eq(build.project.ci_default_git_depth)
end
-
- context 'when feature flag :ci_project_git_depth is disabled' do
- before do
- stub_feature_flags(ci_project_git_depth: { enabled: false })
- end
-
- it 'defaults to 0' do
- expect(git_depth).to eq(0)
- end
- end
end
describe '#refspecs' do
subject { presenter.refspecs }
let(:build) { create(:ci_build) }
+ let(:pipeline) { build.pipeline }
it 'returns the correct refspecs' do
- is_expected.to contain_exactly("+refs/heads/#{build.ref}:refs/remotes/origin/#{build.ref}")
+ is_expected.to contain_exactly("+refs/heads/#{build.ref}:refs/remotes/origin/#{build.ref}",
+ "+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}")
end
context 'when ref is tag' do
let(:build) { create(:ci_build, :tag) }
it 'returns the correct refspecs' do
- is_expected.to contain_exactly("+refs/tags/#{build.ref}:refs/tags/#{build.ref}")
+ is_expected.to contain_exactly("+refs/tags/#{build.ref}:refs/tags/#{build.ref}",
+ "+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}")
end
context 'when GIT_DEPTH is zero' do
@@ -173,7 +207,8 @@ describe Ci::BuildRunnerPresenter do
it 'returns the correct refspecs' do
is_expected.to contain_exactly('+refs/tags/*:refs/tags/*',
- '+refs/heads/*:refs/remotes/origin/*')
+ '+refs/heads/*:refs/remotes/origin/*',
+ "+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}")
end
end
end
@@ -183,81 +218,34 @@ describe Ci::BuildRunnerPresenter do
let(:pipeline) { merge_request.all_pipelines.first }
let(:build) { create(:ci_build, ref: pipeline.ref, pipeline: pipeline) }
- context 'when depend_on_persistent_pipeline_ref feature flag is enabled' do
- before do
- stub_feature_flags(ci_force_exposing_merge_request_refs: false)
- pipeline.persistent_ref.create
- end
-
- it 'returns the correct refspecs' do
- is_expected
- .to contain_exactly("+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}")
- end
-
- context 'when ci_force_exposing_merge_request_refs feature flag is enabled' do
- before do
- stub_feature_flags(ci_force_exposing_merge_request_refs: true)
- end
-
- it 'returns the correct refspecs' do
- is_expected
- .to contain_exactly("+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}",
- '+refs/merge-requests/1/head:refs/merge-requests/1/head')
- end
- end
-
- context 'when GIT_DEPTH is zero' do
- before do
- create(:ci_pipeline_variable, key: 'GIT_DEPTH', value: 0, pipeline: build.pipeline)
- end
-
- it 'returns the correct refspecs' do
- is_expected
- .to contain_exactly("+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}",
- '+refs/heads/*:refs/remotes/origin/*',
- '+refs/tags/*:refs/tags/*')
- end
- end
-
- context 'when pipeline is legacy detached merge request pipeline' do
- let(:merge_request) { create(:merge_request, :with_legacy_detached_merge_request_pipeline) }
+ before do
+ pipeline.persistent_ref.create
+ end
- it 'returns the correct refspecs' do
- is_expected.to contain_exactly("+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}",
- "+refs/heads/#{build.ref}:refs/remotes/origin/#{build.ref}")
- end
- end
+ it 'returns the correct refspecs' do
+ is_expected
+ .to contain_exactly("+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}")
end
- context 'when depend_on_persistent_pipeline_ref feature flag is disabled' do
+ context 'when GIT_DEPTH is zero' do
before do
- stub_feature_flags(depend_on_persistent_pipeline_ref: false)
+ create(:ci_pipeline_variable, key: 'GIT_DEPTH', value: 0, pipeline: build.pipeline)
end
it 'returns the correct refspecs' do
is_expected
- .to contain_exactly('+refs/merge-requests/1/head:refs/merge-requests/1/head')
- end
-
- context 'when GIT_DEPTH is zero' do
- before do
- create(:ci_pipeline_variable, key: 'GIT_DEPTH', value: 0, pipeline: build.pipeline)
- end
-
- it 'returns the correct refspecs' do
- is_expected
- .to contain_exactly('+refs/merge-requests/1/head:refs/merge-requests/1/head',
- '+refs/heads/*:refs/remotes/origin/*',
- '+refs/tags/*:refs/tags/*')
- end
+ .to contain_exactly("+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}",
+ '+refs/heads/*:refs/remotes/origin/*',
+ '+refs/tags/*:refs/tags/*')
end
+ end
- context 'when pipeline is legacy detached merge request pipeline' do
- let(:merge_request) { create(:merge_request, :with_legacy_detached_merge_request_pipeline) }
+ context 'when pipeline is legacy detached merge request pipeline' do
+ let(:merge_request) { create(:merge_request, :with_legacy_detached_merge_request_pipeline) }
- it 'returns the correct refspecs' do
- is_expected.to contain_exactly("+refs/heads/#{build.ref}:refs/remotes/origin/#{build.ref}")
- end
+ it 'returns the correct refspecs' do
+ is_expected.to contain_exactly("+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}",
+ "+refs/heads/#{build.ref}:refs/remotes/origin/#{build.ref}")
end
end
end
diff --git a/spec/presenters/clusterable_presenter_spec.rb b/spec/presenters/clusterable_presenter_spec.rb
index 47ccc59ae45..2c0a7f3e9b2 100644
--- a/spec/presenters/clusterable_presenter_spec.rb
+++ b/spec/presenters/clusterable_presenter_spec.rb
@@ -87,4 +87,20 @@ describe ClusterablePresenter do
it { is_expected.to be_nil }
end
+
+ describe '#index_path' do
+ let(:clusterable) { create(:group) }
+
+ context 'without options' do
+ subject { described_class.new(clusterable).index_path }
+
+ it { is_expected.to eq(group_clusters_path(clusterable)) }
+ end
+
+ context 'with options' do
+ subject { described_class.new(clusterable).index_path(format: :json) }
+
+ it { is_expected.to eq(group_clusters_path(clusterable, format: :json)) }
+ end
+ end
end
diff --git a/spec/presenters/pages_domain_presenter_spec.rb b/spec/presenters/pages_domain_presenter_spec.rb
index 1cae3a8c9be..30ce59b7bfb 100644
--- a/spec/presenters/pages_domain_presenter_spec.rb
+++ b/spec/presenters/pages_domain_presenter_spec.rb
@@ -45,14 +45,6 @@ describe PagesDomainPresenter do
it { is_expected.to eq(true) }
- context 'when lets_encrypt_error feature flag is disabled' do
- before do
- stub_feature_flags(pages_letsencrypt_errors: false)
- end
-
- it { is_expected.to eq(false) }
- end
-
context "when Let's Encrypt integration is disabled" do
before do
allow(::Gitlab::LetsEncrypt).to receive(:enabled?).and_return false
diff --git a/spec/presenters/projects/prometheus/alert_presenter_spec.rb b/spec/presenters/projects/prometheus/alert_presenter_spec.rb
index 85c73aa3533..967a0fb2c09 100644
--- a/spec/presenters/projects/prometheus/alert_presenter_spec.rb
+++ b/spec/presenters/projects/prometheus/alert_presenter_spec.rb
@@ -152,6 +152,148 @@ describe Projects::Prometheus::AlertPresenter do
end
end
end
+
+ context 'with embedded metrics' do
+ let(:starts_at) { '2018-03-12T09:06:00Z' }
+
+ shared_examples_for 'markdown with metrics embed' do
+ let(:expected_markdown) do
+ <<~MARKDOWN.chomp
+ #### Summary
+
+ **Start time:** #{presenter.starts_at}#{markdown_line_break}
+ **full_query:** `avg(metric) > 1.0`
+
+ [](#{url})
+ MARKDOWN
+ end
+
+ context 'without a starting time available' do
+ around do |example|
+ Timecop.freeze(starts_at) { example.run }
+ end
+
+ it { is_expected.to eq(expected_markdown) }
+ end
+
+ context 'with a starting time available' do
+ before do
+ payload['startsAt'] = starts_at
+ end
+
+ it { is_expected.to eq(expected_markdown) }
+ end
+ end
+
+ context 'for gitlab-managed prometheus alerts' do
+ let(:gitlab_alert) { create(:prometheus_alert, project: project) }
+ let(:metric_id) { gitlab_alert.prometheus_metric_id }
+ let(:env_id) { gitlab_alert.environment_id }
+
+ before do
+ payload['labels'] = { 'gitlab_alert_id' => metric_id }
+ end
+
+ let(:url) { "http://localhost/#{project.full_path}/prometheus/alerts/#{metric_id}/metrics_dashboard?end=2018-03-12T09%3A36%3A00Z&environment_id=#{env_id}&start=2018-03-12T08%3A36%3A00Z" }
+
+ it_behaves_like 'markdown with metrics embed'
+ end
+
+ context 'for alerts from a self-managed prometheus' do
+ let!(:environment) { create(:environment, project: project, name: 'production') }
+ let(:url) { "http://localhost/#{project.full_path}/-/environments/#{environment.id}/metrics_dashboard?embed_json=#{CGI.escape(embed_content.to_json)}&end=2018-03-12T09%3A36%3A00Z&start=2018-03-12T08%3A36%3A00Z" }
+
+ let(:title) { 'title' }
+ let(:y_label) { 'y_label' }
+ let(:query) { 'avg(metric) > 1.0' }
+ let(:embed_content) do
+ {
+ panel_groups: [{
+ panels: [{
+ type: 'line-graph',
+ title: title,
+ y_label: y_label,
+ metrics: [{ query_range: query }]
+ }]
+ }]
+ }
+ end
+
+ before do
+ # Setup embed time range
+ payload['startsAt'] = starts_at
+
+ # Setup query
+ payload['generatorURL'] = "http://host?g0.expr=#{CGI.escape(query)}"
+
+ # Setup environment
+ payload['labels'] ||= {}
+ payload['labels']['gitlab_environment_name'] = 'production'
+
+ # Setup chart title & axis labels
+ payload['annotations'] ||= {}
+ payload['annotations']['title'] = 'title'
+ payload['annotations']['gitlab_y_label'] = 'y_label'
+ end
+
+ it_behaves_like 'markdown with metrics embed'
+
+ context 'without y_label' do
+ let(:y_label) { title }
+
+ before do
+ payload['annotations'].delete('gitlab_y_label')
+ end
+
+ it_behaves_like 'markdown with metrics embed'
+ end
+
+ context 'when not enough information is present for an embed' do
+ let(:expected_markdown) do
+ <<~MARKDOWN.chomp
+ #### Summary
+
+ **Start time:** #{presenter.starts_at}#{markdown_line_break}
+ **full_query:** `avg(metric) > 1.0`
+
+ MARKDOWN
+ end
+
+ context 'without title' do
+ before do
+ payload['annotations'].delete('title')
+ end
+
+ it { is_expected.to eq(expected_markdown) }
+ end
+
+ context 'without environment' do
+ before do
+ payload['labels'].delete('gitlab_environment_name')
+ end
+
+ it { is_expected.to eq(expected_markdown) }
+ end
+
+ context 'without full_query' do
+ let(:expected_markdown) do
+ <<~MARKDOWN.chomp
+ #### Summary
+
+ **Start time:** #{presenter.starts_at}
+
+ MARKDOWN
+ end
+
+ before do
+ payload.delete('generatorURL')
+ end
+
+ it { is_expected.to eq(expected_markdown) }
+ end
+ end
+ end
+ end
end
describe '#show_performance_dashboard_link?' do