Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-shell
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
nexedi
gitlab-shell
Commits
e60a0ee7
Commit
e60a0ee7
authored
Nov 09, 2016
by
Elan Ruusamäe
Committed by
Sean McGivern
Dec 01, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
spec: updated tests to match current code
parent
dbd4bc26
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
37 deletions
+67
-37
Gemfile.lock
Gemfile.lock
+0
-3
spec/gitlab_custom_hook_spec.rb
spec/gitlab_custom_hook_spec.rb
+67
-34
No files found.
Gemfile.lock
View file @
e60a0ee7
...
@@ -81,6 +81,3 @@ DEPENDENCIES
...
@@ -81,6 +81,3 @@ DEPENDENCIES
rubocop (= 0.28.0)
rubocop (= 0.28.0)
vcr
vcr
webmock
webmock
BUNDLED WITH
1.11.2
spec/gitlab_custom_hook_spec.rb
View file @
e60a0ee7
...
@@ -16,14 +16,34 @@ describe GitlabCustomHook do
...
@@ -16,14 +16,34 @@ describe GitlabCustomHook do
let
(
:gitlab_custom_hook
)
{
GitlabCustomHook
.
new
(
tmp_repo_path
,
'key_1'
)
}
let
(
:gitlab_custom_hook
)
{
GitlabCustomHook
.
new
(
tmp_repo_path
,
'key_1'
)
}
# setup paths
# <repository>.git/hooks/ - symlink to gitlab-shell/hooks global dir
# <repository>.git/hooks/<hook_name> - executed by git itself, this is gitlab-shell/hooks/<hook_name>
# <repository>.git/hooks/<hook_name>.d/* - global hooks: all executable files (minus editor backup files)
# <repository>.git/custom_hooks/<hook_name> - per project hook (this is already existing behavior)
# <repository>.git/custom_hooks/<hook_name>.d/* - per project hooks
#
# custom hooks are invoked in such way that first failure prevents other scripts being ran
# as global scripts are ran first, failing global skips repo hooks
before
do
before
do
FileUtils
.
mkdir_p
(
File
.
join
(
tmp_root_path
,
'hooks'
))
FileUtils
.
mkdir_p
(
File
.
join
(
tmp_root_path
,
'hooks'
,
'update.d'
))
FileUtils
.
mkdir_p
(
File
.
join
(
tmp_root_path
,
'hooks'
,
'pre-receive.d'
))
FileUtils
.
mkdir_p
(
File
.
join
(
tmp_root_path
,
'hooks'
,
'post-receive.d'
))
FileUtils
.
symlink
(
File
.
join
(
tmp_root_path
,
'hooks'
),
File
.
join
(
tmp_repo_path
,
'hooks'
))
FileUtils
.
mkdir_p
(
File
.
join
(
tmp_repo_path
,
'custom_hooks'
))
FileUtils
.
mkdir_p
(
File
.
join
(
tmp_repo_path
,
'custom_hooks'
))
FileUtils
.
mkdir_p
(
File
.
join
(
tmp_root_path
,
'custom_hooks'
))
FileUtils
.
mkdir_p
(
File
.
join
(
tmp_repo_path
,
'custom_hooks'
,
'update.d'
))
FileUtils
.
mkdir_p
(
File
.
join
(
tmp_repo_path
,
'custom_hooks'
,
'pre-receive.d'
))
FileUtils
.
mkdir_p
(
File
.
join
(
tmp_repo_path
,
'custom_hooks'
,
'post-receive.d'
))
end
end
after
do
after
do
FileUtils
.
rm_rf
(
File
.
join
(
tmp_repo_path
,
'custom_hooks'
))
FileUtils
.
rm_rf
(
File
.
join
(
tmp_repo_path
,
'custom_hooks'
))
FileUtils
.
rm_rf
(
File
.
join
(
tmp_root_path
,
'custom_hooks'
))
FileUtils
.
rm_rf
(
File
.
join
(
tmp_repo_path
,
'hooks'
))
FileUtils
.
rm_rf
(
File
.
join
(
tmp_repo_path
,
'hooks.d'
))
FileUtils
.
rm_rf
(
File
.
join
(
tmp_root_path
,
'hooks'
))
end
end
context
'with gl_id_test_hook'
do
context
'with gl_id_test_hook'
do
...
@@ -56,7 +76,6 @@ describe GitlabCustomHook do
...
@@ -56,7 +76,6 @@ describe GitlabCustomHook do
context
"having no hooks"
do
context
"having no hooks"
do
it
"returns true"
do
it
"returns true"
do
stub_const
(
"ROOT_PATH"
,
tmp_root_path
)
expect
(
gitlab_custom_hook
.
pre_receive
(
changes
)).
to
eq
(
true
)
expect
(
gitlab_custom_hook
.
pre_receive
(
changes
)).
to
eq
(
true
)
expect
(
gitlab_custom_hook
.
update
(
ref_name
,
old_value
,
new_value
)).
to
eq
(
true
)
expect
(
gitlab_custom_hook
.
update
(
ref_name
,
old_value
,
new_value
)).
to
eq
(
true
)
expect
(
gitlab_custom_hook
.
post_receive
(
changes
)).
to
eq
(
true
)
expect
(
gitlab_custom_hook
.
post_receive
(
changes
)).
to
eq
(
true
)
...
@@ -65,11 +84,10 @@ describe GitlabCustomHook do
...
@@ -65,11 +84,10 @@ describe GitlabCustomHook do
context
"having only ok repo hooks"
do
context
"having only ok repo hooks"
do
before
do
before
do
create_hooks
(
tmp_repo_path
,
hook_ok
)
create_
repo_
hooks
(
tmp_repo_path
,
hook_ok
)
end
end
it
"returns true"
do
it
"returns true"
do
stub_const
(
"ROOT_PATH"
,
tmp_root_path
)
expect
(
gitlab_custom_hook
.
pre_receive
(
changes
)).
to
eq
(
true
)
expect
(
gitlab_custom_hook
.
pre_receive
(
changes
)).
to
eq
(
true
)
expect
(
gitlab_custom_hook
.
update
(
ref_name
,
old_value
,
new_value
)).
to
eq
(
true
)
expect
(
gitlab_custom_hook
.
update
(
ref_name
,
old_value
,
new_value
)).
to
eq
(
true
)
expect
(
gitlab_custom_hook
.
post_receive
(
changes
)).
to
eq
(
true
)
expect
(
gitlab_custom_hook
.
post_receive
(
changes
)).
to
eq
(
true
)
...
@@ -78,12 +96,11 @@ describe GitlabCustomHook do
...
@@ -78,12 +96,11 @@ describe GitlabCustomHook do
context
"having both ok repo and global hooks"
do
context
"having both ok repo and global hooks"
do
before
do
before
do
create_hooks
(
tmp_repo_path
,
hook_ok
)
create_
repo_
hooks
(
tmp_repo_path
,
hook_ok
)
create_
hooks
(
tmp_root_path
,
hook_ok
)
create_
global_hooks_d
(
tmp_root_path
,
hook_ok
)
end
end
it
"returns true"
do
it
"returns true"
do
stub_const
(
"ROOT_PATH"
,
tmp_root_path
)
expect
(
gitlab_custom_hook
.
pre_receive
(
changes
)).
to
eq
(
true
)
expect
(
gitlab_custom_hook
.
pre_receive
(
changes
)).
to
eq
(
true
)
expect
(
gitlab_custom_hook
.
update
(
ref_name
,
old_value
,
new_value
)).
to
eq
(
true
)
expect
(
gitlab_custom_hook
.
update
(
ref_name
,
old_value
,
new_value
)).
to
eq
(
true
)
expect
(
gitlab_custom_hook
.
post_receive
(
changes
)).
to
eq
(
true
)
expect
(
gitlab_custom_hook
.
post_receive
(
changes
)).
to
eq
(
true
)
...
@@ -92,29 +109,27 @@ describe GitlabCustomHook do
...
@@ -92,29 +109,27 @@ describe GitlabCustomHook do
context
"having failing repo and ok global hooks"
do
context
"having failing repo and ok global hooks"
do
before
do
before
do
create_
hooks
(
tmp_repo_path
,
hook_fail
)
create_
repo_hooks_d
(
tmp_repo_path
,
hook_fail
)
create_
hooks
(
tmp_root
_path
,
hook_ok
)
create_
global_hooks_d
(
tmp_repo
_path
,
hook_ok
)
end
end
it
"returns false"
do
it
"returns false"
do
stub_const
(
"ROOT_PATH"
,
tmp_root_path
)
expect
(
gitlab_custom_hook
.
pre_receive
(
changes
)).
to
eq
(
false
)
expect
(
gitlab_custom_hook
.
pre_receive
(
changes
)).
to
eq
(
false
)
expect
(
gitlab_custom_hook
.
update
(
ref_name
,
old_value
,
new_value
)).
to
eq
(
false
)
expect
(
gitlab_custom_hook
.
update
(
ref_name
,
old_value
,
new_value
)).
to
eq
(
false
)
expect
(
gitlab_custom_hook
.
post_receive
(
changes
)).
to
eq
(
false
)
expect
(
gitlab_custom_hook
.
post_receive
(
changes
)).
to
eq
(
false
)
end
end
it
"only executes the
repo
hook"
do
it
"only executes the
global
hook"
do
expect
(
gitlab_custom_hook
).
to
receive
(
:call_receive_hook
)
expect
(
gitlab_custom_hook
).
to
receive
(
:call_receive_hook
)
.
with
(
hook_path
(
tmp_repo_path
,
"
pre-receive
"
),
changes
)
.
with
(
hook_path
(
tmp_repo_path
,
"
custom_hooks/pre-receive.d/hook
"
),
changes
)
.
and_call_original
.
and_call_original
expect
(
gitlab_custom_hook
).
to
receive
(
:system
)
expect
(
gitlab_custom_hook
).
to
receive
(
:system
)
.
with
(
vars
,
hook_path
(
tmp_repo_path
,
"
update
"
),
ref_name
,
old_value
,
new_value
)
.
with
(
vars
,
hook_path
(
tmp_repo_path
,
"
custom_hooks/update.d/hook
"
),
ref_name
,
old_value
,
new_value
)
.
and_call_original
.
and_call_original
expect
(
gitlab_custom_hook
).
to
receive
(
:call_receive_hook
)
expect
(
gitlab_custom_hook
).
to
receive
(
:call_receive_hook
)
.
with
(
hook_path
(
tmp_repo_path
,
"
post-receive
"
),
changes
)
.
with
(
hook_path
(
tmp_repo_path
,
"
custom_hooks/post-receive.d/hook
"
),
changes
)
.
and_call_original
.
and_call_original
stub_const
(
"ROOT_PATH"
,
tmp_root_path
)
gitlab_custom_hook
.
pre_receive
(
changes
)
gitlab_custom_hook
.
pre_receive
(
changes
)
gitlab_custom_hook
.
update
(
ref_name
,
old_value
,
new_value
)
gitlab_custom_hook
.
update
(
ref_name
,
old_value
,
new_value
)
gitlab_custom_hook
.
post_receive
(
changes
)
gitlab_custom_hook
.
post_receive
(
changes
)
...
@@ -123,12 +138,11 @@ describe GitlabCustomHook do
...
@@ -123,12 +138,11 @@ describe GitlabCustomHook do
context
"having ok repo but failing global hooks"
do
context
"having ok repo but failing global hooks"
do
before
do
before
do
create_
hooks
(
tmp_repo_path
,
hook_ok
)
create_
repo_hooks_d
(
tmp_repo_path
,
hook_ok
)
create_
hooks
(
tmp_root
_path
,
hook_fail
)
create_
global_hooks_d
(
tmp_repo
_path
,
hook_fail
)
end
end
it
"returns false"
do
it
"returns false"
do
stub_const
(
"ROOT_PATH"
,
tmp_root_path
)
expect
(
gitlab_custom_hook
.
pre_receive
(
changes
)).
to
eq
(
false
)
expect
(
gitlab_custom_hook
.
pre_receive
(
changes
)).
to
eq
(
false
)
expect
(
gitlab_custom_hook
.
update
(
ref_name
,
old_value
,
new_value
)).
to
eq
(
false
)
expect
(
gitlab_custom_hook
.
update
(
ref_name
,
old_value
,
new_value
)).
to
eq
(
false
)
expect
(
gitlab_custom_hook
.
post_receive
(
changes
)).
to
eq
(
false
)
expect
(
gitlab_custom_hook
.
post_receive
(
changes
)).
to
eq
(
false
)
...
@@ -136,42 +150,61 @@ describe GitlabCustomHook do
...
@@ -136,42 +150,61 @@ describe GitlabCustomHook do
it
"executes the relevant hooks"
do
it
"executes the relevant hooks"
do
expect
(
gitlab_custom_hook
).
to
receive
(
:call_receive_hook
)
expect
(
gitlab_custom_hook
).
to
receive
(
:call_receive_hook
)
.
with
(
hook_path
(
tmp_repo_path
,
"
pre-receive
"
),
changes
)
.
with
(
hook_path
(
tmp_repo_path
,
"
hooks/pre-receive.d/hook
"
),
changes
)
.
and_call_original
.
and_call_original
expect
(
gitlab_custom_hook
).
to
receive
(
:call_receive_hook
)
expect
(
gitlab_custom_hook
).
to
receive
(
:call_receive_hook
)
.
with
(
hook_path
(
tmp_r
oot_path
,
"pre-receive
"
),
changes
)
.
with
(
hook_path
(
tmp_r
epo_path
,
"custom_hooks/pre-receive.d/hook
"
),
changes
)
.
and_call_original
.
and_call_original
expect
(
gitlab_custom_hook
).
to
receive
(
:system
)
expect
(
gitlab_custom_hook
).
to
receive
(
:system
)
.
with
(
vars
,
hook_path
(
tmp_repo_path
,
"
update
"
),
ref_name
,
old_value
,
new_value
)
.
with
(
vars
,
hook_path
(
tmp_repo_path
,
"
hooks/update.d/hook
"
),
ref_name
,
old_value
,
new_value
)
.
and_call_original
.
and_call_original
expect
(
gitlab_custom_hook
).
to
receive
(
:system
)
expect
(
gitlab_custom_hook
).
to
receive
(
:system
)
.
with
(
vars
,
hook_path
(
tmp_r
oot_path
,
"update
"
),
ref_name
,
old_value
,
new_value
)
.
with
(
vars
,
hook_path
(
tmp_r
epo_path
,
"custom_hooks/update.d/hook
"
),
ref_name
,
old_value
,
new_value
)
.
and_call_original
.
and_call_original
expect
(
gitlab_custom_hook
).
to
receive
(
:call_receive_hook
)
expect
(
gitlab_custom_hook
).
to
receive
(
:call_receive_hook
)
.
with
(
hook_path
(
tmp_repo_path
,
"
post-receive
"
),
changes
)
.
with
(
hook_path
(
tmp_repo_path
,
"
hooks/post-receive.d/hook
"
),
changes
)
.
and_call_original
.
and_call_original
expect
(
gitlab_custom_hook
).
to
receive
(
:call_receive_hook
)
expect
(
gitlab_custom_hook
).
to
receive
(
:call_receive_hook
)
.
with
(
hook_path
(
tmp_r
oot_path
,
"post-receive
"
),
changes
)
.
with
(
hook_path
(
tmp_r
epo_path
,
"custom_hooks/post-receive.d/hook
"
),
changes
)
.
and_call_original
.
and_call_original
stub_const
(
"ROOT_PATH"
,
tmp_root_path
)
gitlab_custom_hook
.
pre_receive
(
changes
)
gitlab_custom_hook
.
pre_receive
(
changes
)
gitlab_custom_hook
.
update
(
ref_name
,
old_value
,
new_value
)
gitlab_custom_hook
.
update
(
ref_name
,
old_value
,
new_value
)
gitlab_custom_hook
.
post_receive
(
changes
)
gitlab_custom_hook
.
post_receive
(
changes
)
end
end
end
end
def
hook_path
(
path
,
name
)
def
hook_path
(
repo_path
,
path
)
File
.
join
(
path
,
'custom_hooks'
,
name
)
File
.
join
(
repo_path
,
path
.
split
(
'/'
))
end
def
create_hook
(
repo_path
,
path
,
which
)
FileUtils
.
ln_sf
(
which
,
hook_path
(
repo_path
,
path
))
end
def
create_global_hooks
(
path
,
which
)
# should not be tested, as the "global hooks" is gitlab-shell itself (gitlab-shell/hooks/<hook_name>)
raise
"no method, this is gitlab-shell itself"
end
# global hooks multiplexed
def
create_global_hooks_d
(
path
,
which
)
create_hook
(
path
,
'hooks/pre-receive.d/hook'
,
which
)
create_hook
(
path
,
'hooks/update.d/hook'
,
which
)
create_hook
(
path
,
'hooks/post-receive.d/hook'
,
which
)
end
end
def
create_hook
(
path
,
name
,
which
)
# repo hooks
FileUtils
.
ln_sf
(
which
,
hook_path
(
path
,
name
))
def
create_repo_hooks
(
path
,
which
)
create_hook
(
path
,
'custom_hooks/pre-receive'
,
which
)
create_hook
(
path
,
'custom_hooks/update'
,
which
)
create_hook
(
path
,
'custom_hooks/post-receive'
,
which
)
end
end
def
create_hooks
(
path
,
which
)
# repo hooks multiplexed
create_hook
(
path
,
'pre-receive'
,
which
)
def
create_repo_hooks_d
(
path
,
which
)
create_hook
(
path
,
'update'
,
which
)
create_hook
(
path
,
'custom_hooks/pre-receive.d/hook'
,
which
)
create_hook
(
path
,
'post-receive'
,
which
)
create_hook
(
path
,
'custom_hooks/update.d/hook'
,
which
)
create_hook
(
path
,
'custom_hooks/post-receive.d/hook'
,
which
)
end
end
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