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
1
Merge Requests
1
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-workhorse
Commits
3b6d7157
Commit
3b6d7157
authored
Aug 02, 2015
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove server startup repetition
parent
c71b3d6e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
34 deletions
+15
-34
main_test.go
main_test.go
+15
-34
No files found.
main_test.go
View file @
3b6d7157
...
@@ -32,14 +32,7 @@ func TestAllowedClone(t *testing.T) {
...
@@ -32,14 +32,7 @@ func TestAllowedClone(t *testing.T) {
// Prepare test server and backend
// Prepare test server and backend
ts
:=
testAuthServer
(
200
,
`{"GL_ID":"user-123"}`
)
ts
:=
testAuthServer
(
200
,
`{"GL_ID":"user-123"}`
)
defer
ts
.
Close
()
defer
ts
.
Close
()
cmd
,
err
:=
startServer
(
ts
)
defer
cleanUpProcessGroup
(
startServerOrFail
(
t
,
ts
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
cleanUpProcessGroup
(
cmd
)
if
err
:=
waitServer
();
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Do the git clone
// Do the git clone
cloneCmd
:=
exec
.
Command
(
"git"
,
"clone"
,
remote
,
checkoutDir
)
cloneCmd
:=
exec
.
Command
(
"git"
,
"clone"
,
remote
,
checkoutDir
)
...
@@ -60,14 +53,7 @@ func TestDeniedClone(t *testing.T) {
...
@@ -60,14 +53,7 @@ func TestDeniedClone(t *testing.T) {
// Prepare test server and backend
// Prepare test server and backend
ts
:=
testAuthServer
(
403
,
"Access denied"
)
ts
:=
testAuthServer
(
403
,
"Access denied"
)
defer
ts
.
Close
()
defer
ts
.
Close
()
cmd
,
err
:=
startServer
(
ts
)
defer
cleanUpProcessGroup
(
startServerOrFail
(
t
,
ts
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
cleanUpProcessGroup
(
cmd
)
if
err
:=
waitServer
();
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Do the git clone
// Do the git clone
cloneCmd
:=
exec
.
Command
(
"git"
,
"clone"
,
remote
,
checkoutDir
)
cloneCmd
:=
exec
.
Command
(
"git"
,
"clone"
,
remote
,
checkoutDir
)
...
@@ -84,14 +70,7 @@ func TestAllowedPush(t *testing.T) {
...
@@ -84,14 +70,7 @@ func TestAllowedPush(t *testing.T) {
// 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"}`
)
defer
ts
.
Close
()
defer
ts
.
Close
()
cmd
,
err
:=
startServer
(
ts
)
defer
cleanUpProcessGroup
(
startServerOrFail
(
t
,
ts
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
cleanUpProcessGroup
(
cmd
)
if
err
:=
waitServer
();
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Perform the git push
// Perform the git push
pushCmd
:=
exec
.
Command
(
"git"
,
"push"
,
remote
,
fmt
.
Sprintf
(
"master:%s"
,
newBranch
()))
pushCmd
:=
exec
.
Command
(
"git"
,
"push"
,
remote
,
fmt
.
Sprintf
(
"master:%s"
,
newBranch
()))
...
@@ -105,14 +84,7 @@ func TestDeniedPush(t *testing.T) {
...
@@ -105,14 +84,7 @@ func TestDeniedPush(t *testing.T) {
// Prepare the test server and backend
// Prepare the test server and backend
ts
:=
testAuthServer
(
403
,
"Access denied"
)
ts
:=
testAuthServer
(
403
,
"Access denied"
)
defer
ts
.
Close
()
defer
ts
.
Close
()
cmd
,
err
:=
startServer
(
ts
)
defer
cleanUpProcessGroup
(
startServerOrFail
(
t
,
ts
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
cleanUpProcessGroup
(
cmd
)
if
err
:=
waitServer
();
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Perform the git push
// Perform the git push
pushCmd
:=
exec
.
Command
(
"git"
,
"push"
,
"-v"
,
remote
,
fmt
.
Sprintf
(
"master:%s"
,
newBranch
()))
pushCmd
:=
exec
.
Command
(
"git"
,
"push"
,
"-v"
,
remote
,
fmt
.
Sprintf
(
"master:%s"
,
newBranch
()))
...
@@ -144,12 +116,21 @@ func testAuthServer(code int, body string) *httptest.Server {
...
@@ -144,12 +116,21 @@ func testAuthServer(code int, body string) *httptest.Server {
}))
}))
}
}
func
startServer
(
ts
*
httptest
.
Server
)
(
*
exec
.
Cmd
,
error
)
{
func
startServer
OrFail
(
t
*
testing
.
T
,
ts
*
httptest
.
Server
)
*
exec
.
Cmd
{
cmd
:=
exec
.
Command
(
"go"
,
"run"
,
"main.go"
,
fmt
.
Sprintf
(
"-authBackend=%s"
,
ts
.
URL
),
fmt
.
Sprintf
(
"-listenAddr=%s"
,
servAddr
),
testRepoRoot
)
cmd
:=
exec
.
Command
(
"go"
,
"run"
,
"main.go"
,
fmt
.
Sprintf
(
"-authBackend=%s"
,
ts
.
URL
),
fmt
.
Sprintf
(
"-listenAddr=%s"
,
servAddr
),
testRepoRoot
)
cmd
.
SysProcAttr
=
&
syscall
.
SysProcAttr
{
Setpgid
:
true
}
cmd
.
SysProcAttr
=
&
syscall
.
SysProcAttr
{
Setpgid
:
true
}
cmd
.
Stdout
=
os
.
Stdout
cmd
.
Stdout
=
os
.
Stdout
cmd
.
Stderr
=
os
.
Stderr
cmd
.
Stderr
=
os
.
Stderr
return
cmd
,
cmd
.
Start
()
if
err
:=
cmd
.
Start
();
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
err
:=
waitServer
();
err
!=
nil
{
cleanUpProcessGroup
(
cmd
)
t
.
Fatal
(
err
)
}
return
cmd
}
}
func
waitServer
()
(
err
error
)
{
func
waitServer
()
(
err
error
)
{
...
...
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