diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-19 17:16:28 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-19 17:16:28 +0300 |
commit | e4384360a16dd9a19d4d2d25d0ef1f2b862ed2a6 (patch) | |
tree | 2fcdfa7dcdb9db8f5208b2562f4b4e803d671243 /spec/lib/gitlab/git/repository_spec.rb | |
parent | ffda4e7bcac36987f936b4ba515995a6698698f0 (diff) |
Add latest changes from gitlab-org/gitlab@16-2-stable-eev16.2.0-rc42
Diffstat (limited to 'spec/lib/gitlab/git/repository_spec.rb')
-rw-r--r-- | spec/lib/gitlab/git/repository_spec.rb | 56 |
1 files changed, 52 insertions, 4 deletions
diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index b137157f2d5..9ce8a674146 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -285,6 +285,28 @@ RSpec.describe Gitlab::Git::Repository, feature_category: :source_code_managemen subject { repository.size } it { is_expected.to be > 0 } + it { is_expected.to be_a(Float) } + + it "uses repository_info for size" do + expect(repository.gitaly_repository_client).to receive(:repository_info).and_call_original + + subject + end + + context "when use_repository_info_for_repository_size feature flag is disabled" do + before do + stub_feature_flags(use_repository_info_for_repository_size: false) + end + + it { is_expected.to be > 0 } + it { is_expected.to be_a(Float) } + + it "uses repository_size for size" do + expect(repository.gitaly_repository_client).to receive(:repository_size).and_call_original + + subject + end + end end describe '#to_s' do @@ -1151,7 +1173,31 @@ RSpec.describe Gitlab::Git::Repository, feature_category: :source_code_managemen commit_result.newrev end - subject { repository.new_blobs(newrevs).to_a } + subject { repository.new_blobs(newrevs) } + + describe 'memoization' do + before do + allow(repository).to receive(:blobs).once.with(["--not", "--all", "--not", "revision1"], kind_of(Hash)) + .and_return(['first result']) + repository.new_blobs(['revision1']) + end + + it 'calls blobs only once' do + expect(repository.new_blobs(['revision1'])).to eq(['first result']) + end + + context 'when called with a different revision' do + before do + allow(repository).to receive(:blobs).once.with(["--not", "--all", "--not", "revision2"], kind_of(Hash)) + .and_return(['second result']) + repository.new_blobs(['revision2']) + end + + it 'memoizes the different arguments' do + expect(repository.new_blobs(['revision2'])).to eq(['second result']) + end + end + end shared_examples '#new_blobs with revisions' do before do @@ -1173,7 +1219,9 @@ RSpec.describe Gitlab::Git::Repository, feature_category: :source_code_managemen it 'memoizes results' do expect(subject).to match_array(expected_blobs) - expect(subject).to match_array(expected_blobs) + + # call subject again + expect(repository.new_blobs(newrevs)).to match_array(expected_blobs) end end @@ -2146,10 +2194,10 @@ RSpec.describe Gitlab::Git::Repository, feature_category: :source_code_managemen expect(repository.refs_by_oid(oid: Gitlab::Git::BLANK_SHA, limit: 0)).to eq([]) end - it 'returns nil for an empty repo' do + it 'returns empty for an empty repo' do project = create(:project) - expect(project.repository.refs_by_oid(oid: TestEnv::BRANCH_SHA['master'], limit: 0)).to be_nil + expect(project.repository.refs_by_oid(oid: TestEnv::BRANCH_SHA['master'], limit: 0)).to eq([]) end end |