diff options
author | Douwe Maan <douwe@gitlab.com> | 2018-01-23 09:34:59 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-01-23 09:34:59 +0000 |
commit | 09fc32173f8b984f473b58350113634f4b4c0456 (patch) | |
tree | 796e02d6193336fe6e36709426fe13e087a8fe65 /spec | |
parent | 11463bf9ec06ccc5431f09ec19f627648f57c123 (diff) | |
parent | 2e0951e93f15ab3437cb13a1a2be36f45f777c3c (diff) | |
download | gitlab-ce-09fc32173f8b984f473b58350113634f4b4c0456.tar.gz |
Merge branch 'gitaly-user-commit-files' into 'master'
Incorporate Gitaly's OperationService.UserCommitFiles RPC
Closes gitaly#890
See merge request gitlab-org/gitlab-ce!16307
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/git/gitlab_projects_spec.rb | 3 | ||||
-rw-r--r-- | spec/services/files/update_service_spec.rb | 12 | ||||
-rw-r--r-- | spec/spec_helper.rb | 10 | ||||
-rw-r--r-- | spec/support/cycle_analytics_helpers.rb | 31 | ||||
-rw-r--r-- | spec/support/project_forks_helper.rb | 4 |
5 files changed, 48 insertions, 12 deletions
diff --git a/spec/lib/gitlab/git/gitlab_projects_spec.rb b/spec/lib/gitlab/git/gitlab_projects_spec.rb index 78e4fbca28e..f4b964e1ee9 100644 --- a/spec/lib/gitlab/git/gitlab_projects_spec.rb +++ b/spec/lib/gitlab/git/gitlab_projects_spec.rb @@ -219,6 +219,9 @@ describe Gitlab::Git::GitlabProjects do before do FileUtils.mkdir_p(dest_repos_path) + + # Undo spec_helper stub that deletes hooks + allow_any_instance_of(described_class).to receive(:fork_repository).and_call_original end after do diff --git a/spec/services/files/update_service_spec.rb b/spec/services/files/update_service_spec.rb index 43b0c9a63a9..16bfbdf3089 100644 --- a/spec/services/files/update_service_spec.rb +++ b/spec/services/files/update_service_spec.rb @@ -72,13 +72,15 @@ describe Files::UpdateService do end end - context 'when target branch is different than source branch' do - let(:branch_name) { "#{project.default_branch}-new" } + context 'with gitaly disabled', :skip_gitaly_mock do + context 'when target branch is different than source branch' do + let(:branch_name) { "#{project.default_branch}-new" } - it 'fires hooks only once' do - expect(Gitlab::Git::HooksService).to receive(:new).once.and_call_original + it 'fires hooks only once' do + expect(Gitlab::Git::HooksService).to receive(:new).once.and_call_original - subject.execute + subject.execute + end end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6186fb92bad..85de0a14631 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -100,6 +100,16 @@ RSpec.configure do |config| config.before(:example) do # Skip pre-receive hook check so we can use the web editor and merge. allow_any_instance_of(Gitlab::Git::Hook).to receive(:trigger).and_return([true, nil]) + + allow_any_instance_of(Gitlab::Git::GitlabProjects).to receive(:fork_repository).and_wrap_original do |m, *args| + m.call(*args) + + shard_path, repository_relative_path = args + # We can't leave the hooks in place after a fork, as those would fail in tests + # The "internal" API is not available + FileUtils.rm_rf(File.join(shard_path, repository_relative_path, 'hooks')) + end + # Enable all features by default for testing allow(Feature).to receive(:enabled?) { true } end diff --git a/spec/support/cycle_analytics_helpers.rb b/spec/support/cycle_analytics_helpers.rb index 26fd271ce31..d5ef80cfab2 100644 --- a/spec/support/cycle_analytics_helpers.rb +++ b/spec/support/cycle_analytics_helpers.rb @@ -5,10 +5,16 @@ module CycleAnalyticsHelpers end def create_commit(message, project, user, branch_name, count: 1) - oldrev = project.repository.commit(branch_name).sha + repository = project.repository + oldrev = repository.commit(branch_name).sha + + if Timecop.frozen? && Gitlab::GitalyClient.feature_enabled?(:operation_user_commit_files) + mock_gitaly_multi_action_dates(repository.raw) + end + commit_shas = Array.new(count) do |index| - commit_sha = project.repository.create_file(user, generate(:branch), "content", message: message, branch_name: branch_name) - project.repository.commit(commit_sha) + commit_sha = repository.create_file(user, generate(:branch), "content", message: message, branch_name: branch_name) + repository.commit(commit_sha) commit_sha end @@ -98,6 +104,25 @@ module CycleAnalyticsHelpers pipeline: dummy_pipeline, protected: false) end + + def mock_gitaly_multi_action_dates(raw_repository) + allow(raw_repository).to receive(:multi_action).and_wrap_original do |m, *args| + new_date = Time.now + branch_update = m.call(*args) + + if branch_update.newrev + _, opts = args + commit = raw_repository.commit(branch_update.newrev).rugged_commit + branch_update.newrev = commit.amend( + update_ref: "#{Gitlab::Git::BRANCH_REF_PREFIX}#{opts[:branch_name]}", + author: commit.author.merge(time: new_date), + committer: commit.committer.merge(time: new_date) + ) + end + + branch_update + end + end end RSpec.configure do |config| diff --git a/spec/support/project_forks_helper.rb b/spec/support/project_forks_helper.rb index d6680735aa1..2c501a2a27c 100644 --- a/spec/support/project_forks_helper.rb +++ b/spec/support/project_forks_helper.rb @@ -38,10 +38,6 @@ module ProjectForksHelper # so we have to explicitely call this method to clear the @exists variable. # of the instance we're returning here. forked_project.repository.after_import - - # We can't leave the hooks in place after a fork, as those would fail in tests - # The "internal" API is not available - FileUtils.rm_rf("#{forked_project.repository.path}/hooks") end forked_project |