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
29d303c5
Commit
29d303c5
authored
Aug 01, 2015
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor tests and add comments
parent
7113b09d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
16 deletions
+20
-16
main_test.go
main_test.go
+20
-16
No files found.
main_test.go
View file @
29d303c5
...
@@ -23,6 +23,12 @@ const testRepo = "test.git"
...
@@ -23,6 +23,12 @@ const testRepo = "test.git"
var
remote
=
fmt
.
Sprintf
(
"http://%s/%s"
,
servAddr
,
testRepo
)
var
remote
=
fmt
.
Sprintf
(
"http://%s/%s"
,
servAddr
,
testRepo
)
func
TestAllowedClone
(
t
*
testing
.
T
)
{
func
TestAllowedClone
(
t
*
testing
.
T
)
{
// Prepare clone directory
if
err
:=
os
.
RemoveAll
(
scratchDir
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
// 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
)
cmd
,
err
:=
startServer
(
ts
)
...
@@ -30,9 +36,11 @@ func TestAllowedClone(t *testing.T) {
...
@@ -30,9 +36,11 @@ func TestAllowedClone(t *testing.T) {
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
defer
cleanUpProcessGroup
(
cmd
)
defer
cleanUpProcessGroup
(
cmd
)
if
err
:=
os
.
RemoveAll
(
scratchDir
);
err
!=
nil
{
if
err
:=
waitServer
(
);
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
// 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
{
if
out
,
err
:=
cloneCmd
.
CombinedOutput
();
err
!=
nil
{
t
.
Logf
(
"%s"
,
out
)
t
.
Logf
(
"%s"
,
out
)
...
@@ -67,6 +75,9 @@ func TestAllowedPush(t *testing.T) {
...
@@ -67,6 +75,9 @@ func TestAllowedPush(t *testing.T) {
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
defer
cleanUpProcessGroup
(
cmd
)
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
,
branch
)
pushCmd
:=
exec
.
Command
(
"git"
,
"push"
,
remote
,
branch
)
...
@@ -84,29 +95,22 @@ func testAuthServer(code int, body string) *httptest.Server {
...
@@ -84,29 +95,22 @@ func testAuthServer(code int, body string) *httptest.Server {
}))
}))
}
}
func
startServer
(
ts
*
httptest
.
Server
)
(
cmd
*
exec
.
Cmd
,
err
error
)
{
func
startServer
(
ts
*
httptest
.
Server
)
(
*
exec
.
Cmd
,
error
)
{
var
conn
net
.
Conn
cmd
:=
exec
.
Command
(
"go"
,
"run"
,
"main.go"
,
fmt
.
Sprintf
(
"-authBackend=%s"
,
ts
.
URL
),
fmt
.
Sprintf
(
"-listenAddr=%s"
,
servAddr
),
testRepoRoot
)
// Start our server process
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
}
err
=
cmd
.
Start
()
return
cmd
,
cmd
.
Start
()
if
err
!=
nil
{
}
return
}
func
waitServer
()
(
err
error
)
{
var
conn
net
.
Conn
// Wait for the server to start accepting TCP connections
for
i
:=
0
;
i
<
servWaitListen
/
servWaitSleep
;
i
++
{
for
i
:=
0
;
i
<
servWaitListen
/
servWaitSleep
;
i
++
{
conn
,
err
=
net
.
Dial
(
"tcp"
,
servAddr
)
conn
,
err
=
net
.
Dial
(
"tcp"
,
servAddr
)
if
err
==
nil
{
if
err
==
nil
{
conn
.
Close
()
conn
.
Close
()
break
return
}
}
time
.
Sleep
(
servWaitSleep
*
time
.
Millisecond
)
time
.
Sleep
(
servWaitSleep
*
time
.
Millisecond
)
}
}
if
err
!=
nil
{
cleanUpProcessGroup
(
cmd
)
}
return
return
}
}
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