2013-04-11 16:54:20 -04:00
|
|
|
require 'rspec/mocks'
|
|
|
|
|
2013-04-01 07:39:19 -04:00
|
|
|
module TestEnv
|
|
|
|
extend self
|
|
|
|
|
|
|
|
# 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 16:54:20 -04:00
|
|
|
RSpec::Mocks::setup(self)
|
|
|
|
|
2013-04-11 04:50:58 -04:00
|
|
|
# Disable mailer for spinach tests
|
|
|
|
disable_mailer if opts[:mailer] == false
|
|
|
|
|
2014-07-31 12:24:53 -04:00
|
|
|
# Clean /tmp/tests
|
|
|
|
tmp_test_path = Rails.root.join('tmp', 'tests')
|
2014-07-31 14:01:42 -04:00
|
|
|
|
|
|
|
if File.directory?(tmp_test_path)
|
2014-09-22 13:46:57 -04:00
|
|
|
Dir.entries(tmp_test_path).each do |entry|
|
|
|
|
unless ['.', '..', 'gitlab-shell'].include?(entry)
|
|
|
|
FileUtils.rm_r(File.join(tmp_test_path, entry))
|
|
|
|
end
|
|
|
|
end
|
2014-07-31 14:01:42 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
FileUtils.mkdir_p(tmp_test_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
|
|
|
|
NotificationService.any_instance.unstub(:mailer)
|
2013-04-25 10:15:33 -04:00
|
|
|
end
|
|
|
|
|
2014-07-31 08:39:01 -04:00
|
|
|
def setup_gitlab_shell
|
2014-09-22 13:46:57 -04:00
|
|
|
`rake gitlab:shell:install`
|
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)
|
|
|
|
git_cmd = %W(git clone --bare #{clone_url} #{factory_repo_path})
|
2014-07-31 08:39:01 -04:00
|
|
|
system(*git_cmd)
|
2013-11-12 09:11:46 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-31 08:39:01 -04:00
|
|
|
def copy_repo(project)
|
2014-09-27 03:56:19 -04:00
|
|
|
base_repo_path = File.expand_path(factory_repo_path)
|
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
|
|
|
|
@factory_repo_path ||= repos_path + "/root/#{factory_repo_name}.git"
|
|
|
|
end
|
|
|
|
|
|
|
|
def factory_repo_name
|
|
|
|
'gitlab-test'
|
|
|
|
end
|
2013-04-01 07:39:19 -04:00
|
|
|
end
|