diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-18 15:10:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-18 15:10:09 +0300 |
commit | 4c3f961bd94656e64cee5b0ad07b3f49a84338a5 (patch) | |
tree | eb9afef2d82734c64869ab4a78b99ea6d1805501 /spec/lib | |
parent | 16887b928c9b4f26aabdb2f37ec5fe4ee97e73fe (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/generators/gitlab/analytics/internal_events_generator_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/checks/file_size_check/allow_existing_oversized_blobs_spec.rb | 86 | ||||
-rw-r--r-- | spec/lib/gitlab/checks/file_size_check/any_oversized_blobs_spec.rb (renamed from spec/lib/gitlab/checks/file_size_check/any_oversized_blob_spec.rb) | 11 | ||||
-rw-r--r-- | spec/lib/gitlab/git/finders/refs_finder_spec.rb | 62 | ||||
-rw-r--r-- | spec/lib/gitlab/import_export/all_models.yml | 1 | ||||
-rw-r--r-- | spec/lib/gitlab/usage/metrics/aggregates/aggregate_spec.rb | 5 | ||||
-rw-r--r-- | spec/lib/gitlab/usage_data_metrics_spec.rb | 6 |
7 files changed, 165 insertions, 8 deletions
diff --git a/spec/lib/generators/gitlab/analytics/internal_events_generator_spec.rb b/spec/lib/generators/gitlab/analytics/internal_events_generator_spec.rb index a97695af398..336226c48a1 100644 --- a/spec/lib/generators/gitlab/analytics/internal_events_generator_spec.rb +++ b/spec/lib/generators/gitlab/analytics/internal_events_generator_spec.rb @@ -46,7 +46,7 @@ RSpec.describe Gitlab::Analytics::InternalEventsGenerator, :silence_stdout, feat "milestone" => "13.9", "introduced_by_url" => mr, "time_frame" => "7d", - "data_source" => "redis_hll", + "data_source" => "internal_events", "data_category" => "optional", "instrumentation_class" => "RedisHLLMetric", "distribution" => %w[ce ee], diff --git a/spec/lib/gitlab/checks/file_size_check/allow_existing_oversized_blobs_spec.rb b/spec/lib/gitlab/checks/file_size_check/allow_existing_oversized_blobs_spec.rb new file mode 100644 index 00000000000..3b52d2e1364 --- /dev/null +++ b/spec/lib/gitlab/checks/file_size_check/allow_existing_oversized_blobs_spec.rb @@ -0,0 +1,86 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Checks::FileSizeCheck::AllowExistingOversizedBlobs, feature_category: :source_code_management do + subject { checker.find } + + let_it_be(:project) { create(:project, :public, :repository) } + let(:checker) do + described_class.new( + project: project, + changes: changes, + file_size_limit_megabytes: 1) + end + + describe '#find' do + let(:branch_name) { SecureRandom.uuid } + let(:other_branch_name) { SecureRandom.uuid } + let(:filename) { 'log.log' } + let(:create_file) do + project.repository.create_file( + project.owner, + filename, + initial_contents, + branch_name: branch_name, + message: 'whatever' + ) + end + + let(:changed_ref) do + project.repository.update_file( + project.owner, + filename, + changed_contents, + branch_name: other_branch_name, + start_branch_name: branch_name, + message: 'whatever' + ) + end + + let(:changes) { [oldrev: create_file, newrev: changed_ref] } + + before do + # set up a branch + create_file + + # branch off that branch + changed_ref + + # delete stuff so it can be picked up by new_blobs + project.repository.delete_branch(other_branch_name) + end + + context 'when changing from valid to oversized' do + let(:initial_contents) { 'a' } + let(:changed_contents) { 'a' * ((2**20) + 1) } # 1 MB + 1 byte + + it 'returns an array with blobs that became oversized' do + blob = subject.first + expect(blob.path).to eq(filename) + expect(subject).to contain_exactly(blob) + end + end + + context 'when changing from oversized to oversized' do + let(:initial_contents) { 'a' * ((2**20) + 1) } # 1 MB + 1 byte + let(:changed_contents) { 'a' * ((2**20) + 2) } # 1 MB + 1 byte + + it { is_expected.to be_blank } + end + + context 'when changing from oversized to valid' do + let(:initial_contents) { 'a' * ((2**20) + 1) } # 1 MB + 1 byte + let(:changed_contents) { 'aa' } + + it { is_expected.to be_blank } + end + + context 'when changing from valid to valid' do + let(:initial_contents) { 'abc' } + let(:changed_contents) { 'def' } + + it { is_expected.to be_blank } + end + end +end diff --git a/spec/lib/gitlab/checks/file_size_check/any_oversized_blob_spec.rb b/spec/lib/gitlab/checks/file_size_check/any_oversized_blobs_spec.rb index bf24d6b63c6..7c786c2ba24 100644 --- a/spec/lib/gitlab/checks/file_size_check/any_oversized_blob_spec.rb +++ b/spec/lib/gitlab/checks/file_size_check/any_oversized_blobs_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::Checks::FileSizeCheck::AnyOversizedBlob, feature_category: :source_code_management do +RSpec.describe Gitlab::Checks::FileSizeCheck::AnyOversizedBlobs, feature_category: :source_code_management do let_it_be(:project) { create(:project, :public, :repository) } let(:any_blob) do described_class.new( @@ -11,8 +11,8 @@ RSpec.describe Gitlab::Checks::FileSizeCheck::AnyOversizedBlob, feature_category file_size_limit_megabytes: 1) end - describe '#find!' do - subject { any_blob.find! } + describe '#find' do + subject { any_blob.find } # SHA of the 2-mb-file branch let(:newrev) { 'bf12d2567099e26f59692896f73ac819bae45b00' } @@ -24,9 +24,8 @@ RSpec.describe Gitlab::Checks::FileSizeCheck::AnyOversizedBlob, feature_category end it 'returns the blob exceeding the file size limit' do - blob = subject - expect(blob).to be_kind_of(Gitlab::Git::Blob) - expect(blob.path).to eq('file.bin') + expect(subject).to contain_exactly(kind_of(Gitlab::Git::Blob)) + expect(subject[0].path).to eq('file.bin') end end end diff --git a/spec/lib/gitlab/git/finders/refs_finder_spec.rb b/spec/lib/gitlab/git/finders/refs_finder_spec.rb new file mode 100644 index 00000000000..63d794d1e59 --- /dev/null +++ b/spec/lib/gitlab/git/finders/refs_finder_spec.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +require "spec_helper" + +RSpec.describe Gitlab::Git::Finders::RefsFinder, feature_category: :source_code_management do + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, :repository) } + + let(:repository) { project.repository } + let(:finder) { described_class.new(repository, **params) } + let(:params) { {} } + + describe "#execute" do + subject { finder.execute } + + context "when :ref_type is :branches" do + let(:params) do + { search: "mast", ref_type: :branches } + end + + it { is_expected.to be_an(Array) } + + it "returns matching ref object" do + expect(subject.length).to eq(1) + + ref = subject.first + + expect(ref).to be_a(Gitaly::ListRefsResponse::Reference) + expect(ref.name).to eq("refs/heads/master") + expect(ref.target).to be_a(String) + end + end + + context "when :ref_type is :tags" do + let(:params) do + { search: "v1.0.", ref_type: :tags } + end + + it { is_expected.to be_an(Array) } + + it "returns matching ref object" do + expect(subject.length).to eq(1) + + ref = subject.first + + expect(ref).to be_a(Gitaly::ListRefsResponse::Reference) + expect(ref.name).to eq("refs/tags/v1.0.0") + expect(ref.target).to be_a(String) + end + end + + context "when :ref_type is invalid" do + let(:params) do + { search: "master", ref_type: nil } + end + + it "raises an error" do + expect { subject }.to raise_error(described_class::UnknownRefTypeError) + end + end + end +end diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index aa7d4b84fb5..981802ad09d 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -816,6 +816,7 @@ project: - compliance_standards_adherence - scan_result_policy_reads - project_state +- security_policy_bots award_emoji: - awardable - user diff --git a/spec/lib/gitlab/usage/metrics/aggregates/aggregate_spec.rb b/spec/lib/gitlab/usage/metrics/aggregates/aggregate_spec.rb index 8be0769a379..c3060cd4927 100644 --- a/spec/lib/gitlab/usage/metrics/aggregates/aggregate_spec.rb +++ b/spec/lib/gitlab/usage/metrics/aggregates/aggregate_spec.rb @@ -28,6 +28,10 @@ RSpec.describe Gitlab::Usage::Metrics::Aggregates::Aggregate, :clean_gitlab_redi 7 | 'OR' | 'redis_hll' | :calculate_metrics_union 28 | 'OR' | 'database' | :calculate_metrics_union 7 | 'OR' | 'database' | :calculate_metrics_union + 28 | 'AND' | 'internal_events' | :calculate_metrics_intersections + 7 | 'AND' | 'internal_events' | :calculate_metrics_intersections + 28 | 'OR' | 'internal_events' | :calculate_metrics_union + 7 | 'OR' | 'internal_events' | :calculate_metrics_union end with_them do @@ -152,6 +156,7 @@ RSpec.describe Gitlab::Usage::Metrics::Aggregates::Aggregate, :clean_gitlab_redi where(:time_frame, :operator, :datasource) do '28d' | 'OR' | 'redis_hll' '7d' | 'OR' | 'database' + '28d' | 'OR' | 'internal_events' end with_them do diff --git a/spec/lib/gitlab/usage_data_metrics_spec.rb b/spec/lib/gitlab/usage_data_metrics_spec.rb index e8881e986eb..34e62523d45 100644 --- a/spec/lib/gitlab/usage_data_metrics_spec.rb +++ b/spec/lib/gitlab/usage_data_metrics_spec.rb @@ -62,7 +62,11 @@ RSpec.describe Gitlab::UsageDataMetrics, :with_license, feature_category: :servi let(:metric_files_key_paths) do Gitlab::Usage::MetricDefinition .definitions - .select { |k, v| v.attributes[:data_source] == 'redis_hll' && v.key_path.starts_with?('redis_hll_counters') && v.available? } + .select do |_, v| + (v.data_source == 'redis_hll' || v.data_source == 'internal_events') && + v.key_path.starts_with?('redis_hll_counters') && + v.available? + end .keys .sort end |