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

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2018-10-25 13:05:20 +0300
committerJacob Vosmaer <jacob@gitlab.com>2018-10-25 13:05:20 +0300
commit37087c89c54f53ffc041f7f00080fa92df3c24de (patch)
tree891862b2f0dd445d6f961476e858f349b3801964
parentd78899872747f42179d3d304a876b2ef7677fb91 (diff)
parent0c0ff5e778da96962af270751bbbf7ab67901cde (diff)
Merge branch 'remote-repository-specs' into 'master'
Add Gitlab::Git::RemoteRepository unit specs See merge request gitlab-org/gitaly!940
-rw-r--r--ruby/Gemfile1
-rw-r--r--ruby/Gemfile.lock35
-rw-r--r--ruby/spec/lib/gitlab/git/remote_repository_spec.rb105
-rw-r--r--ruby/spec/spec_helper.rb1
-rw-r--r--ruby/spec/test_repo_helper.rb6
5 files changed, 148 insertions, 0 deletions
diff --git a/ruby/Gemfile b/ruby/Gemfile
index 269f61d03..7d0776568 100644
--- a/ruby/Gemfile
+++ b/ruby/Gemfile
@@ -24,6 +24,7 @@ gem 'google-protobuf', '~> 3.6'
group :development, :test do
gem 'rubocop', '~> 0.50', require: false
gem 'rspec', require: false
+ gem 'rspec-parameterized', require: false
gem 'timecop', require: false
gem 'factory_bot', require: false
end
diff --git a/ruby/Gemfile.lock b/ruby/Gemfile.lock
index 5afda76e5..e3f0a4c9e 100644
--- a/ruby/Gemfile.lock
+++ b/ruby/Gemfile.lock
@@ -1,16 +1,28 @@
GEM
remote: https://rubygems.org/
specs:
+ abstract_type (0.0.7)
activesupport (5.0.6)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7)
minitest (~> 5.1)
tzinfo (~> 1.1)
+ adamantium (0.2.0)
+ ice_nine (~> 0.11.0)
+ memoizable (~> 0.4.0)
ast (2.4.0)
+ binding_of_caller (0.8.0)
+ debug_inspector (>= 0.0.1)
charlock_holmes (0.7.6)
+ coderay (1.1.2)
+ concord (0.1.5)
+ adamantium (~> 0.2.0)
+ equalizer (~> 0.0.9)
concurrent-ruby (1.0.5)
crass (1.0.4)
+ debug_inspector (0.0.3)
diff-lcs (1.3)
+ equalizer (0.0.11)
escape_utils (1.2.1)
factory_bot (4.11.1)
activesupport (>= 3.0.0)
@@ -53,9 +65,12 @@ GEM
google-protobuf (~> 3.1)
googleapis-common-protos-types (~> 1.0.0)
i18n (0.8.1)
+ ice_nine (0.11.2)
json (2.1.0)
licensee (8.9.2)
rugged (~> 0.24)
+ memoizable (0.4.2)
+ thread_safe (~> 0.3, >= 0.3.1)
mime-types (3.2.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2018.0812)
@@ -71,6 +86,11 @@ GEM
ast (~> 2.4.0)
posix-spawn (0.3.13)
powerpack (0.1.2)
+ proc_to_ast (0.1.0)
+ coderay
+ parser
+ unparser
+ procto (0.0.3)
rainbow (3.0.0)
rdoc (4.3.0)
rouge (3.2.1)
@@ -86,6 +106,12 @@ GEM
rspec-mocks (3.7.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
+ rspec-parameterized (0.4.0)
+ binding_of_caller
+ parser
+ proc_to_ast
+ rspec (>= 2.13, < 4)
+ unparser
rspec-support (3.7.1)
rubocop (0.54.0)
parallel (~> 1.10)
@@ -108,6 +134,14 @@ GEM
tzinfo (1.2.2)
thread_safe (~> 0.1)
unicode-display_width (1.4.0)
+ unparser (0.2.8)
+ abstract_type (~> 0.0.7)
+ adamantium (~> 0.2.0)
+ concord (~> 0.1.5)
+ diff-lcs (~> 1.3)
+ equalizer (~> 0.0.9)
+ parser (>= 2.3.1.2, < 2.6)
+ procto (~> 0.0.2)
PLATFORMS
ruby
@@ -127,6 +161,7 @@ DEPENDENCIES
licensee (~> 8.9.0)
rdoc (~> 4.2)
rspec
+ rspec-parameterized
rubocop (~> 0.50)
rugged (~> 0.27)
sentry-raven (~> 2.7.2)
diff --git a/ruby/spec/lib/gitlab/git/remote_repository_spec.rb b/ruby/spec/lib/gitlab/git/remote_repository_spec.rb
new file mode 100644
index 000000000..93d88f644
--- /dev/null
+++ b/ruby/spec/lib/gitlab/git/remote_repository_spec.rb
@@ -0,0 +1,105 @@
+require 'spec_helper'
+
+describe Gitlab::Git::RemoteRepository, :seed_helper do
+ include TestRepo
+
+ let(:repository) { gitlab_git_from_gitaly(git_test_repo_read_only) }
+ let(:non_existing_gitaly_repo) do
+ Gitaly::Repository.new(storage_name: DEFAULT_STORAGE_NAME, relative_path: 'does-not-exist.git')
+ end
+
+ subject { described_class.new(repository) }
+
+ describe '#empty?' do
+ using RSpec::Parameterized::TableSyntax
+
+ where(:repository, :result) do
+ repository | false
+ gitlab_git_from_gitaly(non_existing_gitaly_repo) | true
+ end
+
+ with_them do
+ it { expect(subject.empty?).to eq(result) }
+ end
+ end
+
+ describe '#commit_id' do
+ it 'returns an OID if the revision exists' do
+ expect(subject.commit_id('v1.0.0')).to eq('6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9')
+ end
+
+ it 'is nil when the revision does not exist' do
+ expect(subject.commit_id('does-not-exist')).to be_nil
+ end
+ end
+
+ describe '#branch_exists?' do
+ using RSpec::Parameterized::TableSyntax
+
+ where(:branch, :result) do
+ 'master' | true
+ 'does-not-exist' | false
+ end
+
+ with_them do
+ it { expect(subject.branch_exists?(branch)).to eq(result) }
+ end
+ end
+
+ describe '#same_repository?' do
+ using RSpec::Parameterized::TableSyntax
+
+ where(:other_repository, :result) do
+ repository | true
+ repository_from_relative_path(repository.relative_path) | true
+ repository_from_relative_path('wrong/relative-path.git') | false
+ end
+
+ with_them do
+ it { expect(subject.same_repository?(other_repository)).to eq(result) }
+ end
+ end
+
+ describe '#fetch_env' do
+ let(:remote_repository) { described_class.new(repository) }
+
+ let(:gitaly_client) { double(:gitaly_client) }
+ let(:address) { 'fake-address' }
+ let(:token) { 'fake-token' }
+
+ subject { remote_repository.fetch_env }
+
+ before do
+ ENV['GITALY_RUBY_GITALY_BIN_DIR'] = __dir__
+
+ allow(remote_repository).to receive(:gitaly_client).and_return(gitaly_client)
+
+ expect(gitaly_client).to receive(:address).with(repository.storage).and_return(address)
+ expect(gitaly_client).to receive(:token).with(repository.storage).and_return(token)
+ end
+
+ it { expect(subject).to be_a(Hash) }
+ it { expect(subject['GITALY_ADDRESS']).to eq(address) }
+ it { expect(subject['GITALY_TOKEN']).to eq(token) }
+ it { expect(subject['GITALY_WD']).to eq(Dir.pwd) }
+
+ it 'creates a plausible GIT_SSH_COMMAND' do
+ git_ssh_command = subject['GIT_SSH_COMMAND']
+
+ expect(git_ssh_command).to start_with('/')
+ expect(git_ssh_command).to end_with('/gitaly-ssh upload-pack')
+ end
+
+ it 'creates a plausible GITALY_PAYLOAD' do
+ req = Gitaly::SSHUploadPackRequest.decode_json(subject['GITALY_PAYLOAD'])
+
+ expect(remote_repository.gitaly_repository).to eq(req.repository)
+ end
+
+ context 'when the token is blank' do
+ let(:token) { '' }
+
+ it { expect(subject.keys).not_to include('GITALY_TOKEN') }
+ end
+ end
+end
diff --git a/ruby/spec/spec_helper.rb b/ruby/spec/spec_helper.rb
index 5a7a6e483..d31f8f8b7 100644
--- a/ruby/spec/spec_helper.rb
+++ b/ruby/spec/spec_helper.rb
@@ -3,6 +3,7 @@ require_relative '../lib/gitlab/git.rb'
require_relative 'support/sentry.rb'
require 'timecop'
require 'test_repo_helper'
+require 'rspec-parameterized'
require 'factory_bot'
Dir[File.join(__dir__, 'support/helpers/*.rb')].each { |f| require f }
diff --git a/ruby/spec/test_repo_helper.rb b/ruby/spec/test_repo_helper.rb
index b3895c29d..f2df1751a 100644
--- a/ruby/spec/test_repo_helper.rb
+++ b/ruby/spec/test_repo_helper.rb
@@ -78,6 +78,12 @@ module TestRepo
)
end
+ def repository_from_relative_path(relative_path)
+ gitlab_git_from_gitaly(
+ Gitaly::Repository.new(storage_name: DEFAULT_STORAGE_NAME, relative_path: relative_path)
+ )
+ end
+
def self.clone_new_repo!(origin, destination)
return if system("git", "clone", "--quiet", "--bare", origin.to_s, destination.to_s)