diff options
author | Zeger-Jan van de Weg <zegerjan@gitlab.com> | 2018-11-05 10:50:58 +0300 |
---|---|---|
committer | Zeger-Jan van de Weg <zegerjan@gitlab.com> | 2018-11-05 10:50:58 +0300 |
commit | 805b98249291cb08045df0aa6aa0b40774433995 (patch) | |
tree | 424657535a49da997ae45c4ccd684b7d7652c53e | |
parent | fa165e3aa294c5da83a549d05c293148a61af715 (diff) | |
parent | 5c03ccee39e0bb35aa984388afa416d25c365336 (diff) |
Merge branch 'more-specs' into 'master'
More specs
See merge request gitlab-org/gitaly!953
-rw-r--r-- | ruby/lib/gitlab/git/operation_service.rb | 5 | ||||
-rw-r--r-- | ruby/lib/gitlab/git/repository.rb | 2 | ||||
-rw-r--r-- | ruby/lib/gitlab/git/tag.rb | 41 | ||||
-rw-r--r-- | ruby/lib/gitlab/git/user.rb | 8 | ||||
-rw-r--r-- | ruby/spec/lib/gitlab/git/blob_spec.rb | 2 | ||||
-rw-r--r-- | ruby/spec/lib/gitlab/git/branch_spec.rb | 2 | ||||
-rw-r--r-- | ruby/spec/lib/gitlab/git/commit_spec.rb | 2 | ||||
-rw-r--r-- | ruby/spec/lib/gitlab/git/lfs_changes_spec.rb | 21 | ||||
-rw-r--r-- | ruby/spec/lib/gitlab/git/raw_diff_change_spec.rb | 68 | ||||
-rw-r--r-- | ruby/spec/lib/gitlab/git/remote_repository_spec.rb | 2 | ||||
-rw-r--r-- | ruby/spec/lib/gitlab/git/repository_spec.rb | 22 | ||||
-rw-r--r-- | ruby/spec/lib/gitlab/git/user_spec.rb | 47 |
12 files changed, 164 insertions, 58 deletions
diff --git a/ruby/lib/gitlab/git/operation_service.rb b/ruby/lib/gitlab/git/operation_service.rb index c7a24958f..649337dd9 100644 --- a/ruby/lib/gitlab/git/operation_service.rb +++ b/ruby/lib/gitlab/git/operation_service.rb @@ -21,10 +21,7 @@ module Gitlab attr_reader :user, :repository def initialize(user, new_repository) - if user - user = Gitlab::Git::User.from_gitlab(user) unless user.respond_to?(:gl_id) - @user = user - end + @user = user # Refactoring aid Gitlab::Git.check_namespace!(new_repository) diff --git a/ruby/lib/gitlab/git/repository.rb b/ruby/lib/gitlab/git/repository.rb index 92f0ddb2a..c2fac6aa7 100644 --- a/ruby/lib/gitlab/git/repository.rb +++ b/ruby/lib/gitlab/git/repository.rb @@ -315,8 +315,6 @@ module Gitlab target_object = Ref.dereference_object(lookup(target)) raise InvalidRef, "target not found: #{target}" unless target_object - user = Gitlab::Git::User.from_gitlab(user) unless user.respond_to?(:gl_id) - options = nil # Use nil, not the empty hash. Rugged cares about this. if message options = { diff --git a/ruby/lib/gitlab/git/tag.rb b/ruby/lib/gitlab/git/tag.rb index 818c1077e..1d7c8e5d2 100644 --- a/ruby/lib/gitlab/git/tag.rb +++ b/ruby/lib/gitlab/git/tag.rb @@ -7,33 +7,10 @@ module Gitlab attr_reader :object_sha, :repository - MAX_TAG_MESSAGE_DISPLAY_SIZE = 10.megabytes SERIALIZE_KEYS = %i[name target target_commit message].freeze attr_accessor *SERIALIZE_KEYS # rubocop:disable Lint/AmbiguousOperator - class << self - def get_message(repository, tag_id) - BatchLoader.for(repository: repository, tag_id: tag_id).batch do |items, loader| - items_by_repo = items.group_by { |i| i[:repository] } - - items_by_repo.each do |_repo, items| - tag_ids = items.map { |i| i[:tag_id] } - - messages = get_messages(repository, tag_ids) - - messages.each do |id, message| - loader.call({ repository: repository, tag_id: id }, message) - end - end - end - end - - def get_messages(repository, tag_ids) - repository.gitaly_ref_client.get_tag_messages(tag_ids) - end - end - def initialize(repository, raw_tag) @repository = repository @raw_tag = raw_tag @@ -59,7 +36,7 @@ module Gitlab def init_from_gitaly @name = encode!(@raw_tag.name.dup) @target = @raw_tag.id - @message = message_from_gitaly_tag + @message = @raw_tag.message.dup @target_commit = Gitlab::Git::Commit.decorate(repository, @raw_tag.target_commit) if @raw_tag.target_commit.present? end @@ -67,22 +44,6 @@ module Gitlab def message encode! @message end - - private - - def message_from_gitaly_tag - return @raw_tag.message.dup if full_message_fetched_from_gitaly? - - if @raw_tag.message_size > MAX_TAG_MESSAGE_DISPLAY_SIZE - '--tag message is too big' - else - self.class.get_message(@repository, target) - end - end - - def full_message_fetched_from_gitaly? - @raw_tag.message.bytesize == @raw_tag.message_size - end end end end diff --git a/ruby/lib/gitlab/git/user.rb b/ruby/lib/gitlab/git/user.rb index 41e14dca8..9ed75f7f7 100644 --- a/ruby/lib/gitlab/git/user.rb +++ b/ruby/lib/gitlab/git/user.rb @@ -3,10 +3,6 @@ module Gitlab class User attr_reader :username, :name, :email, :gl_id - def self.from_gitlab(gitlab_user) - new(gitlab_user.username, gitlab_user.name, gitlab_user.email, Gitlab::GlId.gl_id(gitlab_user)) - end - def self.from_gitaly(gitaly_user) new( gitaly_user.gl_username, @@ -27,10 +23,6 @@ module Gitlab [username, name, email, gl_id] == [other.username, other.name, other.email, other.gl_id] end - def to_gitaly - Gitaly::User.new(gl_username: username, gl_id: gl_id, name: name.b, email: email.b) - end - def git_env { 'GIT_COMMITTER_NAME' => name, diff --git a/ruby/spec/lib/gitlab/git/blob_spec.rb b/ruby/spec/lib/gitlab/git/blob_spec.rb index cfae0ec1d..92ae4b719 100644 --- a/ruby/spec/lib/gitlab/git/blob_spec.rb +++ b/ruby/spec/lib/gitlab/git/blob_spec.rb @@ -1,6 +1,6 @@ require "spec_helper" -describe Gitlab::Git::Blob, :seed_helper do +describe Gitlab::Git::Blob do include TestRepo let(:repository) { gitlab_git_from_gitaly(git_test_repo_read_only) } diff --git a/ruby/spec/lib/gitlab/git/branch_spec.rb b/ruby/spec/lib/gitlab/git/branch_spec.rb index e07755b9a..8d99d2eaa 100644 --- a/ruby/spec/lib/gitlab/git/branch_spec.rb +++ b/ruby/spec/lib/gitlab/git/branch_spec.rb @@ -1,6 +1,6 @@ require "spec_helper" -describe Gitlab::Git::Branch, :seed_helper do +describe Gitlab::Git::Branch do include TestRepo let(:repository) { gitlab_git_from_gitaly(git_test_repo_read_only) } diff --git a/ruby/spec/lib/gitlab/git/commit_spec.rb b/ruby/spec/lib/gitlab/git/commit_spec.rb index b6498f93a..b46346353 100644 --- a/ruby/spec/lib/gitlab/git/commit_spec.rb +++ b/ruby/spec/lib/gitlab/git/commit_spec.rb @@ -1,6 +1,6 @@ require "spec_helper" -describe Gitlab::Git::Commit, :seed_helper do +describe Gitlab::Git::Commit do include TestRepo let(:repository) { gitlab_git_from_gitaly(new_mutable_test_repo) } diff --git a/ruby/spec/lib/gitlab/git/lfs_changes_spec.rb b/ruby/spec/lib/gitlab/git/lfs_changes_spec.rb new file mode 100644 index 000000000..3a5c673be --- /dev/null +++ b/ruby/spec/lib/gitlab/git/lfs_changes_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +describe Gitlab::Git::LfsChanges do + include TestRepo + + let(:repository) { gitlab_git_from_gitaly(new_mutable_test_repo) } + let(:newrev) { '54fcc214b94e78d7a41a9a8fe6d87a5e59500e51' } + let(:blob_object_id) { '0c304a93cb8430108629bbbcaa27db3343299bc0' } + + subject { described_class.new(repository, newrev) } + + describe '#new_pointers' do + it 'filters new objects to find lfs pointers' do + expect(subject.new_pointers(not_in: []).first.id).to eq(blob_object_id) + end + + it 'limits new_objects using object_limit' do + expect(subject.new_pointers(object_limit: 1)).to eq([]) + end + end +end diff --git a/ruby/spec/lib/gitlab/git/raw_diff_change_spec.rb b/ruby/spec/lib/gitlab/git/raw_diff_change_spec.rb new file mode 100644 index 000000000..071b9a21c --- /dev/null +++ b/ruby/spec/lib/gitlab/git/raw_diff_change_spec.rb @@ -0,0 +1,68 @@ +require 'spec_helper' + +describe Gitlab::Git::RawDiffChange do + let(:raw_change) {} + let(:old_mode) { 0o100644 } + let(:new_mode) { 0o100644 } + let(:change) { described_class.new(raw_change, old_mode, new_mode) } + + context 'bad input' do + let(:raw_change) { 'foo' } + + it 'does not set most of the attrs' do + expect(change.blob_id).to eq('foo') + expect(change.operation).to eq(:unknown) + expect(change.old_path).to be_blank + expect(change.new_path).to be_blank + expect(change.blob_size).to eq(0) + end + end + + context 'adding a file' do + let(:raw_change) { '93e123ac8a3e6a0b600953d7598af629dec7b735 59 A bar/branch-test.txt' } + + it 'initialize the proper attrs' do + expect(change.operation).to eq(:added) + expect(change.old_path).to be_blank + expect(change.new_path).to eq('bar/branch-test.txt') + expect(change.blob_id).to be_present + expect(change.blob_size).to be_present + end + end + + context 'renaming a file' do + let(:raw_change) { "85bc2f9753afd5f4fc5d7c75f74f8d526f26b4f3 107 R060\tfiles/js/commit.js.coffee\tfiles/js/commit.coffee" } + + it 'initialize the proper attrs' do + expect(change.operation).to eq(:renamed) + expect(change.old_path).to eq('files/js/commit.js.coffee') + expect(change.new_path).to eq('files/js/commit.coffee') + expect(change.blob_id).to be_present + expect(change.blob_size).to be_present + end + end + + context 'modifying a file' do + let(:raw_change) { 'c60514b6d3d6bf4bec1030f70026e34dfbd69ad5 824 M README.md' } + + it 'initialize the proper attrs' do + expect(change.operation).to eq(:modified) + expect(change.old_path).to eq('README.md') + expect(change.new_path).to eq('README.md') + expect(change.blob_id).to be_present + expect(change.blob_size).to be_present + end + end + + context 'deleting a file' do + let(:raw_change) { '60d7a906c2fd9e4509aeb1187b98d0ea7ce827c9 15364 D files/.DS_Store' } + + it 'initialize the proper attrs' do + expect(change.operation).to eq(:deleted) + expect(change.old_path).to eq('files/.DS_Store') + expect(change.new_path).to be_nil + expect(change.blob_id).to be_present + expect(change.blob_size).to be_present + end + end +end diff --git a/ruby/spec/lib/gitlab/git/remote_repository_spec.rb b/ruby/spec/lib/gitlab/git/remote_repository_spec.rb index 2788f482b..df9468594 100644 --- a/ruby/spec/lib/gitlab/git/remote_repository_spec.rb +++ b/ruby/spec/lib/gitlab/git/remote_repository_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Git::RemoteRepository, :seed_helper do +describe Gitlab::Git::RemoteRepository do include TestRepo let(:repository) { gitlab_git_from_gitaly(git_test_repo_read_only) } diff --git a/ruby/spec/lib/gitlab/git/repository_spec.rb b/ruby/spec/lib/gitlab/git/repository_spec.rb index b6d7e065e..c40e77c19 100644 --- a/ruby/spec/lib/gitlab/git/repository_spec.rb +++ b/ruby/spec/lib/gitlab/git/repository_spec.rb @@ -118,6 +118,28 @@ describe Gitlab::Git::Repository do # rubocop:disable Metrics/BlockLength it { is_expected.not_to include("branch-from-space") } end + describe '#tags' do + describe 'first tag' do + let(:tag) { repository.tags.first } + + it { expect(tag.name).to eq("v1.0.0") } + it { expect(tag.target).to eq("f4e6814c3e4e7a0de82a9e7cd20c626cc963a2f8") } + it { expect(tag.dereferenced_target.sha).to eq("6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9") } + it { expect(tag.message).to eq("Release") } + end + + describe 'last tag' do + let(:tag) { repository.tags.last } + + it { expect(tag.name).to eq("v1.2.1") } + it { expect(tag.target).to eq("2ac1f24e253e08135507d0830508febaaccf02ee") } + it { expect(tag.dereferenced_target.sha).to eq("fa1b1e6c004a68b7d8763b86455da9e6b23e36d6") } + it { expect(tag.message).to eq("Version 1.2.1") } + end + + it { expect(repository.tags.size).to eq(SeedRepo::Repo::TAGS.size) } + end + describe '#empty?' do it { expect(repository).not_to be_empty } end diff --git a/ruby/spec/lib/gitlab/git/user_spec.rb b/ruby/spec/lib/gitlab/git/user_spec.rb new file mode 100644 index 000000000..778fc3c80 --- /dev/null +++ b/ruby/spec/lib/gitlab/git/user_spec.rb @@ -0,0 +1,47 @@ +require 'spec_helper' + +describe Gitlab::Git::User do + let(:username) { 'janedoe' } + let(:name) { 'Jane Doé' } + let(:email) { 'janedoé@example.com' } + let(:gl_id) { 'user-123' } + let(:user) do + described_class.new(username, name, email, gl_id) + end + + subject { described_class.new(username, name, email, gl_id) } + + describe '.from_gitaly' do + let(:gitaly_user) do + Gitaly::User.new(gl_username: username, name: name.b, email: email.b, gl_id: gl_id) + end + + subject { described_class.from_gitaly(gitaly_user) } + + it { expect(subject).to eq(user) } + end + + describe '#==' do + def eq_other(username, name, email, gl_id) + eq(described_class.new(username, name, email, gl_id)) + end + + it { expect(subject).to eq_other(username, name, email, gl_id) } + + it { expect(subject).not_to eq_other(nil, nil, nil, nil) } + it { expect(subject).not_to eq_other(username + 'x', name, email, gl_id) } + it { expect(subject).not_to eq_other(username, name + 'x', email, gl_id) } + it { expect(subject).not_to eq_other(username, name, email + 'x', gl_id) } + it { expect(subject).not_to eq_other(username, name, email, gl_id + 'x') } + end + + describe '#git_env' do + let(:git_env) { subject.git_env } + + it 'returns the user environment variables' do + expect(git_env['GIT_COMMITTER_NAME']).to eq(name) + expect(git_env['GIT_COMMITTER_EMAIL']).to eq(email) + expect(git_env['GL_ID']).to eq(gl_id) + end + end +end |