diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-24 15:12:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-24 15:12:07 +0300 |
commit | 263baf70a1f64bb773bfb57d74516a008c2bc7e4 (patch) | |
tree | 3fd07a2e7bccc2f6d19a1423c322240bd9808234 /spec | |
parent | 0086677f7cad8c0d7e73d8584ce317f1fce5534e (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/frontend/design_management/components/toolbar/index_spec.js | 2 | ||||
-rw-r--r-- | spec/frontend/pipeline_wizard/components/commit_spec.js | 2 | ||||
-rw-r--r-- | spec/lib/api/helpers/caching_spec.rb | 9 | ||||
-rw-r--r-- | spec/lib/gitlab/audit/auditor_spec.rb | 9 | ||||
-rw-r--r-- | spec/lib/gitlab/cache/helpers_spec.rb | 9 | ||||
-rw-r--r-- | spec/services/merge_requests/create_pipeline_service_spec.rb | 2 | ||||
-rw-r--r-- | spec/support/rspec_order.rb | 5 | ||||
-rw-r--r-- | spec/support/shared_examples/lib/cache_helpers_shared_examples.rb | 117 |
8 files changed, 139 insertions, 16 deletions
diff --git a/spec/frontend/design_management/components/toolbar/index_spec.js b/spec/frontend/design_management/components/toolbar/index_spec.js index b6137ba2eee..1776405ece9 100644 --- a/spec/frontend/design_management/components/toolbar/index_spec.js +++ b/spec/frontend/design_management/components/toolbar/index_spec.js @@ -107,7 +107,7 @@ describe('Design management toolbar component', () => { await nextTick(); wrapper.findComponent(DeleteButton).vm.$emit('delete-selected-designs'); - expect(wrapper.emitted().delete).toBeTruthy(); + expect(wrapper.emitted().delete).toHaveLength(1); }); it('renders download button with correct link', () => { diff --git a/spec/frontend/pipeline_wizard/components/commit_spec.js b/spec/frontend/pipeline_wizard/components/commit_spec.js index c987accbb0d..d7e019c642e 100644 --- a/spec/frontend/pipeline_wizard/components/commit_spec.js +++ b/spec/frontend/pipeline_wizard/components/commit_spec.js @@ -174,7 +174,7 @@ describe('Pipeline Wizard - Commit Page', () => { }); it('will not emit a done event', () => { - expect(wrapper.emitted().done?.length).toBeFalsy(); + expect(wrapper.emitted().done?.length).toBeUndefined(); }); afterEach(() => { diff --git a/spec/lib/api/helpers/caching_spec.rb b/spec/lib/api/helpers/caching_spec.rb index 38b7b386d5c..828af7b5f91 100644 --- a/spec/lib/api/helpers/caching_spec.rb +++ b/spec/lib/api/helpers/caching_spec.rb @@ -33,10 +33,7 @@ RSpec.describe API::Helpers::Caching, :use_clean_rails_redis_caching do end describe "#present_cached" do - subject do - instance.present_cached(presentable, **kwargs) - end - + let(:method) { :present_cached } let(:kwargs) do { with: presenter, @@ -44,6 +41,10 @@ RSpec.describe API::Helpers::Caching, :use_clean_rails_redis_caching do } end + subject do + instance.public_send(method, presentable, **kwargs) + end + context 'single object' do let_it_be(:presentable) { create(:todo, project: project) } diff --git a/spec/lib/gitlab/audit/auditor_spec.rb b/spec/lib/gitlab/audit/auditor_spec.rb index fc5917ca583..f743515e616 100644 --- a/spec/lib/gitlab/audit/auditor_spec.rb +++ b/spec/lib/gitlab/audit/auditor_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' RSpec.describe Gitlab::Audit::Auditor do let(:name) { 'audit_operation' } - let(:author) { create(:user) } + let(:author) { create(:user, :with_sign_ins) } let(:group) { create(:group) } let(:provider) { 'standard' } let(:context) do @@ -37,6 +37,13 @@ RSpec.describe Gitlab::Audit::Auditor do ).and_call_original audit! + + authentication_event = AuthenticationEvent.last + + expect(authentication_event.user).to eq(author) + expect(authentication_event.user_name).to eq(author.name) + expect(authentication_event.ip_address).to eq(author.current_sign_in_ip) + expect(authentication_event.provider).to eq(provider) end it 'logs audit events to database', :aggregate_failures do diff --git a/spec/lib/gitlab/cache/helpers_spec.rb b/spec/lib/gitlab/cache/helpers_spec.rb index 08e0d7729bd..39d37e979b4 100644 --- a/spec/lib/gitlab/cache/helpers_spec.rb +++ b/spec/lib/gitlab/cache/helpers_spec.rb @@ -18,10 +18,7 @@ RSpec.describe Gitlab::Cache::Helpers, :use_clean_rails_redis_caching do end describe "#render_cached" do - subject do - instance.render_cached(presentable, **kwargs) - end - + let(:method) { :render_cached } let(:kwargs) do { with: presenter, @@ -29,6 +26,10 @@ RSpec.describe Gitlab::Cache::Helpers, :use_clean_rails_redis_caching do } end + subject do + instance.public_send(method, presentable, **kwargs) + end + context 'single object' do let_it_be(:presentable) { create(:merge_request, source_project: project, source_branch: 'wip') } diff --git a/spec/services/merge_requests/create_pipeline_service_spec.rb b/spec/services/merge_requests/create_pipeline_service_spec.rb index c443d758a77..dc96b5c0e5e 100644 --- a/spec/services/merge_requests/create_pipeline_service_spec.rb +++ b/spec/services/merge_requests/create_pipeline_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe MergeRequests::CreatePipelineService do +RSpec.describe MergeRequests::CreatePipelineService, :clean_gitlab_redis_cache do include ProjectForksHelper let_it_be(:project, reload: true) { create(:project, :repository) } diff --git a/spec/support/rspec_order.rb b/spec/support/rspec_order.rb index 58f1fe29357..e9a33dd7bea 100644 --- a/spec/support/rspec_order.rb +++ b/spec/support/rspec_order.rb @@ -43,9 +43,6 @@ RSpec.configure do |config| config.on_example_group_definition do |example_group| order = Support::RspecOrder.order_for(example_group) - if order - example_group.metadata[:order] = order.to_sym - example_group.metadata[:description] += " (order #{order})" - end + example_group.metadata[:order] = order.to_sym if order end end diff --git a/spec/support/shared_examples/lib/cache_helpers_shared_examples.rb b/spec/support/shared_examples/lib/cache_helpers_shared_examples.rb index 845fa78a827..495ea931728 100644 --- a/spec/support/shared_examples/lib/cache_helpers_shared_examples.rb +++ b/spec/support/shared_examples/lib/cache_helpers_shared_examples.rb @@ -43,6 +43,54 @@ RSpec.shared_examples_for 'object cache helper' do subject end end + + context 'when a caller id is present' do + let(:transaction) { Gitlab::Metrics::WebTransaction.new({}) } + let(:caller_id) { 'caller_id' } + + before do + allow(::Gitlab::Metrics::WebTransaction).to receive(:current).and_return(transaction) + allow(transaction).to receive(:increment) + allow(Gitlab::ApplicationContext).to receive(:current_context_attribute).with(:caller_id).and_return(caller_id) + end + + context 'when feature flag is off' do + before do + stub_feature_flags(add_timing_to_certain_cache_actions: false) + end + + it 'does not call increment' do + expect(transaction).not_to receive(:increment).with(:cached_object_operations_total, any_args) + + subject + end + + it 'does not call histogram' do + expect(Gitlab::Metrics).not_to receive(:histogram) + + subject + end + + it "is valid JSON" do + parsed = Gitlab::Json.parse(subject.to_s) + + expect(parsed).to be_a(Hash) + expect(parsed["id"]).to eq(presentable.id) + end + end + + it 'increments the counter' do + expect(transaction) + .to receive(:increment) + .with(:cached_object_operations_total, 1, { caller_id: caller_id, render_type: :object, cache_hit: false }).once + + expect(transaction) + .to receive(:increment) + .with(:cached_object_operations_total, 0, { caller_id: caller_id, render_type: :object, cache_hit: true }).once + + subject + end + end end RSpec.shared_examples_for 'collection cache helper' do @@ -98,4 +146,73 @@ RSpec.shared_examples_for 'collection cache helper' do subject end end + + context 'when a caller id is present' do + let(:transaction) { Gitlab::Metrics::WebTransaction.new({}) } + let(:caller_id) { 'caller_id' } + + before do + allow(::Gitlab::Metrics::WebTransaction).to receive(:current).and_return(transaction) + allow(transaction).to receive(:increment) + allow(Gitlab::ApplicationContext).to receive(:current_context_attribute).with(:caller_id).and_return(caller_id) + end + + context 'when feature flag is off' do + before do + stub_feature_flags(add_timing_to_certain_cache_actions: false) + end + + it 'does not call increment' do + expect(transaction).not_to receive(:increment).with(:cached_object_operations_total, any_args) + + subject + end + + it 'does not call histogram' do + expect(Gitlab::Metrics).not_to receive(:histogram) + + subject + end + + it "is valid JSON" do + parsed = Gitlab::Json.parse(subject.to_s) + + expect(parsed).to be_an(Array) + + presentable.each_with_index do |item, i| + expect(parsed[i]["id"]).to eq(item.id) + end + end + end + + context 'when the presentables all miss' do + it 'increments the counters' do + expect(transaction) + .to receive(:increment) + .with(:cached_object_operations_total, 0, { caller_id: caller_id, render_type: :collection, cache_hit: true }).once + + expect(transaction) + .to receive(:increment) + .with(:cached_object_operations_total, presentable.size, { caller_id: caller_id, render_type: :collection, cache_hit: false }).once + + subject + end + end + + context 'when the presents hit' do + it 'increments the counters' do + subject + + expect(transaction) + .to receive(:increment) + .with(:cached_object_operations_total, presentable.size, { caller_id: caller_id, render_type: :collection, cache_hit: true }).once + + expect(transaction) + .to receive(:increment) + .with(:cached_object_operations_total, 0, { caller_id: caller_id, render_type: :collection, cache_hit: false }).once + + instance.public_send(method, presentable, **kwargs) + end + end + end end |