Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-08-19 12:08:42 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-08-19 12:08:42 +0300
commitb76ae638462ab0f673e5915986070518dd3f9ad3 (patch)
treebdab0533383b52873be0ec0eb4d3c66598ff8b91 /spec/lib/gitlab/git
parent434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff)
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'spec/lib/gitlab/git')
-rw-r--r--spec/lib/gitlab/git/commit_spec.rb12
-rw-r--r--spec/lib/gitlab/git/commit_stats_spec.rb30
-rw-r--r--spec/lib/gitlab/git/conflict/file_spec.rb16
-rw-r--r--spec/lib/gitlab/git/remote_mirror_spec.rb25
-rw-r--r--spec/lib/gitlab/git/repository_spec.rb202
-rw-r--r--spec/lib/gitlab/git/tag_spec.rb83
-rw-r--r--spec/lib/gitlab/git/tree_spec.rb86
7 files changed, 268 insertions, 186 deletions
diff --git a/spec/lib/gitlab/git/commit_spec.rb b/spec/lib/gitlab/git/commit_spec.rb
index 49f1e6e994f..f58bab52cfa 100644
--- a/spec/lib/gitlab/git/commit_spec.rb
+++ b/spec/lib/gitlab/git/commit_spec.rb
@@ -369,11 +369,15 @@ RSpec.describe Gitlab::Git::Commit, :seed_helper do
commits.map { |c| c.id }
end
- it 'has 1 element' do
- expect(subject.size).to eq(1)
+ it { is_expected.to contain_exactly(SeedRepo::Commit::ID) }
+
+ context 'between_uses_list_commits FF disabled' do
+ before do
+ stub_feature_flags(between_uses_list_commits: false)
+ end
+
+ it { is_expected.to contain_exactly(SeedRepo::Commit::ID) }
end
- it { is_expected.to include(SeedRepo::Commit::ID) }
- it { is_expected.not_to include(SeedRepo::FirstCommit::ID) }
end
describe '.shas_with_signatures' do
diff --git a/spec/lib/gitlab/git/commit_stats_spec.rb b/spec/lib/gitlab/git/commit_stats_spec.rb
new file mode 100644
index 00000000000..29d3909efec
--- /dev/null
+++ b/spec/lib/gitlab/git/commit_stats_spec.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+require "spec_helper"
+
+RSpec.describe Gitlab::Git::CommitStats, :seed_helper do
+ let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH, '', 'group/project') }
+ let(:commit) { Gitlab::Git::Commit.find(repository, SeedRepo::Commit::ID) }
+
+ def verify_stats!
+ stats = described_class.new(repository, commit)
+
+ expect(stats).to have_attributes(
+ additions: eq(11),
+ deletions: eq(6),
+ total: eq(17)
+ )
+ end
+
+ it 'returns commit stats and caches them', :use_clean_rails_redis_caching do
+ expect(repository.gitaly_commit_client).to receive(:commit_stats).with(commit.id).and_call_original
+
+ verify_stats!
+
+ expect(Rails.cache.fetch("commit_stats:group/project:#{commit.id}")).to eq([11, 6])
+
+ expect(repository.gitaly_commit_client).not_to receive(:commit_stats)
+
+ verify_stats!
+ end
+end
diff --git a/spec/lib/gitlab/git/conflict/file_spec.rb b/spec/lib/gitlab/git/conflict/file_spec.rb
index 454a48a1d3a..6eb7a7e394e 100644
--- a/spec/lib/gitlab/git/conflict/file_spec.rb
+++ b/spec/lib/gitlab/git/conflict/file_spec.rb
@@ -3,7 +3,7 @@
require 'spec_helper'
RSpec.describe Gitlab::Git::Conflict::File do
- let(:conflict) { { theirs: { path: 'foo', mode: 33188 }, ours: { path: 'foo', mode: 33188 } } }
+ let(:conflict) { { ancestor: { path: 'ancestor' }, theirs: { path: 'foo', mode: 33188 }, ours: { path: 'foo', mode: 33188 } } }
let(:invalid_content) { described_class.new(nil, nil, conflict, (+"a\xC4\xFC").force_encoding(Encoding::ASCII_8BIT)) }
let(:valid_content) { described_class.new(nil, nil, conflict, (+"Espa\xC3\xB1a").force_encoding(Encoding::ASCII_8BIT)) }
@@ -48,4 +48,18 @@ RSpec.describe Gitlab::Git::Conflict::File do
end
end
end
+
+ describe '#path' do
+ it 'returns our_path' do
+ expect(valid_content.path).to eq(conflict[:ours][:path])
+ end
+
+ context 'when our_path is not present' do
+ let(:conflict) { { ancestor: { path: 'ancestor' }, theirs: { path: 'theirs', mode: 33188 }, ours: { path: '', mode: 0 } } }
+
+ it 'returns their_path' do
+ expect(valid_content.path).to eq(conflict[:theirs][:path])
+ end
+ end
+ end
end
diff --git a/spec/lib/gitlab/git/remote_mirror_spec.rb b/spec/lib/gitlab/git/remote_mirror_spec.rb
index 0954879f6bd..4b827e5d2d0 100644
--- a/spec/lib/gitlab/git/remote_mirror_spec.rb
+++ b/spec/lib/gitlab/git/remote_mirror_spec.rb
@@ -6,30 +6,17 @@ RSpec.describe Gitlab::Git::RemoteMirror do
describe '#update' do
let(:project) { create(:project, :repository) }
let(:repository) { project.repository }
- let(:ref_name) { 'foo' }
let(:url) { 'https://example.com' }
let(:options) { { only_branches_matching: ['master'], ssh_key: 'KEY', known_hosts: 'KNOWN HOSTS', keep_divergent_refs: true } }
- subject(:remote_mirror) { described_class.new(repository, ref_name, url, **options) }
+ subject(:remote_mirror) { described_class.new(repository, url, **options) }
- shared_examples 'an update' do
- it 'delegates to the Gitaly client' do
- expect(repository.gitaly_remote_client)
- .to receive(:update_remote_mirror)
- .with(ref_name, url, ['master'], ssh_key: 'KEY', known_hosts: 'KNOWN HOSTS', keep_divergent_refs: true)
-
- remote_mirror.update # rubocop:disable Rails/SaveBang
- end
- end
-
- context 'with url' do
- it_behaves_like 'an update'
- end
-
- context 'without url' do
- let(:url) { nil }
+ it 'delegates to the Gitaly client' do
+ expect(repository.gitaly_remote_client)
+ .to receive(:update_remote_mirror)
+ .with(url, ['master'], ssh_key: 'KEY', known_hosts: 'KNOWN HOSTS', keep_divergent_refs: true)
- it_behaves_like 'an update'
+ remote_mirror.update # rubocop:disable Rails/SaveBang
end
it 'wraps gitaly errors' do
diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb
index 706bcdea291..29e7a1dce1d 100644
--- a/spec/lib/gitlab/git/repository_spec.rb
+++ b/spec/lib/gitlab/git/repository_spec.rb
@@ -491,6 +491,8 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
end
describe '#fetch_remote' do
+ let(:url) { 'http://example.clom' }
+
it 'delegates to the gitaly RepositoryService' do
ssh_auth = double(:ssh_auth)
expected_opts = {
@@ -500,17 +502,17 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
timeout: described_class::GITLAB_PROJECTS_TIMEOUT,
prune: false,
check_tags_changed: false,
- url: nil,
- refmap: nil
+ refmap: nil,
+ http_authorization_header: ""
}
- expect(repository.gitaly_repository_client).to receive(:fetch_remote).with('remote-name', expected_opts)
+ expect(repository.gitaly_repository_client).to receive(:fetch_remote).with(url, expected_opts)
- repository.fetch_remote('remote-name', ssh_auth: ssh_auth, forced: true, no_tags: true, prune: false, check_tags_changed: false)
+ repository.fetch_remote(url, ssh_auth: ssh_auth, forced: true, no_tags: true, prune: false, check_tags_changed: false)
end
it_behaves_like 'wrapping gRPC errors', Gitlab::GitalyClient::RepositoryService, :fetch_remote do
- subject { repository.fetch_remote('remote-name') }
+ subject { repository.fetch_remote(url) }
end
end
@@ -584,29 +586,29 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
expect_any_instance_of(Gitlab::GitalyClient::RemoteService)
.to receive(:find_remote_root_ref).and_call_original
- expect(repository.find_remote_root_ref('origin', SeedHelper::GITLAB_GIT_TEST_REPO_URL)).to eq 'master'
+ expect(repository.find_remote_root_ref(SeedHelper::GITLAB_GIT_TEST_REPO_URL)).to eq 'master'
end
it 'returns UTF-8' do
- expect(repository.find_remote_root_ref('origin', SeedHelper::GITLAB_GIT_TEST_REPO_URL)).to be_utf8
+ expect(repository.find_remote_root_ref(SeedHelper::GITLAB_GIT_TEST_REPO_URL)).to be_utf8
end
it 'returns nil when remote name is nil' do
expect_any_instance_of(Gitlab::GitalyClient::RemoteService)
.not_to receive(:find_remote_root_ref)
- expect(repository.find_remote_root_ref(nil, nil)).to be_nil
+ expect(repository.find_remote_root_ref(nil)).to be_nil
end
it 'returns nil when remote name is empty' do
expect_any_instance_of(Gitlab::GitalyClient::RemoteService)
.not_to receive(:find_remote_root_ref)
- expect(repository.find_remote_root_ref('', '')).to be_nil
+ expect(repository.find_remote_root_ref('')).to be_nil
end
it_behaves_like 'wrapping gRPC errors', Gitlab::GitalyClient::RemoteService, :find_remote_root_ref do
- subject { repository.find_remote_root_ref('origin', SeedHelper::GITLAB_GIT_TEST_REPO_URL) }
+ subject { repository.find_remote_root_ref(SeedHelper::GITLAB_GIT_TEST_REPO_URL) }
end
end
@@ -950,44 +952,23 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
let(:expected_commits) { 1 }
let(:revisions) { [new_commit] }
- shared_examples 'an enumeration of new commits' do
- it 'enumerates commits' do
- commits = repository.new_commits(revisions).to_a
-
- expect(commits.size).to eq(expected_commits)
- commits.each do |commit|
- expect(commit.id).to eq(new_commit)
- expect(commit.message).to eq("Message")
- end
+ before do
+ expect_next_instance_of(Gitlab::GitalyClient::CommitService) do |service|
+ expect(service)
+ .to receive(:list_commits)
+ .with([new_commit, '--not', '--all'])
+ .and_call_original
end
end
- context 'with list_commits disabled' do
- before do
- stub_feature_flags(list_commits: false)
+ it 'enumerates commits' do
+ commits = repository.new_commits(revisions).to_a
- expect_next_instance_of(Gitlab::GitalyClient::RefService) do |service|
- expect(service)
- .to receive(:list_new_commits)
- .with(new_commit)
- .and_call_original
- end
+ expect(commits.size).to eq(expected_commits)
+ commits.each do |commit|
+ expect(commit.id).to eq(new_commit)
+ expect(commit.message).to eq("Message")
end
-
- it_behaves_like 'an enumeration of new commits'
- end
-
- context 'with list_commits enabled' do
- before do
- expect_next_instance_of(Gitlab::GitalyClient::CommitService) do |service|
- expect(service)
- .to receive(:list_commits)
- .with([new_commit, '--not', '--all'])
- .and_call_original
- end
- end
-
- it_behaves_like 'an enumeration of new commits'
end
end
@@ -1750,43 +1731,61 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
end
end
- describe '#write_config' do
- before do
- repository_rugged.config["gitlab.fullpath"] = repository_path
- end
+ describe '#set_full_path' do
+ shared_examples '#set_full_path' do
+ before do
+ repository_rugged.config["gitlab.fullpath"] = repository_path
+ end
- context 'is given a path' do
- it 'writes it to disk' do
- repository.write_config(full_path: "not-the/real-path.git")
+ context 'is given a path' do
+ it 'writes it to disk' do
+ repository.set_full_path(full_path: "not-the/real-path.git")
- config = File.read(File.join(repository_path, "config"))
+ config = File.read(File.join(repository_path, "config"))
- expect(config).to include("[gitlab]")
- expect(config).to include("fullpath = not-the/real-path.git")
+ expect(config).to include("[gitlab]")
+ expect(config).to include("fullpath = not-the/real-path.git")
+ end
end
- end
- context 'it is given an empty path' do
- it 'does not write it to disk' do
- repository.write_config(full_path: "")
+ context 'it is given an empty path' do
+ it 'does not write it to disk' do
+ repository.set_full_path(full_path: "")
- config = File.read(File.join(repository_path, "config"))
+ config = File.read(File.join(repository_path, "config"))
- expect(config).to include("[gitlab]")
- expect(config).to include("fullpath = #{repository_path}")
+ expect(config).to include("[gitlab]")
+ expect(config).to include("fullpath = #{repository_path}")
+ end
+ end
+
+ context 'repository does not exist' do
+ it 'raises NoRepository and does not call Gitaly WriteConfig' do
+ repository = Gitlab::Git::Repository.new('default', 'does/not/exist.git', '', 'group/project')
+
+ expect(repository.gitaly_repository_client).not_to receive(:set_full_path)
+
+ expect do
+ repository.set_full_path(full_path: 'foo/bar.git')
+ end.to raise_error(Gitlab::Git::Repository::NoRepository)
+ end
end
end
- context 'repository does not exist' do
- it 'raises NoRepository and does not call Gitaly WriteConfig' do
- repository = Gitlab::Git::Repository.new('default', 'does/not/exist.git', '', 'group/project')
+ context 'with :set_full_path enabled' do
+ before do
+ stub_feature_flags(set_full_path: true)
+ end
- expect(repository.gitaly_repository_client).not_to receive(:write_config)
+ it_behaves_like '#set_full_path'
+ end
- expect do
- repository.write_config(full_path: 'foo/bar.git')
- end.to raise_error(Gitlab::Git::Repository::NoRepository)
+ context 'with :set_full_path disabled' do
+ before do
+ stub_feature_flags(set_full_path: false)
end
+
+ it_behaves_like '#set_full_path'
end
end
@@ -1813,34 +1812,6 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
end
end
- describe '#delete_config' do
- let(:repository) { mutable_repository }
- let(:entries) do
- {
- 'test.foo1' => 'bla bla',
- 'test.foo2' => 1234,
- 'test.foo3' => true
- }
- end
-
- it 'can delete config settings' do
- entries.each do |key, value|
- repository_rugged.config[key] = value
- end
-
- expect(repository.delete_config(*%w[does.not.exist test.foo1 test.foo2])).to be_nil
-
- # Workaround for https://github.com/libgit2/rugged/issues/785: If
- # Gitaly changes .gitconfig while Rugged has the file loaded
- # Rugged::Repository#each_key will report stale values unless a
- # lookup is done first.
- expect(repository_rugged.config['test.foo1']).to be_nil
- config_keys = repository_rugged.config.each_key.to_a
- expect(config_keys).not_to include('test.foo1')
- expect(config_keys).not_to include('test.foo2')
- end
- end
-
describe '#merge_to_ref' do
let(:repository) { mutable_repository }
let(:branch_head) { '6d394385cf567f80a8fd85055db1ab4c5295806f' }
@@ -2001,47 +1972,6 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
end
end
- describe 'remotes' do
- let(:repository) { mutable_repository }
- let(:remote_name) { 'my-remote' }
- let(:url) { 'http://my-repo.git' }
-
- after do
- ensure_seeds
- end
-
- describe '#add_remote' do
- let(:mirror_refmap) { '+refs/*:refs/*' }
-
- it 'added the remote' do
- begin
- repository_rugged.remotes.delete(remote_name)
- rescue Rugged::ConfigError
- end
-
- repository.add_remote(remote_name, url, mirror_refmap: mirror_refmap)
-
- expect(repository_rugged.remotes[remote_name]).not_to be_nil
- expect(repository_rugged.config["remote.#{remote_name}.mirror"]).to eq('true')
- expect(repository_rugged.config["remote.#{remote_name}.prune"]).to eq('true')
- expect(repository_rugged.config["remote.#{remote_name}.fetch"]).to eq(mirror_refmap)
- end
- end
-
- describe '#remove_remote' do
- it 'removes the remote' do
- repository_rugged.remotes.create(remote_name, url)
-
- expect(repository.remove_remote(remote_name)).to be true
-
- # Since we deleted the remote via Gitaly, Rugged doesn't know
- # this changed underneath it. Let's refresh the Rugged repo.
- repository_rugged = Rugged::Repository.new(repository_path)
- expect(repository_rugged.remotes[remote_name]).to be_nil
- end
- end
- end
-
describe '#bundle_to_disk' do
let(:save_path) { File.join(Dir.tmpdir, "repo-#{SecureRandom.hex}.bundle") }
diff --git a/spec/lib/gitlab/git/tag_spec.rb b/spec/lib/gitlab/git/tag_spec.rb
index b6ff76c5e1c..79ae47f8a7b 100644
--- a/spec/lib/gitlab/git/tag_spec.rb
+++ b/spec/lib/gitlab/git/tag_spec.rb
@@ -38,7 +38,7 @@ RSpec.describe Gitlab::Git::Tag, :seed_helper do
it { expect(tag.tagger.timezone).to eq("+0200") }
end
- describe 'signed tag' do
+ shared_examples 'signed tag' do
let(:project) { create(:project, :repository) }
let(:tag) { project.repository.find_tag('v1.1.1') }
@@ -54,6 +54,18 @@ RSpec.describe Gitlab::Git::Tag, :seed_helper do
it { expect(tag.tagger.timezone).to eq("+0100") }
end
+ context 'with :get_tag_signatures enabled' do
+ it_behaves_like 'signed tag'
+ end
+
+ context 'with :get_tag_signatures disabled' do
+ before do
+ stub_feature_flags(get_tag_signatures: false)
+ end
+
+ it_behaves_like 'signed tag'
+ end
+
it { expect(repository.tags.size).to eq(SeedRepo::Repo::TAGS.size) }
end
@@ -77,6 +89,75 @@ RSpec.describe Gitlab::Git::Tag, :seed_helper do
end
end
+ describe '.extract_signature_lazily' do
+ let(:project) { create(:project, :repository) }
+
+ subject { described_class.extract_signature_lazily(project.repository, tag_id).itself }
+
+ context 'when the tag is signed' do
+ let(:tag_id) { project.repository.find_tag('v1.1.1').id }
+
+ it 'returns signature and signed text' do
+ signature, signed_text = subject
+
+ expect(signature).to eq(X509Helpers::User1.signed_tag_signature.chomp)
+ expect(signature).to be_a_binary_string
+ expect(signed_text).to eq(X509Helpers::User1.signed_tag_base_data)
+ expect(signed_text).to be_a_binary_string
+ end
+ end
+
+ context 'when the tag has no signature' do
+ let(:tag_id) { project.repository.find_tag('v1.0.0').id }
+
+ it 'returns empty signature and message as signed text' do
+ signature, signed_text = subject
+
+ expect(signature).to be_empty
+ expect(signed_text).to eq(X509Helpers::User1.unsigned_tag_base_data)
+ expect(signed_text).to be_a_binary_string
+ end
+ end
+
+ context 'when the tag cannot be found' do
+ let(:tag_id) { Gitlab::Git::BLANK_SHA }
+
+ it 'raises GRPC::Internal' do
+ expect { subject }.to raise_error(GRPC::Internal)
+ end
+ end
+
+ context 'when the tag ID is invalid' do
+ let(:tag_id) { '4b4918a572fa86f9771e5ba40fbd48e' }
+
+ it 'raises GRPC::Internal' do
+ expect { subject }.to raise_error(GRPC::Internal)
+ end
+ end
+
+ context 'when loading signatures in batch once' do
+ it 'fetches signatures in batch once' do
+ tag_ids = [project.repository.find_tag('v1.1.1').id, project.repository.find_tag('v1.0.0').id]
+ signatures = tag_ids.map do |tag_id|
+ described_class.extract_signature_lazily(repository, tag_id)
+ end
+
+ other_repository = double(:repository)
+ described_class.extract_signature_lazily(other_repository, tag_ids.first)
+
+ expect(described_class).to receive(:batch_signature_extraction)
+ .with(repository, tag_ids)
+ .once
+ .and_return({})
+
+ expect(described_class).not_to receive(:batch_signature_extraction)
+ .with(other_repository, tag_ids.first)
+
+ 2.times { signatures.each(&:itself) }
+ end
+ end
+ end
+
describe 'tag into from Gitaly tag' do
context 'message_size != message.size' do
let(:gitaly_tag) { build(:gitaly_tag, message: ''.b, message_size: message_size) }
diff --git a/spec/lib/gitlab/git/tree_spec.rb b/spec/lib/gitlab/git/tree_spec.rb
index c44d7e44751..f11d84bd8d3 100644
--- a/spec/lib/gitlab/git/tree_spec.rb
+++ b/spec/lib/gitlab/git/tree_spec.rb
@@ -6,29 +6,44 @@ RSpec.describe Gitlab::Git::Tree, :seed_helper do
let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH, '', 'group/project') }
shared_examples :repo do
- let(:tree) { Gitlab::Git::Tree.where(repository, SeedRepo::Commit::ID) }
+ subject(:tree) { Gitlab::Git::Tree.where(repository, sha, path, recursive, pagination_params) }
- it { expect(tree).to be_kind_of Array }
- it { expect(tree.empty?).to be_falsey }
- it { expect(tree.count(&:dir?)).to eq(2) }
- it { expect(tree.count(&:file?)).to eq(10) }
- it { expect(tree.count(&:submodule?)).to eq(2) }
+ let(:sha) { SeedRepo::Commit::ID }
+ let(:path) { nil }
+ let(:recursive) { false }
+ let(:pagination_params) { nil }
- it 'returns an empty array when called with an invalid ref' do
- expect(described_class.where(repository, 'foobar-does-not-exist')).to eq([])
+ let(:entries) { tree.first }
+ let(:cursor) { tree.second }
+
+ it { expect(entries).to be_kind_of Array }
+ it { expect(entries.empty?).to be_falsey }
+ it { expect(entries.count(&:dir?)).to eq(2) }
+ it { expect(entries.count(&:file?)).to eq(10) }
+ it { expect(entries.count(&:submodule?)).to eq(2) }
+ it { expect(cursor&.next_cursor).to be_blank }
+
+ context 'with an invalid ref' do
+ let(:sha) { 'foobar-does-not-exist' }
+
+ it { expect(entries).to eq([]) }
+ it { expect(cursor).to be_nil }
end
- it 'returns a list of tree objects' do
- entries = described_class.where(repository, SeedRepo::Commit::ID, 'files', true)
+ context 'when path is provided' do
+ let(:path) { 'files' }
+ let(:recursive) { true }
- expect(entries.map(&:path)).to include('files/html',
- 'files/markdown/ruby-style-guide.md')
- expect(entries.count).to be >= 10
- expect(entries).to all(be_a(Gitlab::Git::Tree))
+ it 'returns a list of tree objects' do
+ expect(entries.map(&:path)).to include('files/html',
+ 'files/markdown/ruby-style-guide.md')
+ expect(entries.count).to be >= 10
+ expect(entries).to all(be_a(Gitlab::Git::Tree))
+ end
end
describe '#dir?' do
- let(:dir) { tree.select(&:dir?).first }
+ let(:dir) { entries.select(&:dir?).first }
it { expect(dir).to be_kind_of Gitlab::Git::Tree }
it { expect(dir.id).to eq('3c122d2b7830eca25235131070602575cf8b41a1') }
@@ -41,7 +56,8 @@ RSpec.describe Gitlab::Git::Tree, :seed_helper do
context :subdir do
# rubocop: disable Rails/FindBy
# This is not ActiveRecord where..first
- let(:subdir) { Gitlab::Git::Tree.where(repository, SeedRepo::Commit::ID, 'files').first }
+ let(:path) { 'files' }
+ let(:subdir) { entries.first }
# rubocop: enable Rails/FindBy
it { expect(subdir).to be_kind_of Gitlab::Git::Tree }
@@ -55,7 +71,8 @@ RSpec.describe Gitlab::Git::Tree, :seed_helper do
context :subdir_file do
# rubocop: disable Rails/FindBy
# This is not ActiveRecord where..first
- let(:subdir_file) { Gitlab::Git::Tree.where(repository, SeedRepo::Commit::ID, 'files/ruby').first }
+ let(:path) { 'files/ruby' }
+ let(:subdir_file) { entries.first }
# rubocop: enable Rails/FindBy
it { expect(subdir_file).to be_kind_of Gitlab::Git::Tree }
@@ -68,10 +85,11 @@ RSpec.describe Gitlab::Git::Tree, :seed_helper do
context :flat_path do
let(:filename) { 'files/flat/path/correct/content.txt' }
- let(:oid) { create_file(filename) }
+ let(:sha) { create_file(filename) }
+ let(:path) { 'files/flat' }
# rubocop: disable Rails/FindBy
# This is not ActiveRecord where..first
- let(:subdir_file) { Gitlab::Git::Tree.where(repository, oid, 'files/flat').first }
+ let(:subdir_file) { entries.first }
# rubocop: enable Rails/FindBy
let(:repository_rugged) { Rugged::Repository.new(File.join(SEED_STORAGE_PATH, TEST_REPO_PATH)) }
@@ -116,7 +134,7 @@ RSpec.describe Gitlab::Git::Tree, :seed_helper do
end
describe '#file?' do
- let(:file) { tree.select(&:file?).first }
+ let(:file) { entries.select(&:file?).first }
it { expect(file).to be_kind_of Gitlab::Git::Tree }
it { expect(file.id).to eq('dfaa3f97ca337e20154a98ac9d0be76ddd1fcc82') }
@@ -125,21 +143,21 @@ RSpec.describe Gitlab::Git::Tree, :seed_helper do
end
describe '#readme?' do
- let(:file) { tree.select(&:readme?).first }
+ let(:file) { entries.select(&:readme?).first }
it { expect(file).to be_kind_of Gitlab::Git::Tree }
it { expect(file.name).to eq('README.md') }
end
describe '#contributing?' do
- let(:file) { tree.select(&:contributing?).first }
+ let(:file) { entries.select(&:contributing?).first }
it { expect(file).to be_kind_of Gitlab::Git::Tree }
it { expect(file.name).to eq('CONTRIBUTING.md') }
end
describe '#submodule?' do
- let(:submodule) { tree.select(&:submodule?).first }
+ let(:submodule) { entries.select(&:submodule?).first }
it { expect(submodule).to be_kind_of Gitlab::Git::Tree }
it { expect(submodule.id).to eq('79bceae69cb5750d6567b223597999bfa91cb3b9') }
@@ -149,7 +167,16 @@ RSpec.describe Gitlab::Git::Tree, :seed_helper do
end
describe '.where with Gitaly enabled' do
- it_behaves_like :repo
+ it_behaves_like :repo do
+ context 'with pagination parameters' do
+ let(:pagination_params) { { limit: 3, page_token: nil } }
+
+ it 'returns paginated list of tree objects' do
+ expect(entries.count).to eq(3)
+ expect(cursor.next_cursor).to be_present
+ end
+ end
+ end
end
describe '.where with Rugged enabled', :enable_rugged do
@@ -161,6 +188,15 @@ RSpec.describe Gitlab::Git::Tree, :seed_helper do
described_class.where(repository, SeedRepo::Commit::ID, 'files', false)
end
- it_behaves_like :repo
+ it_behaves_like :repo do
+ context 'with pagination parameters' do
+ let(:pagination_params) { { limit: 3, page_token: nil } }
+
+ it 'does not support pagination' do
+ expect(entries.count).to be >= 10
+ expect(cursor).to be_nil
+ end
+ end
+ end
end
end