2013-04-11 16:54:20 -04:00
|
|
|
require 'rspec/mocks'
|
|
|
|
|
2013-04-01 07:39:19 -04:00
|
|
|
module TestEnv
|
|
|
|
extend self
|
|
|
|
|
2014-09-29 10:50:20 -04:00
|
|
|
# When developing the seed repository, comment out the branch you will modify.
|
|
|
|
BRANCH_SHA = {
|
2015-01-11 01:48:16 -05:00
|
|
|
'flatten-dir' => 'e56497b',
|
2014-09-29 10:50:20 -04:00
|
|
|
'feature' => '0b4bc9a',
|
|
|
|
'feature_conflict' => 'bb5206f',
|
|
|
|
'fix' => '12d65c8',
|
|
|
|
'improve/awesome' => '5937ac0',
|
|
|
|
'markdown' => '0ed8c6c',
|
|
|
|
'master' => '5937ac0'
|
|
|
|
}
|
|
|
|
|
2013-04-01 07:39:19 -04:00
|
|
|
# Test environment
|
|
|
|
#
|
2014-07-31 08:39:01 -04:00
|
|
|
# See gitlab.yml.example test section for paths
|
2013-04-01 07:39:19 -04:00
|
|
|
#
|
2013-04-10 16:28:42 -04:00
|
|
|
def init(opts = {})
|
2013-04-11 04:50:58 -04:00
|
|
|
# Disable mailer for spinach tests
|
|
|
|
disable_mailer if opts[:mailer] == false
|
|
|
|
|
2015-02-03 20:50:30 -05:00
|
|
|
clean_test_path
|
2014-07-31 14:01:42 -04:00
|
|
|
|
2014-09-29 10:50:20 -04:00
|
|
|
FileUtils.mkdir_p(repos_path)
|
2014-07-31 12:24:53 -04:00
|
|
|
|
2014-07-31 12:35:07 -04:00
|
|
|
# Setup GitLab shell for test instance
|
|
|
|
setup_gitlab_shell
|
|
|
|
|
2014-07-31 08:39:01 -04:00
|
|
|
# Create repository for FactoryGirl.create(:project)
|
|
|
|
setup_factory_repo
|
2013-04-25 10:15:33 -04:00
|
|
|
end
|
|
|
|
|
2013-06-07 16:39:32 -04:00
|
|
|
def disable_mailer
|
|
|
|
NotificationService.any_instance.stub(mailer: double.as_null_object)
|
2013-04-25 10:15:33 -04:00
|
|
|
end
|
2013-11-07 11:53:35 -05:00
|
|
|
|
2013-06-07 16:39:32 -04:00
|
|
|
def enable_mailer
|
2015-02-12 13:17:35 -05:00
|
|
|
allow_any_instance_of(NotificationService).to receive(:mailer).and_call_original
|
2013-04-25 10:15:33 -04:00
|
|
|
end
|
|
|
|
|
2015-02-03 20:50:30 -05:00
|
|
|
# Clean /tmp/tests
|
|
|
|
#
|
|
|
|
# Keeps gitlab-shell and gitlab-test
|
|
|
|
def clean_test_path
|
|
|
|
tmp_test_path = Rails.root.join('tmp', 'tests', '**')
|
|
|
|
|
|
|
|
Dir[tmp_test_path].each do |entry|
|
|
|
|
unless File.basename(entry) =~ /\Agitlab-(shell|test)\z/
|
|
|
|
FileUtils.rm_rf(entry)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-31 08:39:01 -04:00
|
|
|
def setup_gitlab_shell
|
2015-02-03 20:50:30 -05:00
|
|
|
unless File.directory?(Rails.root.join(*%w(tmp tests gitlab-shell)))
|
|
|
|
`rake gitlab:shell:install`
|
|
|
|
end
|
2013-04-25 10:15:33 -04:00
|
|
|
end
|
2013-04-01 07:39:19 -04:00
|
|
|
|
2014-07-31 08:39:01 -04:00
|
|
|
def setup_factory_repo
|
2014-09-27 03:56:19 -04:00
|
|
|
clone_url = "https://gitlab.com/gitlab-org/#{factory_repo_name}.git"
|
2013-04-25 10:15:33 -04:00
|
|
|
|
2014-09-27 03:56:19 -04:00
|
|
|
unless File.directory?(factory_repo_path)
|
2015-02-03 20:50:30 -05:00
|
|
|
system(*%W(git clone -q #{clone_url} #{factory_repo_path}))
|
2014-09-29 10:50:20 -04:00
|
|
|
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 09:11:46 -05:00
|
|
|
end
|
2014-09-29 10:50:20 -04:00
|
|
|
|
|
|
|
# We must copy bare repositories because we will push to them.
|
2015-03-27 16:39:41 -04:00
|
|
|
system(git_env, *%W(git clone -q --bare #{factory_repo_path} #{factory_repo_path_bare}))
|
2013-11-12 09:11:46 -05:00
|
|
|
end
|
|
|
|
|
2014-07-31 08:39:01 -04:00
|
|
|
def copy_repo(project)
|
2014-09-29 10:50:20 -04:00
|
|
|
base_repo_path = File.expand_path(factory_repo_path_bare)
|
2014-07-31 14:30:35 -04: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 07:39:19 -04:00
|
|
|
end
|
|
|
|
|
2014-07-31 08:39:01 -04:00
|
|
|
def repos_path
|
|
|
|
Gitlab.config.gitlab_shell.repos_path
|
2013-04-01 07:39:19 -04:00
|
|
|
end
|
2014-09-27 03:56:19 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def factory_repo_path
|
2014-09-29 10:50:20 -04:00
|
|
|
@factory_repo_path ||= Rails.root.join('tmp', 'tests', factory_repo_name)
|
|
|
|
end
|
|
|
|
|
|
|
|
def factory_repo_path_bare
|
2015-02-03 20:50:30 -05:00
|
|
|
"#{factory_repo_path}_bare"
|
2014-09-27 03:56:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def factory_repo_name
|
|
|
|
'gitlab-test'
|
|
|
|
end
|
2015-03-27 16:39:41 -04:00
|
|
|
|
|
|
|
# Prevent developer git configurations from being persisted to test
|
|
|
|
# repositories
|
|
|
|
def git_env
|
|
|
|
{'GIT_TEMPLATE_DIR' => ''}
|
|
|
|
end
|
2013-04-01 07:39:19 -04:00
|
|
|
end
|