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
c5cf5439
Commit
c5cf5439
authored
Sep 09, 2016
by
Dirk Hörner
Committed by
Sean McGivern
Dec 01, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
spec: add tests for global custom hooks
parent
0e409ee4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
165 additions
and
15 deletions
+165
-15
spec/gitlab_custom_hook_spec.rb
spec/gitlab_custom_hook_spec.rb
+159
-15
spec/support/hook_fail
spec/support/hook_fail
+3
-0
spec/support/hook_ok
spec/support/hook_ok
+3
-0
No files found.
spec/gitlab_custom_hook_spec.rb
View file @
c5cf5439
# coding: utf-8
# coding: utf-8
require
'spec_helper'
require
'spec_helper'
require
'pry'
require
'gitlab_custom_hook'
require
'gitlab_custom_hook'
describe
GitlabCustomHook
do
describe
GitlabCustomHook
do
let
(
:gitlab_custom_hook
)
{
GitlabCustomHook
.
new
(
'repo_path'
,
'key_1'
)
}
let
(
:tmp_repo_path
)
{
File
.
join
(
ROOT_PATH
,
'tmp'
,
'repo.git'
)
}
let
(
:hook_path
)
{
File
.
join
(
ROOT_PATH
,
'spec/support/gl_id_test_hook'
)
}
let
(
:tmp_root_path
)
{
File
.
join
(
ROOT_PATH
,
'tmp'
)
}
let
(
:hook_ok
)
{
File
.
join
(
ROOT_PATH
,
'spec'
,
'support'
,
'hook_ok'
)
}
let
(
:hook_fail
)
{
File
.
join
(
ROOT_PATH
,
'spec'
,
'support'
,
'hook_fail'
)
}
context
'pre_receive hook'
do
let
(
:vars
)
{
{
"GL_ID"
=>
"key_1"
}
}
it
'passes GL_ID variable to hook'
do
let
(
:old_value
)
{
"old-value"
}
allow
(
gitlab_custom_hook
).
to
receive
(
:hook_file
).
and_return
(
hook_path
)
let
(
:new_value
)
{
"new-value"
}
let
(
:ref_name
)
{
"name/of/ref"
}
let
(
:changes
)
{
"
#{
old_value
}
#{
new_value
}
#{
ref_name
}
\n
"
}
expect
(
gitlab_custom_hook
.
pre_receive
(
'changes'
)).
to
be_true
let
(
:gitlab_custom_hook
)
{
GitlabCustomHook
.
new
(
tmp_repo_path
,
'key_1'
)
}
before
do
FileUtils
.
mkdir_p
(
File
.
join
(
tmp_repo_path
,
'custom_hooks'
))
FileUtils
.
mkdir_p
(
File
.
join
(
tmp_root_path
,
'custom_hooks'
))
end
after
do
FileUtils
.
rm_rf
(
File
.
join
(
tmp_repo_path
,
'custom_hooks'
))
FileUtils
.
rm_rf
(
File
.
join
(
tmp_root_path
,
'custom_hooks'
))
end
context
'with gl_id_test_hook'
do
let
(
:hook_path
)
{
File
.
join
(
ROOT_PATH
,
'spec/support/gl_id_test_hook'
)
}
context
'pre_receive hook'
do
it
'passes GL_ID variable to hook'
do
allow
(
gitlab_custom_hook
).
to
receive
(
:hook_file
).
and_return
(
hook_path
)
expect
(
gitlab_custom_hook
.
pre_receive
(
changes
)).
to
be_true
end
end
context
'post_receive hook'
do
it
'passes GL_ID variable to hook'
do
allow
(
gitlab_custom_hook
).
to
receive
(
:hook_file
).
and_return
(
hook_path
)
expect
(
gitlab_custom_hook
.
post_receive
(
changes
)).
to
be_true
end
end
context
'update hook'
do
it
'passes GL_ID variable to hook'
do
allow
(
gitlab_custom_hook
).
to
receive
(
:hook_file
).
and_return
(
hook_path
)
expect
(
gitlab_custom_hook
.
update
(
ref_name
,
old_value
,
new_value
)).
to
be_true
end
end
end
context
"having no hooks"
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
.
update
(
ref_name
,
old_value
,
new_value
)).
to
eq
(
true
)
expect
(
gitlab_custom_hook
.
post_receive
(
changes
)).
to
eq
(
true
)
end
end
context
"having only ok repo hooks"
do
before
do
create_hooks
(
tmp_repo_path
,
hook_ok
)
end
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
.
update
(
ref_name
,
old_value
,
new_value
)).
to
eq
(
true
)
expect
(
gitlab_custom_hook
.
post_receive
(
changes
)).
to
eq
(
true
)
end
end
context
"having both ok repo and global hooks"
do
before
do
create_hooks
(
tmp_repo_path
,
hook_ok
)
create_hooks
(
tmp_root_path
,
hook_ok
)
end
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
.
update
(
ref_name
,
old_value
,
new_value
)).
to
eq
(
true
)
expect
(
gitlab_custom_hook
.
post_receive
(
changes
)).
to
eq
(
true
)
end
end
end
end
context
'post_receive hook'
do
context
"having failing repo and ok global hooks"
do
it
'passes GL_ID variable to hook'
do
before
do
allow
(
gitlab_custom_hook
).
to
receive
(
:hook_file
).
and_return
(
hook_path
)
create_hooks
(
tmp_repo_path
,
hook_fail
)
create_hooks
(
tmp_root_path
,
hook_ok
)
end
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
.
update
(
ref_name
,
old_value
,
new_value
)).
to
eq
(
false
)
expect
(
gitlab_custom_hook
.
post_receive
(
changes
)).
to
eq
(
false
)
end
it
"only executes the repo hook"
do
expect
(
gitlab_custom_hook
).
to
receive
(
:call_receive_hook
)
.
with
(
hook_path
(
tmp_repo_path
,
"pre-receive"
),
changes
)
.
and_call_original
expect
(
gitlab_custom_hook
).
to
receive
(
:system
)
.
with
(
vars
,
hook_path
(
tmp_repo_path
,
"update"
),
ref_name
,
old_value
,
new_value
)
.
and_call_original
expect
(
gitlab_custom_hook
).
to
receive
(
:call_receive_hook
)
.
with
(
hook_path
(
tmp_repo_path
,
"post-receive"
),
changes
)
.
and_call_original
expect
(
gitlab_custom_hook
.
post_receive
(
'changes'
)).
to
be_true
stub_const
(
"ROOT_PATH"
,
tmp_root_path
)
gitlab_custom_hook
.
pre_receive
(
changes
)
gitlab_custom_hook
.
update
(
ref_name
,
old_value
,
new_value
)
gitlab_custom_hook
.
post_receive
(
changes
)
end
end
end
end
context
'update hook'
do
context
"having ok repo but failing global hooks"
do
it
'passes GL_ID variable to hook'
do
before
do
allow
(
gitlab_custom_hook
).
to
receive
(
:hook_file
).
and_return
(
hook_path
)
create_hooks
(
tmp_repo_path
,
hook_ok
)
create_hooks
(
tmp_root_path
,
hook_fail
)
end
expect
(
gitlab_custom_hook
.
update
(
'master'
,
''
,
''
)).
to
be_true
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
.
update
(
ref_name
,
old_value
,
new_value
)).
to
eq
(
false
)
expect
(
gitlab_custom_hook
.
post_receive
(
changes
)).
to
eq
(
false
)
end
end
it
"executes the relevant hooks"
do
expect
(
gitlab_custom_hook
).
to
receive
(
:call_receive_hook
)
.
with
(
hook_path
(
tmp_repo_path
,
"pre-receive"
),
changes
)
.
and_call_original
expect
(
gitlab_custom_hook
).
to
receive
(
:call_receive_hook
)
.
with
(
hook_path
(
tmp_root_path
,
"pre-receive"
),
changes
)
.
and_call_original
expect
(
gitlab_custom_hook
).
to
receive
(
:system
)
.
with
(
vars
,
hook_path
(
tmp_repo_path
,
"update"
),
ref_name
,
old_value
,
new_value
)
.
and_call_original
expect
(
gitlab_custom_hook
).
to
receive
(
:system
)
.
with
(
vars
,
hook_path
(
tmp_root_path
,
"update"
),
ref_name
,
old_value
,
new_value
)
.
and_call_original
expect
(
gitlab_custom_hook
).
to
receive
(
:call_receive_hook
)
.
with
(
hook_path
(
tmp_repo_path
,
"post-receive"
),
changes
)
.
and_call_original
expect
(
gitlab_custom_hook
).
to
receive
(
:call_receive_hook
)
.
with
(
hook_path
(
tmp_root_path
,
"post-receive"
),
changes
)
.
and_call_original
stub_const
(
"ROOT_PATH"
,
tmp_root_path
)
gitlab_custom_hook
.
pre_receive
(
changes
)
gitlab_custom_hook
.
update
(
ref_name
,
old_value
,
new_value
)
gitlab_custom_hook
.
post_receive
(
changes
)
end
end
def
hook_path
(
path
,
name
)
File
.
join
(
path
,
'custom_hooks'
,
name
)
end
def
create_hook
(
path
,
name
,
which
)
FileUtils
.
ln_sf
(
which
,
hook_path
(
path
,
name
))
end
def
create_hooks
(
path
,
which
)
create_hook
(
path
,
'pre-receive'
,
which
)
create_hook
(
path
,
'update'
,
which
)
create_hook
(
path
,
'post-receive'
,
which
)
end
end
end
end
spec/support/hook_fail
0 → 100755
View file @
c5cf5439
#!/bin/bash
#echo "fail: $0"
exit
1
spec/support/hook_ok
0 → 100755
View file @
c5cf5439
#!/bin/bash
#echo "ok: $0"
exit
0
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