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
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-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) {
// Prepare test server and backend
ts
:=
testAuthServer
(
200
,
`{"GL_ID":"user-123"}`
)
defer
ts
.
Close
()
cmd
,
err
:=
startServer
(
ts
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
cleanUpProcessGroup
(
cmd
)
if
err
:=
waitServer
();
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
cleanUpProcessGroup
(
startServerOrFail
(
t
,
ts
))
// Do the git clone
cloneCmd
:=
exec
.
Command
(
"git"
,
"clone"
,
remote
,
checkoutDir
)
...
...
@@ -60,14 +53,7 @@ func TestDeniedClone(t *testing.T) {
// Prepare test server and backend
ts
:=
testAuthServer
(
403
,
"Access denied"
)
defer
ts
.
Close
()
cmd
,
err
:=
startServer
(
ts
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
cleanUpProcessGroup
(
cmd
)
if
err
:=
waitServer
();
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
cleanUpProcessGroup
(
startServerOrFail
(
t
,
ts
))
// Do the git clone
cloneCmd
:=
exec
.
Command
(
"git"
,
"clone"
,
remote
,
checkoutDir
)
...
...
@@ -84,14 +70,7 @@ func TestAllowedPush(t *testing.T) {
// Prepare the test server and backend
ts
:=
testAuthServer
(
200
,
`{"GL_ID":"user-123"}`
)
defer
ts
.
Close
()
cmd
,
err
:=
startServer
(
ts
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
cleanUpProcessGroup
(
cmd
)
if
err
:=
waitServer
();
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
cleanUpProcessGroup
(
startServerOrFail
(
t
,
ts
))
// Perform the git push
pushCmd
:=
exec
.
Command
(
"git"
,
"push"
,
remote
,
fmt
.
Sprintf
(
"master:%s"
,
newBranch
()))
...
...
@@ -105,14 +84,7 @@ func TestDeniedPush(t *testing.T) {
// Prepare the test server and backend
ts
:=
testAuthServer
(
403
,
"Access denied"
)
defer
ts
.
Close
()
cmd
,
err
:=
startServer
(
ts
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
cleanUpProcessGroup
(
cmd
)
if
err
:=
waitServer
();
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
cleanUpProcessGroup
(
startServerOrFail
(
t
,
ts
))
// Perform the git push
pushCmd
:=
exec
.
Command
(
"git"
,
"push"
,
"-v"
,
remote
,
fmt
.
Sprintf
(
"master:%s"
,
newBranch
()))
...
...
@@ -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
.
SysProcAttr
=
&
syscall
.
SysProcAttr
{
Setpgid
:
true
}
cmd
.
Stdout
=
os
.
Stdout
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
)
{
...
...
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