diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-19 00:12:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-19 00:12:09 +0300 |
commit | 83e96e5e3f7aa07c06f97f4b86b00c078bb8a18e (patch) | |
tree | d75b783eeb96b75fece767c91756c47539a005f1 /spec | |
parent | bc7374e61208637f6fb116e2ca59c7162b07cba9 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
7 files changed, 206 insertions, 29 deletions
diff --git a/spec/features/admin/admin_runners_spec.rb b/spec/features/admin/admin_runners_spec.rb index 44fd21e510a..91971406bd6 100644 --- a/spec/features/admin/admin_runners_spec.rb +++ b/spec/features/admin/admin_runners_spec.rb @@ -66,9 +66,9 @@ RSpec.describe "Admin Runners" do it 'has all necessary texts' do expect(page).to have_text "Register an instance runner" - expect(page).to have_text "Online runners 1" - expect(page).to have_text "Offline runners 2" - expect(page).to have_text "Stale runners 1" + expect(page).to have_text "Online 1" + expect(page).to have_text "Offline 2" + expect(page).to have_text "Stale 1" end end diff --git a/spec/frontend/runner/admin_runners/admin_runners_app_spec.js b/spec/frontend/runner/admin_runners/admin_runners_app_spec.js index 97341be7d5d..ff45da340c7 100644 --- a/spec/frontend/runner/admin_runners/admin_runners_app_spec.js +++ b/spec/frontend/runner/admin_runners/admin_runners_app_spec.js @@ -162,15 +162,9 @@ describe('AdminRunnersApp', () => { }); it('shows the total', () => { - expect(findRunnerStats().text()).toContain( - `${s__('Runners|Online runners')} ${mockRunnersCount}`, - ); - expect(findRunnerStats().text()).toContain( - `${s__('Runners|Offline runners')} ${mockRunnersCount}`, - ); - expect(findRunnerStats().text()).toContain( - `${s__('Runners|Stale runners')} ${mockRunnersCount}`, - ); + expect(findRunnerStats().text()).toContain(`${s__('Runners|Online')} ${mockRunnersCount}`); + expect(findRunnerStats().text()).toContain(`${s__('Runners|Offline')} ${mockRunnersCount}`); + expect(findRunnerStats().text()).toContain(`${s__('Runners|Stale')} ${mockRunnersCount}`); }); }); diff --git a/spec/frontend/runner/components/stat/runner_stats_spec.js b/spec/frontend/runner/components/stat/runner_stats_spec.js index 7f1f22be94f..7757757a9ae 100644 --- a/spec/frontend/runner/components/stat/runner_stats_spec.js +++ b/spec/frontend/runner/components/stat/runner_stats_spec.js @@ -7,7 +7,7 @@ import { INSTANCE_TYPE, STATUS_ONLINE, STATUS_OFFLINE, STATUS_STALE } from '~/ru describe('RunnerStats', () => { let wrapper; - const findSingleStats = () => wrapper.findAllComponents(RunnerSingleStat).wrappers; + const findSingleStats = () => wrapper.findAllComponents(RunnerSingleStat); const createComponent = ({ props = {}, mountFn = shallowMount, ...options } = {}) => { wrapper = mountFn(RunnerStats, { @@ -46,16 +46,28 @@ describe('RunnerStats', () => { }); const text = wrapper.text(); - expect(text).toMatch(`${s__('Runners|Online runners')} 3`); - expect(text).toMatch(`${s__('Runners|Offline runners')} 2`); - expect(text).toMatch(`${s__('Runners|Stale runners')} 1`); + expect(text).toContain(`${s__('Runners|Online')} 3`); + expect(text).toContain(`${s__('Runners|Offline')} 2`); + expect(text).toContain(`${s__('Runners|Stale')} 1`); + }); + + it('Skips query for other stats', () => { + createComponent({ + props: { + variables: { status: STATUS_ONLINE }, + }, + }); + + expect(findSingleStats().at(0).props('skip')).toBe(false); + expect(findSingleStats().at(1).props('skip')).toBe(true); + expect(findSingleStats().at(2).props('skip')).toBe(true); }); it('Displays all counts for filtered searches', () => { const mockVariables = { paused: true }; createComponent({ props: { variables: mockVariables } }); - findSingleStats().forEach((stat) => { + findSingleStats().wrappers.forEach((stat) => { expect(stat.props('variables')).toMatchObject(mockVariables); }); }); diff --git a/spec/frontend/runner/group_runners/group_runners_app_spec.js b/spec/frontend/runner/group_runners/group_runners_app_spec.js index 57d64202219..6ed375df338 100644 --- a/spec/frontend/runner/group_runners/group_runners_app_spec.js +++ b/spec/frontend/runner/group_runners/group_runners_app_spec.js @@ -153,15 +153,10 @@ describe('GroupRunnersApp', () => { groupFullPath: mockGroupFullPath, }); - expect(findRunnerStats().text()).toContain( - `${s__('Runners|Online runners')} ${mockGroupRunnersCount}`, - ); - expect(findRunnerStats().text()).toContain( - `${s__('Runners|Offline runners')} ${mockGroupRunnersCount}`, - ); - expect(findRunnerStats().text()).toContain( - `${s__('Runners|Stale runners')} ${mockGroupRunnersCount}`, - ); + const text = findRunnerStats().text(); + expect(text).toContain(`${s__('Runners|Online')} ${mockGroupRunnersCount}`); + expect(text).toContain(`${s__('Runners|Offline')} ${mockGroupRunnersCount}`); + expect(text).toContain(`${s__('Runners|Stale')} ${mockGroupRunnersCount}`); }); it('shows the runners list', async () => { diff --git a/spec/lib/gitlab/background_migration/disable_legacy_open_source_licence_for_recent_public_projects_spec.rb b/spec/lib/gitlab/background_migration/disable_legacy_open_source_licence_for_recent_public_projects_spec.rb new file mode 100644 index 00000000000..7edba8cf524 --- /dev/null +++ b/spec/lib/gitlab/background_migration/disable_legacy_open_source_licence_for_recent_public_projects_spec.rb @@ -0,0 +1,114 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::BackgroundMigration::DisableLegacyOpenSourceLicenceForRecentPublicProjects, :migration do + let(:namespaces_table) { table(:namespaces) } + let(:namespace_1) { namespaces_table.create!(name: 'namespace', path: 'namespace-path-1') } + let(:project_namespace_2) { namespaces_table.create!(name: 'namespace', path: 'namespace-path-2', type: 'Project') } + let(:project_namespace_3) { namespaces_table.create!(name: 'namespace', path: 'namespace-path-3', type: 'Project') } + let(:project_namespace_4) { namespaces_table.create!(name: 'namespace', path: 'namespace-path-4', type: 'Project') } + let(:project_namespace_5) { namespaces_table.create!(name: 'namespace', path: 'namespace-path-5', type: 'Project') } + let(:project_namespace_6) { namespaces_table.create!(name: 'namespace', path: 'namespace-path-6', type: 'Project') } + let(:project_namespace_7) { namespaces_table.create!(name: 'namespace', path: 'namespace-path-7', type: 'Project') } + let(:project_namespace_8) { namespaces_table.create!(name: 'namespace', path: 'namespace-path-8', type: 'Project') } + + let(:project_1) do + projects_table + .create!( + name: 'proj-1', path: 'path-1', namespace_id: namespace_1.id, + project_namespace_id: project_namespace_2.id, visibility_level: 0 + ) + end + + let(:project_2) do + projects_table + .create!( + name: 'proj-2', path: 'path-2', namespace_id: namespace_1.id, + project_namespace_id: project_namespace_3.id, visibility_level: 10, created_at: '2022-02-22' + ) + end + + let(:project_3) do + projects_table + .create!( + name: 'proj-3', path: 'path-3', namespace_id: namespace_1.id, + project_namespace_id: project_namespace_4.id, visibility_level: 20, created_at: '2022-02-17 09:00:01' + ) + end + + let(:project_4) do + projects_table + .create!( + name: 'proj-4', path: 'path-4', namespace_id: namespace_1.id, + project_namespace_id: project_namespace_5.id, visibility_level: 20, created_at: '2022-02-01' + ) + end + + let(:project_5) do + projects_table + .create!( + name: 'proj-5', path: 'path-5', namespace_id: namespace_1.id, + project_namespace_id: project_namespace_6.id, visibility_level: 20, created_at: '2022-01-04' + ) + end + + let(:project_6) do + projects_table + .create!( + name: 'proj-6', path: 'path-6', namespace_id: namespace_1.id, + project_namespace_id: project_namespace_7.id, visibility_level: 20, created_at: '2022-02-17 08:59:59' + ) + end + + let(:project_7) do + projects_table + .create!( + name: 'proj-7', path: 'path-7', namespace_id: namespace_1.id, + project_namespace_id: project_namespace_8.id, visibility_level: 20, created_at: '2022-02-17 09:00:00' + ) + end + + let(:projects_table) { table(:projects) } + let(:project_settings_table) { table(:project_settings) } + + subject(:perform_migration) do + described_class.new(start_id: projects_table.minimum(:id), + end_id: projects_table.maximum(:id), + batch_table: :projects, + batch_column: :id, + sub_batch_size: 2, + pause_ms: 0, + connection: ActiveRecord::Base.connection) + .perform + end + + before do + project_settings_table.create!(project_id: project_1.id, legacy_open_source_license_available: true) + project_settings_table.create!(project_id: project_2.id, legacy_open_source_license_available: true) + project_settings_table.create!(project_id: project_3.id, legacy_open_source_license_available: true) + project_settings_table.create!(project_id: project_4.id, legacy_open_source_license_available: true) + project_settings_table.create!(project_id: project_5.id, legacy_open_source_license_available: false) + project_settings_table.create!(project_id: project_6.id, legacy_open_source_license_available: true) + project_settings_table.create!(project_id: project_7.id, legacy_open_source_license_available: true) + end + + it 'sets `legacy_open_source_license_available` attribute to false for public projects created after threshold time', + :aggregate_failures do + record = ActiveRecord::QueryRecorder.new do + expect { perform_migration } + .to not_change { migrated_attribute(project_1.id) }.from(true) + .and not_change { migrated_attribute(project_2.id) }.from(true) + .and change { migrated_attribute(project_3.id) }.from(true).to(false) + .and not_change { migrated_attribute(project_4.id) }.from(true) + .and not_change { migrated_attribute(project_5.id) }.from(false) + .and not_change { migrated_attribute(project_6.id) }.from(true) + .and change { migrated_attribute(project_7.id) }.from(true).to(false) + end + expect(record.count).to eq(19) + end + + def migrated_attribute(project_id) + project_settings_table.find(project_id).legacy_open_source_license_available + end +end diff --git a/spec/migrations/20220801155858_schedule_disable_legacy_open_source_licence_for_recent_public_projects_spec.rb b/spec/migrations/20220801155858_schedule_disable_legacy_open_source_licence_for_recent_public_projects_spec.rb new file mode 100644 index 00000000000..fdd97f2d008 --- /dev/null +++ b/spec/migrations/20220801155858_schedule_disable_legacy_open_source_licence_for_recent_public_projects_spec.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration! + +RSpec.describe ScheduleDisableLegacyOpenSourceLicenceForRecentPublicProjects, schema: 20220801155858 do + context 'when on gitlab.com' do + let(:background_migration) { described_class::MIGRATION } + let(:migration) { described_class.new } + + before do + allow(Gitlab).to receive(:com?).and_return(true) + migration.up + end + + describe '#up' do + it 'schedules background jobs for each batch of projects' do + expect(background_migration).to( + have_scheduled_batched_migration( + table_name: :projects, + column_name: :id, + interval: described_class::INTERVAL, + batch_size: described_class::BATCH_SIZE, + sub_batch_size: described_class::SUB_BATCH_SIZE + ) + ) + end + end + + describe '#down' do + it 'deletes all batched migration records' do + migration.down + + expect(described_class::MIGRATION).not_to have_scheduled_batched_migration + end + end + end + + context 'when on self-managed instances' do + let(:migration) { described_class.new } + + before do + allow(Gitlab).to receive(:com?).and_return(false) + end + + describe '#up' do + it 'does not schedule background job' do + expect(migration).not_to receive(:queue_batched_background_migration) + + migration.up + end + end + + describe '#down' do + it 'does not delete background job' do + expect(migration).not_to receive(:delete_batched_background_migration) + + migration.down + end + end + end +end diff --git a/spec/support/shared_examples/features/runners_shared_examples.rb b/spec/support/shared_examples/features/runners_shared_examples.rb index 52f3fd60c07..e5043e7b28f 100644 --- a/spec/support/shared_examples/features/runners_shared_examples.rb +++ b/spec/support/shared_examples/features/runners_shared_examples.rb @@ -64,9 +64,9 @@ end RSpec.shared_examples 'shows no runners registered' do it 'shows counts with 0' do - expect(page).to have_text "Online runners 0" - expect(page).to have_text "Offline runners 0" - expect(page).to have_text "Stale runners 0" + expect(page).to have_text "Online 0" + expect(page).to have_text "Offline 0" + expect(page).to have_text "Stale 0" end it 'shows "no runners" message' do |