From 5fc871381ad0768bb38879ab1621e538ca3008d0 Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Mon, 14 Aug 2017 12:29:47 +0100 Subject: Speed up project creation by inlining repository creation --- spec/lib/gitlab/shell_spec.rb | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'spec') diff --git a/spec/lib/gitlab/shell_spec.rb b/spec/lib/gitlab/shell_spec.rb index 2345874cf10..cfadee0bcf5 100644 --- a/spec/lib/gitlab/shell_spec.rb +++ b/spec/lib/gitlab/shell_spec.rb @@ -94,28 +94,41 @@ describe Gitlab::Shell do end describe 'projects commands' do - let(:projects_path) { 'tmp/tests/shell-projects-test/bin/gitlab-projects' } + let(:gitlab_shell_path) { File.expand_path('tmp/tests/gitlab-shell') } + let(:projects_path) { File.join(gitlab_shell_path, 'bin/gitlab-projects') } + let(:gitlab_shell_hooks_path) { File.join(gitlab_shell_path, 'hooks') } before do - allow(Gitlab.config.gitlab_shell).to receive(:path).and_return('tmp/tests/shell-projects-test') + allow(Gitlab.config.gitlab_shell).to receive(:path).and_return(gitlab_shell_path) + allow(Gitlab.config.gitlab_shell).to receive(:hooks_path).and_return(gitlab_shell_hooks_path) allow(Gitlab.config.gitlab_shell).to receive(:git_timeout).and_return(800) end describe '#add_repository' do - it 'returns true when the command succeeds' do - expect(Gitlab::Popen).to receive(:popen) - .with([projects_path, 'add-project', 'current/storage', 'project/path.git'], - nil, popen_vars).and_return([nil, 0]) + it 'creates a repository' do + created_path = File.join(TestEnv.repos_path, 'project', 'path.git') + hooks_path = File.join(created_path, 'hooks') + + begin + result = gitlab_shell.add_repository(TestEnv.repos_path, 'project/path') + + repo_stat = File.stat(created_path) rescue nil + hooks_stat = File.lstat(hooks_path) rescue nil + hooks_dir = File.realpath(hooks_path) + ensure + FileUtils.rm_rf(created_path) + end - expect(gitlab_shell.add_repository('current/storage', 'project/path')).to be true + expect(result).to be_truthy + expect(repo_stat.mode & 0o777).to eq(0o770) + expect(hooks_stat.symlink?).to be_truthy + expect(hooks_dir).to eq(gitlab_shell_hooks_path) end it 'returns false when the command fails' do - expect(Gitlab::Popen).to receive(:popen) - .with([projects_path, 'add-project', 'current/storage', 'project/path.git'], - nil, popen_vars).and_return(["error", 1]) + expect(FileUtils).to receive(:mkdir_p).and_raise(Errno::EEXIST) - expect(gitlab_shell.add_repository('current/storage', 'project/path')).to be false + expect(gitlab_shell.add_repository('current/storage', 'project/path')).to be_falsy end end -- cgit v1.2.3