diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-17 18:08:05 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-17 18:08:05 +0000 |
commit | 184c2ced0761bd8dd7032619d16d3983fed7944a (patch) | |
tree | cc82b32ee7c1797509da3cf384617e4ffa2e1733 /spec | |
parent | 238d22c07218adf2b8f3db630ee8b74ca6f29df5 (diff) | |
download | gitlab-ce-184c2ced0761bd8dd7032619d16d3983fed7944a.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/frontend/lib/utils/set_spec.js | 19 | ||||
-rw-r--r-- | spec/frontend/registry/components/table_registry_spec.js | 16 | ||||
-rw-r--r-- | spec/graphql/types/notes/diff_position_type_spec.rb | 2 | ||||
-rw-r--r-- | spec/initializers/lograge_spec.rb | 33 | ||||
-rw-r--r-- | spec/lib/gitlab/cluster/mixins/puma_cluster_spec.rb | 5 | ||||
-rw-r--r-- | spec/lib/gitlab/cluster/mixins/unicorn_http_server_spec.rb | 5 | ||||
-rw-r--r-- | spec/lib/gitlab/metrics/system_spec.rb | 40 | ||||
-rw-r--r-- | spec/mailers/emails/releases_spec.rb | 52 | ||||
-rw-r--r-- | spec/models/ci/build_spec.rb | 10 | ||||
-rw-r--r-- | spec/models/notification_setting_spec.rb | 1 | ||||
-rw-r--r-- | spec/models/release_spec.rb | 20 | ||||
-rw-r--r-- | spec/serializers/build_details_entity_spec.rb | 18 | ||||
-rw-r--r-- | spec/services/notification_service_spec.rb | 21 | ||||
-rw-r--r-- | spec/support/matchers/graphql_matchers.rb | 10 | ||||
-rw-r--r-- | spec/workers/new_release_worker_spec.rb | 13 |
15 files changed, 253 insertions, 12 deletions
diff --git a/spec/frontend/lib/utils/set_spec.js b/spec/frontend/lib/utils/set_spec.js new file mode 100644 index 00000000000..7636a1c634c --- /dev/null +++ b/spec/frontend/lib/utils/set_spec.js @@ -0,0 +1,19 @@ +import { isSubset } from '~/lib/utils/set'; + +describe('utils/set', () => { + describe('isSubset', () => { + it.each` + subset | superset | expected + ${new Set()} | ${new Set()} | ${true} + ${new Set()} | ${new Set([1])} | ${true} + ${new Set([1])} | ${new Set([1])} | ${true} + ${new Set([1, 3])} | ${new Set([1, 2, 3])} | ${true} + ${new Set([1])} | ${new Set()} | ${false} + ${new Set([1])} | ${new Set([2])} | ${false} + ${new Set([7, 8, 9])} | ${new Set([1, 2, 3])} | ${false} + ${new Set([1, 2, 3, 4])} | ${new Set([1, 2, 3])} | ${false} + `('isSubset($subset, $superset) === $expected', ({ subset, superset, expected }) => { + expect(isSubset(subset, superset)).toBe(expected); + }); + }); +}); diff --git a/spec/frontend/registry/components/table_registry_spec.js b/spec/frontend/registry/components/table_registry_spec.js index 600a7a6ee87..7cb7c012d9d 100644 --- a/spec/frontend/registry/components/table_registry_spec.js +++ b/spec/frontend/registry/components/table_registry_spec.js @@ -112,11 +112,13 @@ describe('table registry', () => { Vue.nextTick(() => { const deleteBtn = findDeleteButton(wrapper); - expect(wrapper.vm.itemsToBeDeleted).toEqual([0, 1]); + expect(wrapper.vm.selectedItems).toEqual([0, 1]); expect(deleteBtn.attributes('disabled')).toEqual(undefined); + wrapper.setData({ itemsToBeDeleted: [...wrapper.vm.selectedItems] }); wrapper.vm.handleMultipleDelete(); Vue.nextTick(() => { + expect(wrapper.vm.selectedItems).toEqual([]); expect(wrapper.vm.itemsToBeDeleted).toEqual([]); expect(wrapper.vm.multiDeleteItems).toHaveBeenCalledWith({ path: bulkDeletePath, @@ -143,13 +145,13 @@ describe('table registry', () => { describe('delete registry', () => { beforeEach(() => { - wrapper.setData({ itemsToBeDeleted: [0] }); + wrapper.setData({ selectedItems: [0] }); }); it('should be possible to delete a registry', () => { const deleteBtn = findDeleteButton(wrapper); const deleteBtns = findDeleteButtonsRow(wrapper); - expect(wrapper.vm.itemsToBeDeleted).toEqual([0]); + expect(wrapper.vm.selectedItems).toEqual([0]); expect(deleteBtn).toBeDefined(); expect(deleteBtn.attributes('disable')).toBe(undefined); expect(deleteBtns.is('button')).toBe(true); @@ -212,15 +214,15 @@ describe('table registry', () => { describe('modal content', () => { it('should show the singular title and image name when deleting a single image', () => { - wrapper.setData({ itemsToBeDeleted: [1] }); - wrapper.vm.setModalDescription(0); + wrapper.setData({ selectedItems: [1, 2, 3] }); + wrapper.vm.deleteSingleItem(0); expect(wrapper.vm.modalAction).toBe('Remove tag'); expect(wrapper.vm.modalDescription).toContain(firstImage.tag); }); it('should show the plural title and image count when deleting more than one image', () => { - wrapper.setData({ itemsToBeDeleted: [1, 2] }); - wrapper.vm.setModalDescription(); + wrapper.setData({ selectedItems: [1, 2] }); + wrapper.vm.deleteMultipleItems(); expect(wrapper.vm.modalAction).toBe('Remove tags'); expect(wrapper.vm.modalDescription).toContain('<b>2</b> tags'); diff --git a/spec/graphql/types/notes/diff_position_type_spec.rb b/spec/graphql/types/notes/diff_position_type_spec.rb index 345bca8f702..aa08daaacd4 100644 --- a/spec/graphql/types/notes/diff_position_type_spec.rb +++ b/spec/graphql/types/notes/diff_position_type_spec.rb @@ -7,6 +7,6 @@ describe GitlabSchema.types['DiffPosition'] do :new_path, :position_type, :old_line, :new_line, :x, :y, :width, :height] - is_expected.to have_graphql_field(*expected_fields) + is_expected.to have_graphql_fields(*expected_fields) end end diff --git a/spec/initializers/lograge_spec.rb b/spec/initializers/lograge_spec.rb index 24d366731a2..c2c1960eeab 100644 --- a/spec/initializers/lograge_spec.rb +++ b/spec/initializers/lograge_spec.rb @@ -34,5 +34,38 @@ describe 'lograge', type: :request do subject end + + it 'logs cpu_s on supported platform' do + allow(Gitlab::Metrics::System).to receive(:thread_cpu_time) + .and_return( + 0.111222333, + 0.222333833 + ) + + expect(Lograge.formatter).to receive(:call) + .with(a_hash_including(cpu_s: 0.1111115)) + .and_call_original + + expect(Lograge.logger).to receive(:send) + .with(anything, include('"cpu_s":0.1111115')) + .and_call_original + + subject + end + + it 'does not log cpu_s on unsupported platform' do + allow(Gitlab::Metrics::System).to receive(:thread_cpu_time) + .and_return(nil) + + expect(Lograge.formatter).to receive(:call) + .with(hash_not_including(:cpu_s)) + .and_call_original + + expect(Lograge.logger).not_to receive(:send) + .with(anything, include('"cpu_s":')) + .and_call_original + + subject + end end end diff --git a/spec/lib/gitlab/cluster/mixins/puma_cluster_spec.rb b/spec/lib/gitlab/cluster/mixins/puma_cluster_spec.rb index 038b72075ad..1eddf488c5d 100644 --- a/spec/lib/gitlab/cluster/mixins/puma_cluster_spec.rb +++ b/spec/lib/gitlab/cluster/mixins/puma_cluster_spec.rb @@ -40,7 +40,10 @@ describe Gitlab::Cluster::Mixins::PumaCluster do yield(process.pid) ensure - Process.kill(:KILL, process.pid) unless process.eof? + begin + Process.kill(:KILL, process.pid) + rescue Errno::ESRCH + end end end end diff --git a/spec/lib/gitlab/cluster/mixins/unicorn_http_server_spec.rb b/spec/lib/gitlab/cluster/mixins/unicorn_http_server_spec.rb index 43176e38b2b..2b3a267991c 100644 --- a/spec/lib/gitlab/cluster/mixins/unicorn_http_server_spec.rb +++ b/spec/lib/gitlab/cluster/mixins/unicorn_http_server_spec.rb @@ -54,7 +54,10 @@ describe Gitlab::Cluster::Mixins::UnicornHttpServer do yield(process.pid) ensure - Process.kill(:KILL, process.pid) unless process.eof? + begin + Process.kill(:KILL, process.pid) + rescue Errno::ESRCH + end end end end diff --git a/spec/lib/gitlab/metrics/system_spec.rb b/spec/lib/gitlab/metrics/system_spec.rb index 6d2764a06f2..a5aa80686fd 100644 --- a/spec/lib/gitlab/metrics/system_spec.rb +++ b/spec/lib/gitlab/metrics/system_spec.rb @@ -58,4 +58,44 @@ describe Gitlab::Metrics::System do expect(described_class.monotonic_time).to be_an(Float) end end + + describe '.thread_cpu_time' do + it 'returns cpu_time on supported platform' do + stub_const("Process::CLOCK_THREAD_CPUTIME_ID", 16) + + expect(Process).to receive(:clock_gettime) + .with(16, kind_of(Symbol)) { 0.111222333 } + + expect(described_class.thread_cpu_time).to eq(0.111222333) + end + + it 'returns nil on unsupported platform' do + hide_const("Process::CLOCK_THREAD_CPUTIME_ID") + + expect(described_class.thread_cpu_time).to be_nil + end + end + + describe '.thread_cpu_duration' do + let(:start_time) { described_class.thread_cpu_time } + + it 'returns difference between start and current time' do + stub_const("Process::CLOCK_THREAD_CPUTIME_ID", 16) + + expect(Process).to receive(:clock_gettime) + .with(16, kind_of(Symbol)) + .and_return( + 0.111222333, + 0.222333833 + ) + + expect(described_class.thread_cpu_duration(start_time)).to eq(0.1111115) + end + + it 'returns nil on unsupported platform' do + hide_const("Process::CLOCK_THREAD_CPUTIME_ID") + + expect(described_class.thread_cpu_duration(start_time)).to be_nil + end + end end diff --git a/spec/mailers/emails/releases_spec.rb b/spec/mailers/emails/releases_spec.rb new file mode 100644 index 00000000000..19f404db2a6 --- /dev/null +++ b/spec/mailers/emails/releases_spec.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +require 'spec_helper' +require 'email_spec' + +describe Emails::Releases do + include EmailSpec::Matchers + include_context 'gitlab email notification' + + describe '#new_release_email' do + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project) } + let(:release) { create(:release, project: project) } + + subject { Notify.new_release_email(user.id, release) } + + it_behaves_like 'an email sent from GitLab' + + context 'when the release has a name' do + it 'shows the correct subject' do + expected_subject = "#{release.project.name} | New release: #{release.name} - #{release.tag}" + is_expected.to have_subject(expected_subject) + end + end + + context 'when the release does not have a name' do + it 'shows the correct subject' do + release.name = nil + expected_subject = "#{release.project.name} | New release: #{release.tag}" + + is_expected.to have_subject(expected_subject) + end + end + + it 'contains a message with the new release tag' do + message = "A new Release #{release.tag} for #{release.project.name} was published." + is_expected.to have_body_text(message) + end + + it 'contains the release assets' do + is_expected.to have_body_text('Assets:') + release.sources do |source| + is_expected.to have_body_text("Download #{source.format}") + end + end + + it 'contains the release notes' do + is_expected.to have_body_text('Release notes:') + is_expected.to have_body_text(release.description) + end + end +end diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 26646085921..cd923f50e02 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -3918,4 +3918,14 @@ describe Ci::Build do end end end + + describe '#invalid_dependencies' do + let!(:pre_stage_job_valid) { create(:ci_build, :manual, pipeline: pipeline, name: 'test1', stage_idx: 0) } + let!(:pre_stage_job_invalid) { create(:ci_build, :success, :expired, pipeline: pipeline, name: 'test2', stage_idx: 1) } + let!(:job) { create(:ci_build, :pending, pipeline: pipeline, stage_idx: 2, options: { dependencies: %w(test1 test2) }) } + + it 'returns invalid dependencies' do + expect(job.invalid_dependencies).to eq([pre_stage_job_invalid]) + end + end end diff --git a/spec/models/notification_setting_spec.rb b/spec/models/notification_setting_spec.rb index 820d233dbdc..094c60e3e09 100644 --- a/spec/models/notification_setting_spec.rb +++ b/spec/models/notification_setting_spec.rb @@ -98,6 +98,7 @@ RSpec.describe NotificationSetting do it 'returns email events' do expect(subject).to include( + :new_release, :new_note, :new_issue, :reopen_issue, diff --git a/spec/models/release_spec.rb b/spec/models/release_spec.rb index 64799421eb6..0aac325c2b2 100644 --- a/spec/models/release_spec.rb +++ b/spec/models/release_spec.rb @@ -109,4 +109,24 @@ RSpec.describe Release do end end end + + describe '#notify_new_release' do + context 'when a release is created' do + it 'instantiates NewReleaseWorker to send notifications' do + expect(NewReleaseWorker).to receive(:perform_async) + + create(:release) + end + end + + context 'when a release is updated' do + let!(:release) { create(:release) } + + it 'does not send any new notification' do + expect(NewReleaseWorker).not_to receive(:perform_async) + + release.update!(description: 'new description') + end + end + end end diff --git a/spec/serializers/build_details_entity_spec.rb b/spec/serializers/build_details_entity_spec.rb index f24036cf0c5..6a84694cee9 100644 --- a/spec/serializers/build_details_entity_spec.rb +++ b/spec/serializers/build_details_entity_spec.rb @@ -123,6 +123,24 @@ describe BuildDetailsEntity do end it { is_expected.to include(failure_reason: 'unmet_prerequisites') } + it { is_expected.to include(callout_message: CommitStatusPresenter.callout_failure_messages[:unmet_prerequisites]) } + end + + context 'when the build has failed due to a missing dependency' do + let!(:test1) { create(:ci_build, :success, :expired, pipeline: pipeline, name: 'test1', stage_idx: 0) } + let!(:test2) { create(:ci_build, :success, :expired, pipeline: pipeline, name: 'test2', stage_idx: 1) } + let!(:build) { create(:ci_build, :pending, pipeline: pipeline, stage_idx: 2, options: { dependencies: %w(test1 test2) }) } + let(:message) { subject[:callout_message] } + + before do + build.drop!(:missing_dependency_failure) + end + + it { is_expected.to include(failure_reason: 'missing_dependency_failure') } + + it 'includes the failing dependencies in the callout message' do + expect(message).to include('test2, test1') + end end context 'when a build has environment with latest deployment' do diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb index 70ce05927b4..aa67b87a645 100644 --- a/spec/services/notification_service_spec.rb +++ b/spec/services/notification_service_spec.rb @@ -678,6 +678,27 @@ describe NotificationService, :mailer do end end + describe '#send_new_release_notifications' do + context 'when recipients for a new release exist' do + let(:release) { create(:release) } + + it 'calls new_release_email for each relevant recipient' do + user_1 = create(:user) + user_2 = create(:user) + user_3 = create(:user) + recipient_1 = NotificationRecipient.new(user_1, :custom, custom_action: :new_release) + recipient_2 = NotificationRecipient.new(user_2, :custom, custom_action: :new_release) + allow(NotificationRecipientService).to receive(:build_new_release_recipients).and_return([recipient_1, recipient_2]) + + release + + should_email(user_1) + should_email(user_2) + should_not_email(user_3) + end + end + end + describe 'Participating project notification settings have priority over group and global settings if available' do let!(:group) { create(:group) } let!(:maintainer) { group.add_owner(create(:user, username: 'maintainer')).user } diff --git a/spec/support/matchers/graphql_matchers.rb b/spec/support/matchers/graphql_matchers.rb index 4d48b4b5389..d735c10f698 100644 --- a/spec/support/matchers/graphql_matchers.rb +++ b/spec/support/matchers/graphql_matchers.rb @@ -28,9 +28,15 @@ RSpec::Matchers.define :have_graphql_fields do |*expected| end end -RSpec::Matchers.define :have_graphql_field do |field_name| +RSpec::Matchers.define :have_graphql_field do |field_name, args = {}| match do |kls| - expect(kls.fields.keys).to include(GraphqlHelpers.fieldnamerize(field_name)) + field = kls.fields[GraphqlHelpers.fieldnamerize(field_name)] + + expect(field).to be_present + + args.each do |argument, value| + expect(field.send(argument)).to eq(value) + end end end diff --git a/spec/workers/new_release_worker_spec.rb b/spec/workers/new_release_worker_spec.rb new file mode 100644 index 00000000000..9010c36f795 --- /dev/null +++ b/spec/workers/new_release_worker_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe NewReleaseWorker do + let(:release) { create(:release) } + + it 'sends a new release notification' do + expect_any_instance_of(NotificationService).to receive(:send_new_release_notifications).with(release) + + described_class.new.perform(release.id) + end +end |