diff options
Diffstat (limited to 'spec/helpers/ci')
-rw-r--r-- | spec/helpers/ci/builds_helper_spec.rb | 59 | ||||
-rw-r--r-- | spec/helpers/ci/catalog/resources_helper_spec.rb | 35 | ||||
-rw-r--r-- | spec/helpers/ci/jobs_helper_spec.rb | 53 | ||||
-rw-r--r-- | spec/helpers/ci/pipeline_editor_helper_spec.rb | 7 | ||||
-rw-r--r-- | spec/helpers/ci/pipelines_helper_spec.rb | 36 | ||||
-rw-r--r-- | spec/helpers/ci/runners_helper_spec.rb | 38 | ||||
-rw-r--r-- | spec/helpers/ci/variables_helper_spec.rb | 2 |
7 files changed, 113 insertions, 117 deletions
diff --git a/spec/helpers/ci/builds_helper_spec.rb b/spec/helpers/ci/builds_helper_spec.rb index c215d7b4a78..eabd40f3dd4 100644 --- a/spec/helpers/ci/builds_helper_spec.rb +++ b/spec/helpers/ci/builds_helper_spec.rb @@ -3,51 +3,6 @@ require 'spec_helper' RSpec.describe Ci::BuildsHelper do - describe '#build_summary' do - subject { helper.build_summary(build, skip: skip) } - - context 'when build has no trace' do - let(:build) { instance_double(Ci::Build, has_trace?: false) } - - context 'when skip is false' do - let(:skip) { false } - - it 'returns no job log' do - expect(subject).to eq('No job log') - end - end - - context 'when skip is true' do - let(:skip) { true } - - it 'returns no job log' do - expect(subject).to eq('No job log') - end - end - end - - context 'when build has trace' do - let(:build) { create(:ci_build, :trace_live) } - - context 'when skip is true' do - let(:skip) { true } - - it 'returns link to logs' do - expect(subject).to include('View job log') - expect(subject).to include(pipeline_job_url(build.pipeline, build)) - end - end - - context 'when skip is false' do - let(:skip) { false } - - it 'returns log lines' do - expect(subject).to include(build.trace.html(last_lines: 10).html_safe) - end - end - end - end - describe '#sidebar_build_class' do using RSpec::Parameterized::TableSyntax @@ -97,20 +52,6 @@ RSpec.describe Ci::BuildsHelper do end end - describe '#prepare_failed_jobs_summary_data' do - let(:failed_build) { create(:ci_build, :failed, :trace_live) } - - subject { helper.prepare_failed_jobs_summary_data([failed_build]) } - - it 'returns array of failed jobs with id, failure and failure summary' do - expect(subject).to eq([{ - id: failed_build.id, - failure: failed_build.present.callout_failure_message, - failure_summary: helper.build_summary(failed_build) - }].to_json) - end - end - def assign_project build(:project).tap do |project| assign(:project, project) diff --git a/spec/helpers/ci/catalog/resources_helper_spec.rb b/spec/helpers/ci/catalog/resources_helper_spec.rb new file mode 100644 index 00000000000..e873b9379fe --- /dev/null +++ b/spec/helpers/ci/catalog/resources_helper_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Ci::Catalog::ResourcesHelper, feature_category: :pipeline_composition do + include Devise::Test::ControllerHelpers + + let_it_be(:project) { build(:project) } + + describe '#can_view_namespace_catalog?' do + subject { helper.can_view_namespace_catalog?(project) } + + before do + stub_licensed_features(ci_namespace_catalog: false) + end + + it 'user cannot view the Catalog in CE regardless of permissions' do + expect(subject).to be false + end + end + + describe '#js_ci_catalog_data' do + let(:project) { build(:project, :repository) } + + let(:default_helper_data) do + {} + end + + subject(:catalog_data) { helper.js_ci_catalog_data(project) } + + it 'returns catalog data' do + expect(catalog_data).to eq(default_helper_data) + end + end +end diff --git a/spec/helpers/ci/jobs_helper_spec.rb b/spec/helpers/ci/jobs_helper_spec.rb index 489d9d3fcee..a9ab4ab3b67 100644 --- a/spec/helpers/ci/jobs_helper_spec.rb +++ b/spec/helpers/ci/jobs_helper_spec.rb @@ -3,24 +3,49 @@ require 'spec_helper' RSpec.describe Ci::JobsHelper do - describe 'jobs data' do - let(:project) { create(:project, :repository) } - let(:bridge) { create(:ci_bridge) } - - subject(:bridge_data) { helper.bridge_data(bridge, project) } + describe 'job helper functions' do + let_it_be(:project) { create(:project, :repository) } + let_it_be(:job) { create(:ci_build, project: project) } before do - allow(helper) - .to receive(:image_path) - .and_return('/path/to/illustration') + helper.instance_variable_set(:@project, project) + helper.instance_variable_set(:@build, job) + end + + it 'returns jobs data' do + expect(helper.jobs_data).to include({ + "endpoint" => "/#{project.full_path}/-/jobs/#{job.id}.json", + "project_path" => project.full_path, + "artifact_help_url" => "/help/user/gitlab_com/index.md#gitlab-cicd", + "deployment_help_url" => "/help/user/project/clusters/deploy_to_cluster.md#troubleshooting", + "runner_settings_url" => "/#{project.full_path}/-/runners#js-runners-settings", + "page_path" => "/#{project.full_path}/-/jobs/#{job.id}", + "build_status" => "pending", + "build_stage" => "test", + "log_state" => "", + "build_options" => { + build_stage: "test", + build_status: "pending", + log_state: "", + page_path: "/#{project.full_path}/-/jobs/#{job.id}" + }, + "retry_outdated_job_docs_url" => "/help/ci/pipelines/settings#retry-outdated-jobs" + }) end - it 'returns bridge data' do - expect(bridge_data).to eq({ - "build_id" => bridge.id, - "empty-state-illustration-path" => '/path/to/illustration', - "pipeline_iid" => bridge.pipeline.iid, - "project_full_path" => project.full_path + it 'returns job statuses' do + expect(helper.job_statuses).to eq({ + "canceled" => "CANCELED", + "created" => "CREATED", + "failed" => "FAILED", + "manual" => "MANUAL", + "pending" => "PENDING", + "preparing" => "PREPARING", + "running" => "RUNNING", + "scheduled" => "SCHEDULED", + "skipped" => "SKIPPED", + "success" => "SUCCESS", + "waiting_for_resource" => "WAITING_FOR_RESOURCE" }) end end diff --git a/spec/helpers/ci/pipeline_editor_helper_spec.rb b/spec/helpers/ci/pipeline_editor_helper_spec.rb index c9aac63a883..b45882d9888 100644 --- a/spec/helpers/ci/pipeline_editor_helper_spec.rb +++ b/spec/helpers/ci/pipeline_editor_helper_spec.rb @@ -4,6 +4,7 @@ require 'spec_helper' RSpec.describe Ci::PipelineEditorHelper do let_it_be(:project) { create(:project) } + let_it_be(:user) { create(:user) } describe 'can_view_pipeline_editor?' do subject { helper.can_view_pipeline_editor?(project) } @@ -29,12 +30,12 @@ RSpec.describe Ci::PipelineEditorHelper do "ci-examples-help-page-path" => help_page_path('ci/examples/index'), "ci-help-page-path" => help_page_path('ci/index'), "ci-lint-path" => project_ci_lint_path(project), + "ci-troubleshooting-path" => help_page_path('ci/troubleshooting', anchor: 'common-cicd-issues'), "default-branch" => project.default_branch_or_main, "empty-state-illustration-path" => 'illustrations/empty.svg', "initial-branch-name" => nil, "includes-help-page-path" => help_page_path('ci/yaml/includes'), "lint-help-page-path" => help_page_path('ci/lint', anchor: 'check-cicd-syntax'), - "lint-unavailable-help-page-path" => help_page_path('ci/pipeline_editor/index', anchor: 'configuration-validation-currently-not-available-message'), "needs-help-page-path" => help_page_path('ci/yaml/index', anchor: 'needs'), "new-merge-request-path" => '/mock/project/-/merge_requests/new', "pipeline-page-path" => project_pipelines_path(project), @@ -62,6 +63,10 @@ RSpec.describe Ci::PipelineEditorHelper do .to receive(:image_path) .with('illustrations/project-run-CICD-pipelines-sm.svg') .and_return('illustrations/validate.svg') + + allow(helper) + .to receive(:current_user) + .and_return(user) end subject(:pipeline_editor_data) { helper.js_pipeline_editor_data(project) } diff --git a/spec/helpers/ci/pipelines_helper_spec.rb b/spec/helpers/ci/pipelines_helper_spec.rb index 19946afb1a4..6463da7c53f 100644 --- a/spec/helpers/ci/pipelines_helper_spec.rb +++ b/spec/helpers/ci/pipelines_helper_spec.rb @@ -121,35 +121,7 @@ RSpec.describe Ci::PipelinesHelper do :has_gitlab_ci, :pipeline_editor_path, :suggested_ci_templates, - :ci_runner_settings_path]) - end - - describe 'the `any_runners_available` attribute' do - subject { data[:any_runners_available] } - - context 'when the `runners_availability_section` experiment variant is control' do - before do - stub_experiments(runners_availability_section: :control) - end - - it { is_expected.to be_nil } - end - - context 'when the `runners_availability_section` experiment variant is candidate' do - before do - stub_experiments(runners_availability_section: :candidate) - end - - context 'when there are no runners' do - it { is_expected.to eq('false') } - end - - context 'when there are runners' do - let!(:runner) { create(:ci_runner, :project, projects: [project]) } - - it { is_expected.to eq('true') } - end - end + :full_path]) end describe 'when the project is eligible for the `ios_specific_templates` experiment' do @@ -192,11 +164,7 @@ RSpec.describe Ci::PipelinesHelper do end end - describe 'the `ios_runners_available` attribute' do - before do - allow(Gitlab).to receive(:com?).and_return(true) - end - + describe 'the `ios_runners_available` attribute', :saas do subject { data[:ios_runners_available] } context 'when the `ios_specific_templates` experiment variant is control' do diff --git a/spec/helpers/ci/runners_helper_spec.rb b/spec/helpers/ci/runners_helper_spec.rb index 6d14abd6574..c170d7fae67 100644 --- a/spec/helpers/ci/runners_helper_spec.rb +++ b/spec/helpers/ci/runners_helper_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::RunnersHelper do +RSpec.describe Ci::RunnersHelper, feature_category: :runner_fleet do let_it_be(:user) { create(:user) } before do @@ -38,6 +38,14 @@ RSpec.describe Ci::RunnersHelper do end end + describe '#runner_short_name' do + it 'shows runner short name' do + runner = build_stubbed(:ci_runner, id: non_existing_record_id) + + expect(helper.runner_short_name(runner)).to eq("##{runner.id} (#{runner.short_sha})") + end + end + describe '#runner_contacted_at' do let(:contacted_at_stored) { 1.hour.ago.change(usec: 0) } let(:contacted_at_cached) { 1.second.ago.change(usec: 0) } @@ -77,7 +85,7 @@ RSpec.describe Ci::RunnersHelper do describe '#admin_runners_data_attributes' do let_it_be(:admin) { create(:user, :admin) } let_it_be(:instance_runner) { create(:ci_runner, :instance) } - let_it_be(:project_runner) { create(:ci_runner, :project ) } + let_it_be(:project_runner) { create(:ci_runner, :project) } before do allow(helper).to receive(:current_user).and_return(admin) @@ -88,9 +96,7 @@ RSpec.describe Ci::RunnersHelper do runner_install_help_page: 'https://docs.gitlab.com/runner/install/', registration_token: Gitlab::CurrentSettings.runners_registration_token, online_contact_timeout_secs: 7200, - stale_timeout_secs: 7889238, - empty_state_svg_path: start_with('/assets/illustrations/pipelines_empty'), - empty_state_filtered_svg_path: start_with('/assets/illustrations/magnifying-glass') + stale_timeout_secs: 7889238 ) end end @@ -98,6 +104,8 @@ RSpec.describe Ci::RunnersHelper do describe '#group_shared_runners_settings_data' do let_it_be(:parent) { create(:group) } let_it_be(:group) { create(:group, parent: parent, shared_runners_enabled: false) } + let_it_be(:group_with_project) { create(:group, parent: parent) } + let_it_be(:project) { create(:project, group: group_with_project) } let(:runner_constants) do { @@ -110,6 +118,8 @@ RSpec.describe Ci::RunnersHelper do it 'returns group data for top level group' do result = { group_id: parent.id, + group_name: parent.name, + group_is_empty: 'false', shared_runners_setting: Namespace::SR_ENABLED, parent_shared_runners_setting: nil }.merge(runner_constants) @@ -120,12 +130,26 @@ RSpec.describe Ci::RunnersHelper do it 'returns group data for child group' do result = { group_id: group.id, + group_name: group.name, + group_is_empty: 'true', shared_runners_setting: Namespace::SR_DISABLED_AND_UNOVERRIDABLE, parent_shared_runners_setting: Namespace::SR_ENABLED }.merge(runner_constants) expect(helper.group_shared_runners_settings_data(group)).to eq result end + + it 'returns group data for child group with project' do + result = { + group_id: group_with_project.id, + group_name: group_with_project.name, + group_is_empty: 'false', + shared_runners_setting: Namespace::SR_ENABLED, + parent_shared_runners_setting: Namespace::SR_ENABLED + }.merge(runner_constants) + + expect(helper.group_shared_runners_settings_data(group_with_project)).to eq result + end end describe '#group_runners_data_attributes' do @@ -142,9 +166,7 @@ RSpec.describe Ci::RunnersHelper do group_full_path: group.full_path, runner_install_help_page: 'https://docs.gitlab.com/runner/install/', online_contact_timeout_secs: 7200, - stale_timeout_secs: 7889238, - empty_state_svg_path: start_with('/assets/illustrations/pipelines_empty'), - empty_state_filtered_svg_path: start_with('/assets/illustrations/magnifying-glass') + stale_timeout_secs: 7889238 ) end end diff --git a/spec/helpers/ci/variables_helper_spec.rb b/spec/helpers/ci/variables_helper_spec.rb index d032e7f9087..9c3236ace72 100644 --- a/spec/helpers/ci/variables_helper_spec.rb +++ b/spec/helpers/ci/variables_helper_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::VariablesHelper, feature_category: :pipeline_authoring do +RSpec.describe Ci::VariablesHelper, feature_category: :secrets_management do describe '#ci_variable_maskable_raw_regex' do it 'converts to a javascript regex' do expect(helper.ci_variable_maskable_raw_regex).to eq("^\\S{8,}$") |