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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-shell
Commits
a7ce4b52
Commit
a7ce4b52
authored
Feb 23, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests.
parent
9a863145
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
9 deletions
+78
-9
lib/gitlab_post_receive.rb
lib/gitlab_post_receive.rb
+2
-2
spec/gitlab_post_receive_spec.rb
spec/gitlab_post_receive_spec.rb
+76
-7
No files found.
lib/gitlab_post_receive.rb
View file @
a7ce4b52
...
...
@@ -16,7 +16,7 @@ class GitlabPostReceive
# get value from it
ENV
[
'GL_ID'
]
=
nil
success
=
update_redis
result
=
update_redis
begin
broadcast_message
=
GitlabNet
.
new
.
broadcast_message
...
...
@@ -29,7 +29,7 @@ class GitlabPostReceive
nil
end
success
result
end
protected
...
...
spec/gitlab_post_receive_spec.rb
View file @
a7ce4b52
...
...
@@ -4,18 +4,87 @@ require 'gitlab_post_receive'
describe
GitlabPostReceive
do
let
(
:repository_path
)
{
"/home/git/repositories"
}
let
(
:repo_name
)
{
'dzaporozhets/gitlab-ci'
}
let
(
:actor
)
{
'key-123'
}
let
(
:changes
)
{
'wow'
}
let
(
:repo_path
)
{
File
.
join
(
repository_path
,
repo_name
)
+
".git"
}
let
(
:gitlab_post_receive
)
{
GitlabPostReceive
.
new
(
repo_path
,
'key-123'
,
'wow'
)
}
let
(
:gitlab_post_receive
)
{
GitlabPostReceive
.
new
(
repo_path
,
actor
,
changes
)
}
let
(
:message
)
{
"test "
*
10
+
"message "
*
10
}
before
do
GitlabConfig
.
any_instance
.
stub
(
repos_path:
repository_path
)
Kernel
.
stub
(
system:
true
)
GitlabNet
.
any_instance
.
stub
(
broadcast_message:
{
"message"
=>
"test "
*
10
+
"message "
*
10
})
GitlabNet
.
any_instance
.
stub
(
broadcast_message:
{
"message"
=>
message
})
end
describe
:initialize
do
it
{
gitlab_post_receive
.
repo_path
.
should
==
repo_path
}
it
{
gitlab_post_receive
.
changes
.
should
==
'wow'
}
it
{
gitlab_post_receive
.
exec
}
describe
"#exec"
do
before
do
GitlabConfig
.
any_instance
.
stub
(
redis_command:
%w(env -i redis-cli)
)
allow
(
gitlab_post_receive
).
to
receive
(
:system
).
and_return
(
true
)
end
it
"resets the GL_ID environment variable"
do
ENV
[
"GL_ID"
]
=
actor
gitlab_post_receive
.
exec
expect
(
ENV
[
"GL_ID"
]).
to
be_nil
end
it
"prints the broadcast message"
do
expect
(
gitlab_post_receive
).
to
receive
(
:puts
).
ordered
expect
(
gitlab_post_receive
).
to
receive
(
:puts
).
with
(
"========================================================================"
).
ordered
expect
(
gitlab_post_receive
).
to
receive
(
:puts
).
ordered
expect
(
gitlab_post_receive
).
to
receive
(
:puts
).
with
(
" test test test test test test test test test test message message"
).
ordered
expect
(
gitlab_post_receive
).
to
receive
(
:puts
).
with
(
" message message message message message message message message"
).
ordered
expect
(
gitlab_post_receive
).
to
receive
(
:puts
).
ordered
expect
(
gitlab_post_receive
).
to
receive
(
:puts
).
with
(
"========================================================================"
).
ordered
gitlab_post_receive
.
exec
end
it
"pushes a Sidekiq job onto the queue"
do
expect
(
gitlab_post_receive
).
to
receive
(
:system
).
with
(
*
[
*
%w(env -i redis-cli rpush resque:gitlab:queue:post_receive)
,
%Q/{"class":"PostReceive","args":["
#{
repo_path
}
","
#{
actor
}
","
#{
changes
}
"]}/
,
{
err:
"/dev/null"
,
out:
"/dev/null"
}
]
).
and_return
(
true
)
gitlab_post_receive
.
exec
end
context
"when the redis command succeeds"
do
before
do
allow
(
gitlab_post_receive
).
to
receive
(
:system
).
and_return
(
true
)
end
it
"returns true"
do
expect
(
gitlab_post_receive
.
exec
).
to
eq
(
true
)
end
end
context
"when the redis command fails"
do
before
do
allow
(
gitlab_post_receive
).
to
receive
(
:system
).
and_return
(
false
)
allow
(
$?
).
to
receive
(
:exitstatus
).
and_return
(
nil
)
end
it
"returns false"
do
expect
(
gitlab_post_receive
.
exec
).
to
eq
(
false
)
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