Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
iv
gitlab-ce
Commits
f82b9e48
Commit
f82b9e48
authored
Jul 31, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dont stub gitlab-shell calls. Make test environment closer to real one
parent
833bc305
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
140 deletions
+29
-140
config/gitlab.yml.example
config/gitlab.yml.example
+6
-0
features/support/env.rb
features/support/env.rb
+0
-1
spec/factories.rb
spec/factories.rb
+1
-3
spec/support/test_env.rb
spec/support/test_env.rb
+22
-136
No files found.
config/gitlab.yml.example
View file @
f82b9e48
...
...
@@ -259,6 +259,12 @@ test:
gitlab:
host: localhost
port: 80
satellites:
path: tmp/tests/gitlab-satellites/
gitlab_shell:
path: tmp/tests/gitlab-shell/
repos_path: tmp/tests/repositories/
hooks_path: tmp/tests/gitlab-shell/hooks/
issues_tracker:
redmine:
title: "Redmine"
...
...
features/support/env.rb
View file @
f82b9e48
...
...
@@ -39,7 +39,6 @@ Capybara.ignore_hidden_elements = false
DatabaseCleaner
.
strategy
=
:truncation
Spinach
.
hooks
.
before_scenario
do
TestEnv
.
setup_stubs
DatabaseCleaner
.
start
end
...
...
spec/factories.rb
View file @
f82b9e48
...
...
@@ -61,9 +61,7 @@ FactoryGirl.define do
path
{
'gitlabhq'
}
after
:create
do
|
project
|
TestEnv
.
clear_repo_dir
(
project
.
namespace
,
project
.
path
)
TestEnv
.
reset_satellite_dir
TestEnv
.
create_repo
(
project
.
namespace
,
project
.
path
)
TestEnv
.
copy_repo
(
project
)
end
end
...
...
spec/support/test_env.rb
View file @
f82b9e48
...
...
@@ -5,24 +5,19 @@ module TestEnv
# Test environment
#
# all repositories and namespaces stored at
# RAILS_APP/tmp/test-git-base-path
#
# Next shell methods are stubbed and return true
# - mv_repository
# - remove_repository
# - add_key
# - remove_key
# See gitlab.yml.example test section for paths
#
def
init
(
opts
=
{})
RSpec
::
Mocks
::
setup
(
self
)
# Disable mailer for spinach tests
disable_mailer
if
opts
[
:mailer
]
==
false
setup_stubs
clear_test_repo_dir
if
opts
[
:init_repos
]
==
true
setup_test_repos
(
opts
)
if
opts
[
:repos
]
==
true
# Setup GitLab shell for test instance
setup_gitlab_shell
# Create repository for FactoryGirl.create(:project)
setup_factory_repo
end
def
disable_mailer
...
...
@@ -33,139 +28,30 @@ module TestEnv
NotificationService
.
any_instance
.
unstub
(
:mailer
)
end
def
setup_stubs
()
# Use tmp dir for FS manipulations
repos_path
=
testing_path
()
ProjectWiki
.
any_instance
.
stub
(
:init_repo
)
do
|
path
|
create_temp_repo
(
File
.
join
(
repos_path
,
"
#{
path
}
.git"
))
def
setup_gitlab_shell
unless
File
.
directory?
(
Gitlab
.
config
.
gitlab_shell
.
path
)
%x[rake gitlab:shell:install]
end
Gitlab
.
config
.
gitlab_shell
.
stub
(
repos_path:
repos_path
)
Gitlab
.
config
.
satellites
.
stub
(
path:
satellite_path
)
Gitlab
::
Git
::
Repository
.
stub
(
repos_path:
repos_path
)
Gitlab
::
Shell
.
any_instance
.
stub
(
add_repository:
true
,
mv_repository:
true
,
remove_repository:
true
,
update_repository_head:
true
,
add_key:
true
,
remove_key:
true
,
version:
'6.3.0'
)
Gitlab
::
Satellite
::
MergeAction
.
any_instance
.
stub
(
merge!:
true
,
)
Gitlab
::
Satellite
::
Satellite
.
any_instance
.
stub
(
exists?:
true
,
destroy:
true
,
create:
true
,
lock_files_dir:
repos_path
)
MergeRequest
.
any_instance
.
stub
(
check_if_can_be_merged:
true
)
Repository
.
any_instance
.
stub
(
size:
12.45
)
end
def
clear_repo_dir
(
namespace
,
name
)
setup_stubs
# Clean any .wiki.git that may have been created
FileUtils
.
rm_rf
File
.
join
(
testing_path
(),
"
#{
name
}
.wiki.git"
)
end
def
setup_factory_repo
repo_path
=
repos_path
+
"/root/testme.git"
clone_url
=
'https://gitlab.com/gitlab-org/testme.git'
def
reset_satellite_dir
setup_stubs
[
%W(git reset --hard --quiet)
,
%W(git clean -fx --quiet)
,
%W(git checkout --quiet origin/master)
].
each
do
|
git_cmd
|
system
(
*
git_cmd
,
chdir:
seed_satellite_path
)
unless
File
.
directory?
(
repo_path
)
git_cmd
=
%W(git clone --bare
#{
clone_url
}
#{
repo_path
}
)
puts
git_cmd
.
inspect
system
(
*
git_cmd
)
end
end
# Create a repo and it's satellite
def
create_repo
(
namespace
,
name
)
setup_stubs
repo
=
repo
(
namespace
,
name
)
# Symlink tmp/repositories/gitlabhq to tmp/test-git-base-path/gitlabhq
FileUtils
.
ln_sf
(
seed_repo_path
,
repo
)
create_satellite
(
repo
,
namespace
,
name
)
end
private
def
testing_path
Rails
.
root
.
join
(
'tmp'
,
'test-git-base-path'
)
end
def
seed_repo_path
Rails
.
root
.
join
(
'tmp'
,
'repositories'
,
'gitlabhq'
)
end
def
seed_satellite_path
Rails
.
root
.
join
(
'tmp'
,
'satellite'
,
'gitlabhq'
)
end
def
satellite_path
"
#{
testing_path
()
}
/satellite"
end
def
repo
(
namespace
,
name
)
unless
(
namespace
.
nil?
||
namespace
.
path
.
nil?
||
namespace
.
path
.
strip
.
empty?
)
repo
=
File
.
join
(
testing_path
(),
"
#{
namespace
.
path
}
/
#{
name
}
.git"
)
else
repo
=
File
.
join
(
testing_path
(),
"
#{
name
}
.git"
)
end
end
def
satellite
(
namespace
,
name
)
unless
(
namespace
.
nil?
||
namespace
.
path
.
nil?
||
namespace
.
path
.
strip
.
empty?
)
satellite_repo
=
File
.
join
(
satellite_path
,
namespace
.
path
,
name
)
else
satellite_repo
=
File
.
join
(
satellite_path
,
name
)
end
end
def
setup_test_repos
(
opts
=
{})
create_repo
(
nil
,
'gitlabhq'
)
#unless opts[:repo].nil? || !opts[:repo].include?('')
create_repo
(
nil
,
'source_gitlabhq'
)
#unless opts[:repo].nil? || !opts[:repo].include?('source_')
create_repo
(
nil
,
'target_gitlabhq'
)
#unless opts[:repo].nil? || !opts[:repo].include?('target_')
end
def
clear_test_repo_dir
setup_stubs
# Remove tmp/test-git-base-path
FileUtils
.
rm_rf
Gitlab
.
config
.
gitlab_shell
.
repos_path
# Recreate tmp/test-git-base-path
FileUtils
.
mkdir_p
Gitlab
.
config
.
gitlab_shell
.
repos_path
# Since much more is happening in satellites
FileUtils
.
mkdir_p
Gitlab
.
config
.
satellites
.
path
end
# Create a testing satellite, and clone the source repo into it
def
create_satellite
(
source_repo
,
namespace
,
satellite_name
)
satellite_repo
=
satellite
(
namespace
,
satellite_name
)
# Symlink tmp/satellite/gitlabhq to tmp/test-git-base-path/satellite/gitlabhq, create the directory if it doesn't exist already
satellite_dir
=
File
.
dirname
(
satellite_repo
)
FileUtils
.
mkdir_p
(
satellite_dir
)
unless
File
.
exists?
(
satellite_dir
)
FileUtils
.
ln_sf
(
seed_satellite_path
,
satellite_repo
)
def
copy_repo
(
project
)
base_repo_path
=
repos_path
+
"/root/testme.git"
target_repo_path
=
repos_path
+
"/
#{
project
.
namespace
.
path
}
/
#{
project
.
path
}
.git"
FileUtils
.
cp_r
(
base_repo_path
,
target_repo_path
)
end
def
create_temp_repo
(
path
)
FileUtils
.
mkdir_p
path
system
(
*
%W(git init --quiet --bare --
#{
path
}
)
)
def
repos_path
Gitlab
.
config
.
gitlab_shell
.
repos_path
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment