Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-workhorse
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-workhorse
Commits
5d3d5373
Commit
5d3d5373
authored
Aug 01, 2015
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Factor out 'run or fail' test pattern
parent
29d303c5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
16 deletions
+11
-16
main_test.go
main_test.go
+11
-16
No files found.
main_test.go
View file @
5d3d5373
...
@@ -42,10 +42,7 @@ func TestAllowedClone(t *testing.T) {
...
@@ -42,10 +42,7 @@ func TestAllowedClone(t *testing.T) {
// Do the git clone
// Do the git clone
cloneCmd
:=
exec
.
Command
(
"git"
,
"clone"
,
remote
,
path
.
Join
(
scratchDir
,
"test"
))
cloneCmd
:=
exec
.
Command
(
"git"
,
"clone"
,
remote
,
path
.
Join
(
scratchDir
,
"test"
))
if
out
,
err
:=
cloneCmd
.
CombinedOutput
();
err
!=
nil
{
runOrFail
(
t
,
cloneCmd
)
t
.
Logf
(
"%s"
,
out
)
t
.
Fatal
(
err
)
}
}
}
func
TestAllowedPush
(
t
*
testing
.
T
)
{
func
TestAllowedPush
(
t
*
testing
.
T
)
{
...
@@ -55,17 +52,11 @@ func TestAllowedPush(t *testing.T) {
...
@@ -55,17 +52,11 @@ func TestAllowedPush(t *testing.T) {
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
cloneCmd
:=
exec
.
Command
(
"git"
,
"clone"
,
path
.
Join
(
testRepoRoot
,
testRepo
),
checkoutDir
)
cloneCmd
:=
exec
.
Command
(
"git"
,
"clone"
,
path
.
Join
(
testRepoRoot
,
testRepo
),
checkoutDir
)
if
out
,
err
:=
cloneCmd
.
CombinedOutput
();
err
!=
nil
{
runOrFail
(
t
,
cloneCmd
)
t
.
Logf
(
"%s"
,
out
)
t
.
Fatal
(
err
)
}
branch
:=
fmt
.
Sprintf
(
"branch-%d"
,
time
.
Now
()
.
UnixNano
())
branch
:=
fmt
.
Sprintf
(
"branch-%d"
,
time
.
Now
()
.
UnixNano
())
branchCmd
:=
exec
.
Command
(
"git"
,
"branch"
,
branch
)
branchCmd
:=
exec
.
Command
(
"git"
,
"branch"
,
branch
)
branchCmd
.
Dir
=
checkoutDir
branchCmd
.
Dir
=
checkoutDir
if
out
,
err
:=
branchCmd
.
CombinedOutput
();
err
!=
nil
{
runOrFail
(
t
,
branchCmd
)
t
.
Logf
(
"%s"
,
out
)
t
.
Fatal
(
err
)
}
// Prepare the test server and backend
// Prepare the test server and backend
ts
:=
testAuthServer
(
200
,
`{"GL_ID":"user-123"}`
)
ts
:=
testAuthServer
(
200
,
`{"GL_ID":"user-123"}`
)
...
@@ -82,10 +73,7 @@ func TestAllowedPush(t *testing.T) {
...
@@ -82,10 +73,7 @@ func TestAllowedPush(t *testing.T) {
// Perform the git push
// Perform the git push
pushCmd
:=
exec
.
Command
(
"git"
,
"push"
,
remote
,
branch
)
pushCmd
:=
exec
.
Command
(
"git"
,
"push"
,
remote
,
branch
)
pushCmd
.
Dir
=
checkoutDir
pushCmd
.
Dir
=
checkoutDir
if
out
,
err
:=
pushCmd
.
CombinedOutput
();
err
!=
nil
{
runOrFail
(
t
,
pushCmd
)
t
.
Logf
(
"%s"
,
out
)
t
.
Fatal
(
err
)
}
}
}
func
testAuthServer
(
code
int
,
body
string
)
*
httptest
.
Server
{
func
testAuthServer
(
code
int
,
body
string
)
*
httptest
.
Server
{
...
@@ -114,3 +102,10 @@ func waitServer() (err error) {
...
@@ -114,3 +102,10 @@ func waitServer() (err error) {
}
}
return
return
}
}
func
runOrFail
(
t
*
testing
.
T
,
cmd
*
exec
.
Cmd
)
{
if
out
,
err
:=
cmd
.
CombinedOutput
();
err
!=
nil
{
t
.
Logf
(
"%s"
,
out
)
t
.
Fatal
(
err
)
}
}
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