2013-04-11 20:54:20 +00:00
|
|
|
require 'rspec/mocks'
|
|
|
|
|
2013-04-01 11:39:19 +00:00
|
|
|
module TestEnv
|
|
|
|
extend self
|
|
|
|
|
2014-09-29 14:50:20 +00:00
|
|
|
# When developing the seed repository, comment out the branch you will modify.
|
|
|
|
BRANCH_SHA = {
|
2015-01-11 06:48:16 +00:00
|
|
|
'flatten-dir' => 'e56497b',
|
2014-09-29 14:50:20 +00:00
|
|
|
'feature' => '0b4bc9a',
|
|
|
|
'feature_conflict' => 'bb5206f',
|
|
|
|
'fix' => '12d65c8',
|
|
|
|
'improve/awesome' => '5937ac0',
|
|
|
|
'markdown' => '0ed8c6c',
|
|
|
|
'master' => '5937ac0'
|
|
|
|
}
|
|
|
|
|
2013-04-01 11:39:19 +00:00
|
|
|
# Test environment
|
|
|
|
#
|
2014-07-31 12:39:01 +00:00
|
|
|
# See gitlab.yml.example test section for paths
|
2013-04-01 11:39:19 +00:00
|
|
|
#
|
2013-04-10 20:28:42 +00:00
|
|
|
def init(opts = {})
|
2013-04-11 08:50:58 +00:00
|
|
|
# Disable mailer for spinach tests
|
|
|
|
disable_mailer if opts[:mailer] == false
|
|
|
|
|
2014-07-31 16:24:53 +00:00
|
|
|
# Clean /tmp/tests
|
2014-11-18 15:14:36 +00:00
|
|
|
tmp_test_path = Rails.root.join('tmp', 'tests')
|
|
|
|
|
2014-07-31 18:01:42 +00:00
|
|
|
if File.directory?(tmp_test_path)
|
2014-09-22 17:46:57 +00:00
|
|
|
Dir.entries(tmp_test_path).each do |entry|
|
2014-09-29 14:50:20 +00:00
|
|
|
unless ['.', '..', 'gitlab-shell', factory_repo_name].include?(entry)
|
2014-09-22 17:46:57 +00:00
|
|
|
FileUtils.rm_r(File.join(tmp_test_path, entry))
|
|
|
|
end
|
|
|
|
end
|
2014-07-31 18:01:42 +00:00
|
|
|
end
|
|
|
|
|
2014-09-29 14:50:20 +00:00
|
|
|
FileUtils.mkdir_p(repos_path)
|
2014-07-31 16:24:53 +00:00
|
|
|
|
2014-07-31 16:35:07 +00:00
|
|
|
# Setup GitLab shell for test instance
|
|
|
|
setup_gitlab_shell
|
|
|
|
|
2014-07-31 12:39:01 +00:00
|
|
|
# Create repository for FactoryGirl.create(:project)
|
|
|
|
setup_factory_repo
|
2013-04-25 14:15:33 +00:00
|
|
|
end
|
|
|
|
|
2013-06-07 20:39:32 +00:00
|
|
|
def disable_mailer
|
|
|
|
NotificationService.any_instance.stub(mailer: double.as_null_object)
|
2013-04-25 14:15:33 +00:00
|
|
|
end
|
2013-11-07 16:53:35 +00:00
|
|
|
|
2013-06-07 20:39:32 +00:00
|
|
|
def enable_mailer
|
2015-02-12 18:17:35 +00:00
|
|
|
allow_any_instance_of(NotificationService).to receive(:mailer).and_call_original
|
2013-04-25 14:15:33 +00:00
|
|
|
end
|
|
|
|
|
2014-07-31 12:39:01 +00:00
|
|
|
def setup_gitlab_shell
|
2014-09-22 17:46:57 +00:00
|
|
|
`rake gitlab:shell:install`
|
2013-04-25 14:15:33 +00:00
|
|
|
end
|
2013-04-01 11:39:19 +00:00
|
|
|
|
2014-07-31 12:39:01 +00:00
|
|
|
def setup_factory_repo
|
2014-09-27 07:56:19 +00:00
|
|
|
clone_url = "https://gitlab.com/gitlab-org/#{factory_repo_name}.git"
|
2013-04-25 14:15:33 +00:00
|
|
|
|
2014-09-27 07:56:19 +00:00
|
|
|
unless File.directory?(factory_repo_path)
|
2014-09-29 14:50:20 +00:00
|
|
|
system(*%W(git clone #{clone_url} #{factory_repo_path}))
|
|
|
|
end
|
|
|
|
|
|
|
|
Dir.chdir(factory_repo_path) do
|
|
|
|
BRANCH_SHA.each do |branch, sha|
|
|
|
|
# Try to reset without fetching to avoid using the network.
|
|
|
|
reset = %W(git update-ref refs/heads/#{branch} #{sha})
|
|
|
|
unless system(*reset)
|
|
|
|
if system(*%w(git fetch origin))
|
|
|
|
unless system(*reset)
|
|
|
|
raise 'The fetched test seed '\
|
|
|
|
'does not contain the required revision.'
|
|
|
|
end
|
|
|
|
else
|
|
|
|
raise 'Could not fetch test seed repository.'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-11-12 14:11:46 +00:00
|
|
|
end
|
2014-09-29 14:50:20 +00:00
|
|
|
|
|
|
|
# We must copy bare repositories because we will push to them.
|
|
|
|
system(*%W(git clone --bare #{factory_repo_path} #{factory_repo_path_bare}))
|
2013-11-12 14:11:46 +00:00
|
|
|
end
|
|
|
|
|
2014-07-31 12:39:01 +00:00
|
|
|
def copy_repo(project)
|
2014-09-29 14:50:20 +00:00
|
|
|
base_repo_path = File.expand_path(factory_repo_path_bare)
|
2014-07-31 18:30:35 +00:00
|
|
|
target_repo_path = File.expand_path(repos_path + "/#{project.namespace.path}/#{project.path}.git")
|
|
|
|
FileUtils.mkdir_p(target_repo_path)
|
|
|
|
FileUtils.cp_r("#{base_repo_path}/.", target_repo_path)
|
|
|
|
FileUtils.chmod_R 0755, target_repo_path
|
2013-04-01 11:39:19 +00:00
|
|
|
end
|
|
|
|
|
2014-07-31 12:39:01 +00:00
|
|
|
def repos_path
|
|
|
|
Gitlab.config.gitlab_shell.repos_path
|
2013-04-01 11:39:19 +00:00
|
|
|
end
|
2014-09-27 07:56:19 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def factory_repo_path
|
2014-09-29 14:50:20 +00:00
|
|
|
@factory_repo_path ||= Rails.root.join('tmp', 'tests', factory_repo_name)
|
|
|
|
end
|
|
|
|
|
|
|
|
def factory_repo_path_bare
|
|
|
|
factory_repo_path.to_s + '_bare'
|
2014-09-27 07:56:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def factory_repo_name
|
|
|
|
'gitlab-test'
|
|
|
|
end
|
2013-04-01 11:39:19 +00:00
|
|
|
end
|