diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-18 09:08:30 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-18 09:08:30 +0000 |
commit | 5ccb67600c63549774a28811d177dd673e6dd4d0 (patch) | |
tree | c8af595d48607c660564fd89d77b47c3384501af /spec | |
parent | 6a201406143969f12cb9e4687a79ce9316420152 (diff) | |
download | gitlab-ce-5ccb67600c63549774a28811d177dd673e6dd4d0.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
11 files changed, 310 insertions, 39 deletions
diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index c5306fda0a5..1e28ef4ba93 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -559,6 +559,28 @@ RSpec.describe ApplicationController do expect(controller.last_payload[:target_duration_s]).to eq(0.25) end end + + it 'logs response length' do + sign_in user + + get :index + + expect(controller.last_payload[:response_bytes]).to eq('authenticated'.bytesize) + end + + context 'with log_response_length disabled' do + before do + stub_feature_flags(log_response_length: false) + end + + it 'logs response length' do + sign_in user + + get :index + + expect(controller.last_payload).not_to include(:response_bytes) + end + end end describe '#access_denied' do diff --git a/spec/frontend/issues/show/components/incidents/timeline_events_form_spec.js b/spec/frontend/issues/show/components/incidents/timeline_events_form_spec.js index 78a2dfac358..620cdfc53b0 100644 --- a/spec/frontend/issues/show/components/incidents/timeline_events_form_spec.js +++ b/spec/frontend/issues/show/components/incidents/timeline_events_form_spec.js @@ -7,6 +7,7 @@ import IncidentTimelineEventForm from '~/issues/show/components/incidents/timeli import createTimelineEventMutation from '~/issues/show/components/incidents/graphql/queries/create_timeline_event.mutation.graphql'; import createMockApollo from 'helpers/mock_apollo_helper'; import { createAlert } from '~/flash'; +import { useFakeDate } from 'helpers/fake_date'; import { timelineEventsCreateEventResponse, timelineEventsCreateEventError } from './mock_data'; Vue.use(VueApollo); @@ -21,6 +22,8 @@ function createMockApolloProvider(response = addEventResponse) { } describe('Timeline events form', () => { + // July 8 2020 + useFakeDate(2020, 6, 8); let wrapper; const mountComponent = ({ mockApollo, mountMethod = shallowMountExtended, stubs }) => { @@ -49,8 +52,14 @@ describe('Timeline events form', () => { const findSubmitAndAddButton = () => wrapper.findByText('Save and add another event'); const findCancelButton = () => wrapper.findByText('Cancel'); const findDatePicker = () => wrapper.findComponent(GlDatepicker); + const findDatePickerInput = () => wrapper.findByTestId('input-datepicker'); const findHourInput = () => wrapper.findByTestId('input-hours'); const findMinuteInput = () => wrapper.findByTestId('input-minutes'); + const setDatetime = () => { + findDatePicker().vm.$emit('input', new Date('2021-08-12')); + findHourInput().vm.$emit('input', 5); + findMinuteInput().vm.$emit('input', 45); + }; const submitForm = async () => { findSubmitButton().trigger('click'); @@ -85,6 +94,22 @@ describe('Timeline events form', () => { await cancelForm(); expect(wrapper.emitted()).toEqual(closeFormEvent); }); + + it('should clear the form', async () => { + setDatetime(); + await nextTick(); + + expect(findDatePickerInput().element.value).toBe('2021-08-12'); + expect(findHourInput().element.value).toBe('5'); + expect(findMinuteInput().element.value).toBe('45'); + + wrapper.vm.clear(); + await nextTick(); + + expect(findDatePickerInput().element.value).toBe('2020-07-08'); + expect(findHourInput().element.value).toBe('0'); + expect(findMinuteInput().element.value).toBe('0'); + }); }); describe('addTimelineEventQuery', () => { @@ -92,7 +117,7 @@ describe('Timeline events form', () => { input: { incidentId: 'gid://gitlab/Issue/1', note: '', - occurredAt: '2020-07-06T00:00:00.000Z', + occurredAt: '2020-07-08T00:00:00.000Z', }, }; @@ -117,9 +142,7 @@ describe('Timeline events form', () => { }, }; - findDatePicker().vm.$emit('input', new Date('2021-08-12')); - findHourInput().vm.$emit('input', 5); - findMinuteInput().vm.$emit('input', 45); + setDatetime(); await nextTick(); await submitForm(); diff --git a/spec/frontend/issues/show/components/incidents/timeline_events_tab_spec.js b/spec/frontend/issues/show/components/incidents/timeline_events_tab_spec.js index 7efa6ad8829..2d87851a761 100644 --- a/spec/frontend/issues/show/components/incidents/timeline_events_tab_spec.js +++ b/spec/frontend/issues/show/components/incidents/timeline_events_tab_spec.js @@ -152,6 +152,15 @@ describe('TimelineEventsTab', () => { expect(findTimelineEventForm().isVisible()).toBe(true); }); + it('should clear the form when button is clicked', async () => { + const mockClear = jest.fn(); + wrapper.vm.$refs.eventForm.clear = mockClear; + + await findAddEventButton().trigger('click'); + + expect(mockClear).toHaveBeenCalled(); + }); + it('should hide the form when the hide event is emitted', async () => { // open the form await findAddEventButton().trigger('click'); diff --git a/spec/lib/gitlab/grape_logging/loggers/response_logger_spec.rb b/spec/lib/gitlab/grape_logging/loggers/response_logger_spec.rb new file mode 100644 index 00000000000..94e880d979d --- /dev/null +++ b/spec/lib/gitlab/grape_logging/loggers/response_logger_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::GrapeLogging::Loggers::ResponseLogger do + let(:logger) { described_class.new } + + describe '#parameters' do + let(:response1) { 'response1' } + let(:response) { [response1] } + + subject { logger.parameters(nil, response) } + + it { expect(subject).to eq({ response_bytes: response1.bytesize }) } + + context 'with multiple response parts' do + let(:response2) { 'response2' } + let(:response) { [response1, response2] } + + it { expect(subject).to eq({ response_bytes: response1.bytesize + response2.bytesize }) } + end + + context 'with log_response_length disabled' do + before do + stub_feature_flags(log_response_length: false) + end + + it { expect(subject).to eq({}) } + end + end +end diff --git a/spec/lib/gitlab/lograge/custom_options_spec.rb b/spec/lib/gitlab/lograge/custom_options_spec.rb index 58b05be6ff9..090b79c5d3c 100644 --- a/spec/lib/gitlab/lograge/custom_options_spec.rb +++ b/spec/lib/gitlab/lograge/custom_options_spec.rb @@ -25,7 +25,8 @@ RSpec.describe Gitlab::Lograge::CustomOptions do remote_ip: '192.168.1.2', ua: 'Nyxt', queue_duration_s: 0.2, - etag_route: '/etag' + etag_route: '/etag', + response_bytes: 1234 } end @@ -55,6 +56,20 @@ RSpec.describe Gitlab::Lograge::CustomOptions do expect(subject[:user_id]).to eq('test') end + it 'adds the response length' do + expect(subject[:response_bytes]).to eq(1234) + end + + context 'with log_response_length disabled' do + before do + stub_feature_flags(log_response_length: false) + end + + it 'does not add the response length' do + expect(subject).not_to include(:response_bytes) + end + end + it 'adds Cloudflare headers' do expect(subject[:cf_ray]).to eq(event.payload[:cf_ray]) expect(subject[:cf_request_id]).to eq(event.payload[:cf_request_id]) diff --git a/spec/lib/gitlab/pages/deployment_update_spec.rb b/spec/lib/gitlab/pages/deployment_update_spec.rb new file mode 100644 index 00000000000..cf109248f36 --- /dev/null +++ b/spec/lib/gitlab/pages/deployment_update_spec.rb @@ -0,0 +1,140 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Pages::DeploymentUpdate do + let_it_be(:project, refind: true) { create(:project, :repository) } + + let_it_be(:old_pipeline) { create(:ci_pipeline, project: project, sha: project.commit('HEAD').sha) } + let_it_be(:pipeline) { create(:ci_pipeline, project: project, sha: project.commit('HEAD').sha) } + + let(:build) { create(:ci_build, pipeline: pipeline, ref: 'HEAD') } + let(:invalid_file) { fixture_file_upload('spec/fixtures/dk.png') } + + let(:file) { fixture_file_upload("spec/fixtures/pages.zip") } + let(:empty_file) { fixture_file_upload("spec/fixtures/pages_empty.zip") } + let(:empty_metadata_filename) { "spec/fixtures/pages_empty.zip.meta" } + let(:metadata_filename) { "spec/fixtures/pages.zip.meta" } + let(:metadata) { fixture_file_upload(metadata_filename) if File.exist?(metadata_filename) } + + subject(:pages_deployment_update) { described_class.new(project, build) } + + context 'for new artifacts' do + context 'for a valid job' do + let!(:artifacts_archive) { create(:ci_job_artifact, :correct_checksum, file: file, job: build) } + + before do + create(:ci_job_artifact, file_type: :metadata, file_format: :gzip, file: metadata, job: build) + + build.reload + end + + it 'is valid' do + expect(pages_deployment_update).to be_valid + end + + context 'when missing artifacts metadata' do + before do + expect(build).to receive(:artifacts_metadata?).and_return(false) + end + + it 'is invalid' do + expect(pages_deployment_update).not_to be_valid + expect(pages_deployment_update.errors.full_messages).to include('missing artifacts metadata') + end + end + end + + it 'is invalid for invalid archive' do + create(:ci_job_artifact, :archive, file: invalid_file, job: build) + + expect(pages_deployment_update).not_to be_valid + expect(pages_deployment_update.errors.full_messages).to include('missing artifacts metadata') + end + end + + describe 'maximum pages artifacts size' do + let(:metadata) { spy('metadata') } # rubocop: disable RSpec/VerifiedDoubles + + before do + file = fixture_file_upload('spec/fixtures/pages.zip') + metafile = fixture_file_upload('spec/fixtures/pages.zip.meta') + + create(:ci_job_artifact, :archive, :correct_checksum, file: file, job: build) + create(:ci_job_artifact, :metadata, file: metafile, job: build) + + allow(build).to receive(:artifacts_metadata_entry) + .and_return(metadata) + end + + context 'when maximum pages size is set to zero' do + before do + stub_application_setting(max_pages_size: 0) + end + + context "when size is above the limit" do + before do + allow(metadata).to receive(:total_size).and_return(1.megabyte) + allow(metadata).to receive(:entries).and_return([]) + end + + it 'is valid' do + expect(pages_deployment_update).to be_valid + end + end + end + + context 'when size is limited on the instance level' do + before do + stub_application_setting(max_pages_size: 100) + end + + context "when size is below the limit" do + before do + allow(metadata).to receive(:total_size).and_return(1.megabyte) + allow(metadata).to receive(:entries).and_return([]) + end + + it 'is valid' do + expect(pages_deployment_update).to be_valid + end + end + + context "when size is above the limit" do + before do + allow(metadata).to receive(:total_size).and_return(101.megabyte) + allow(metadata).to receive(:entries).and_return([]) + end + + it 'is invalid' do + expect(pages_deployment_update).not_to be_valid + expect(pages_deployment_update.errors.full_messages) + .to include('artifacts for pages are too large: 105906176') + end + end + end + end + + context 'when retrying the job' do + let!(:older_deploy_job) do + create( + :generic_commit_status, + :failed, + pipeline: pipeline, + ref: build.ref, + stage: 'deploy', + name: 'pages:deploy' + ) + end + + before do + create(:ci_job_artifact, :correct_checksum, file: file, job: build) + create(:ci_job_artifact, file_type: :metadata, file_format: :gzip, file: metadata, job: build) + build.reload + end + + it 'marks older pages:deploy jobs retried' do + expect(pages_deployment_update).to be_valid + end + end +end diff --git a/spec/lib/gitlab/sidekiq_middleware/server_metrics_spec.rb b/spec/lib/gitlab/sidekiq_middleware/server_metrics_spec.rb index 7d31979a393..117b37ffda3 100644 --- a/spec/lib/gitlab/sidekiq_middleware/server_metrics_spec.rb +++ b/spec/lib/gitlab/sidekiq_middleware/server_metrics_spec.rb @@ -169,6 +169,16 @@ RSpec.describe Gitlab::SidekiqMiddleware::ServerMetrics do subject.call(worker, job, :test) { nil } end end + + context 'when job is interrupted' do + let(:job) { { 'interrupted_count' => 1 } } + + it 'sets sidekiq_jobs_interrupted_total metric' do + expect(interrupted_total_metric).to receive(:increment) + + subject.call(worker, job, :test) { nil } + end + end end end diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb index 4064f24cff0..e3207636bdc 100644 --- a/spec/models/environment_spec.rb +++ b/spec/models/environment_spec.rb @@ -34,6 +34,14 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do it { is_expected.to validate_length_of(:external_url).is_at_most(255) } + describe 'validation' do + it 'does not become invalid record when external_url is empty' do + environment = build(:environment, external_url: nil) + + expect(environment).to be_valid + end + end + describe '.before_save' do it 'ensures environment tier when a new object is created' do environment = build(:environment, name: 'gprd', tier: nil) diff --git a/spec/models/work_items/widgets/hierarchy_spec.rb b/spec/models/work_items/widgets/hierarchy_spec.rb index 6d05953ecff..ab2bcfee13f 100644 --- a/spec/models/work_items/widgets/hierarchy_spec.rb +++ b/spec/models/work_items/widgets/hierarchy_spec.rb @@ -3,7 +3,10 @@ require 'spec_helper' RSpec.describe WorkItems::Widgets::Hierarchy do - let_it_be(:work_item) { create(:work_item) } + let_it_be(:group) { create(:group) } + let_it_be(:project) { create(:project, group: group) } + let_it_be(:task) { create(:work_item, :task, project: project) } + let_it_be(:work_item_parent) { create(:work_item, project: project) } describe '.type' do subject { described_class.type } @@ -12,17 +15,17 @@ RSpec.describe WorkItems::Widgets::Hierarchy do end describe '#type' do - subject { described_class.new(work_item).type } + subject { described_class.new(task).type } it { is_expected.to eq(:hierarchy) } end describe '#parent' do - let_it_be(:parent_link) { create(:parent_link) } + let_it_be(:parent_link) { create(:parent_link, work_item: task, work_item_parent: work_item_parent) } subject { described_class.new(parent_link.work_item).parent } - it { is_expected.to eq parent_link.work_item_parent } + it { is_expected.to eq(parent_link.work_item_parent) } context 'when work_items flag is disabled' do before do @@ -31,15 +34,23 @@ RSpec.describe WorkItems::Widgets::Hierarchy do it { is_expected.to be_nil } end + + context 'when work_items flag is enabled for the parent group' do + before do + stub_feature_flags(work_items: group) + end + + it { is_expected.to eq(parent_link.work_item_parent) } + end end describe '#children' do - let_it_be(:parent_link1) { create(:parent_link, work_item_parent: work_item) } - let_it_be(:parent_link2) { create(:parent_link, work_item_parent: work_item) } + let_it_be(:parent_link1) { create(:parent_link, work_item_parent: work_item_parent, work_item: task) } + let_it_be(:parent_link2) { create(:parent_link, work_item_parent: work_item_parent) } - subject { described_class.new(work_item).children } + subject { described_class.new(work_item_parent).children } - it { is_expected.to match_array([parent_link1.work_item, parent_link2.work_item]) } + it { is_expected.to contain_exactly(parent_link1.work_item, parent_link2.work_item) } context 'when work_items flag is disabled' do before do @@ -48,5 +59,13 @@ RSpec.describe WorkItems::Widgets::Hierarchy do it { is_expected.to be_empty } end + + context 'when work_items flag is enabled for the parent group' do + before do + stub_feature_flags(work_items: group) + end + + it { is_expected.to contain_exactly(parent_link1.work_item, parent_link2.work_item) } + end end end diff --git a/spec/services/projects/update_pages_service_spec.rb b/spec/services/projects/update_pages_service_spec.rb index 06e39ccc8c7..24b5e35e422 100644 --- a/spec/services/projects/update_pages_service_spec.rb +++ b/spec/services/projects/update_pages_service_spec.rb @@ -171,16 +171,6 @@ RSpec.describe Projects::UpdatePagesService do end end - shared_examples 'fails with outdated reference message' do - it 'fails' do - expect(execute).not_to eq(:success) - expect(project.reload.pages_metadatum).not_to be_deployed - - expect(deploy_status).to be_failed - expect(deploy_status.description).to eq('build SHA is outdated for this ref') - end - end - shared_examples 'successfully deploys' do it 'succeeds' do expect do @@ -212,27 +202,29 @@ RSpec.describe Projects::UpdatePagesService do project.update_pages_deployment!(new_deployment) end - include_examples 'fails with outdated reference message' + it 'fails with outdated reference message' do + expect(execute).to eq(:error) + expect(project.reload.pages_metadatum).not_to be_deployed + + expect(deploy_status).to be_failed + expect(deploy_status.description).to eq('build SHA is outdated for this ref') + end end end - context 'when uploaded deployment size is wrong' do - it 'raises an error' do - allow_next_instance_of(PagesDeployment) do |deployment| - allow(deployment) - .to receive(:size) - .and_return(file.size + 1) - end + it 'fails when uploaded deployment size is wrong' do + allow_next_instance_of(PagesDeployment) do |deployment| + allow(deployment) + .to receive(:size) + .and_return(file.size + 1) + end - expect do - expect(execute).not_to eq(:success) + expect(execute).not_to eq(:success) - expect(GenericCommitStatus.last.description).to eq("Error: The uploaded artifact size does not match the expected value.") - project.pages_metadatum.reload - expect(project.pages_metadatum).not_to be_deployed - expect(project.pages_metadatum.pages_deployment).to be_ni - end.to raise_error(Projects::UpdatePagesService::WrongUploadedDeploymentSizeError) - end + expect(GenericCommitStatus.last.description).to eq('The uploaded artifact size does not match the expected value') + project.pages_metadatum.reload + expect(project.pages_metadatum).not_to be_deployed + expect(project.pages_metadatum.pages_deployment).to be_nil end end end diff --git a/spec/support/shared_contexts/lib/gitlab/sidekiq_middleware/server_metrics_shared_context.rb b/spec/support/shared_contexts/lib/gitlab/sidekiq_middleware/server_metrics_shared_context.rb index 0d992f33c61..449db59e35d 100644 --- a/spec/support/shared_contexts/lib/gitlab/sidekiq_middleware/server_metrics_shared_context.rb +++ b/spec/support/shared_contexts/lib/gitlab/sidekiq_middleware/server_metrics_shared_context.rb @@ -10,6 +10,7 @@ RSpec.shared_context 'server metrics with mocked prometheus' do let(:gitaly_seconds_metric) { double('gitaly seconds metric') } let(:failed_total_metric) { double('failed total metric') } let(:retried_total_metric) { double('retried total metric') } + let(:interrupted_total_metric) { double('interrupted total metric') } let(:redis_requests_total) { double('redis calls total metric') } let(:running_jobs_metric) { double('running jobs metric') } let(:redis_seconds_metric) { double('redis seconds metric') } @@ -30,6 +31,7 @@ RSpec.shared_context 'server metrics with mocked prometheus' do allow(Gitlab::Metrics).to receive(:histogram).with(:sidekiq_elasticsearch_requests_duration_seconds, anything, anything, anything).and_return(elasticsearch_seconds_metric) allow(Gitlab::Metrics).to receive(:counter).with(:sidekiq_jobs_failed_total, anything).and_return(failed_total_metric) allow(Gitlab::Metrics).to receive(:counter).with(:sidekiq_jobs_retried_total, anything).and_return(retried_total_metric) + allow(Gitlab::Metrics).to receive(:counter).with(:sidekiq_jobs_interrupted_total, anything).and_return(interrupted_total_metric) allow(Gitlab::Metrics).to receive(:counter).with(:sidekiq_redis_requests_total, anything).and_return(redis_requests_total) allow(Gitlab::Metrics).to receive(:counter).with(:sidekiq_elasticsearch_requests_total, anything).and_return(elasticsearch_requests_total) allow(Gitlab::Metrics).to receive(:counter).with(:sidekiq_load_balancing_count, anything).and_return(load_balancing_metric) |