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
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"
var
remote
=
fmt
.
Sprintf
(
"http://%s/%s"
,
servAddr
,
testRepo
)
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"}`
)
defer
ts
.
Close
()
cmd
,
err
:=
startServer
(
ts
)
...
...
@@ -30,9 +36,11 @@ func TestAllowedClone(t *testing.T) {
t
.
Fatal
(
err
)
}
defer
cleanUpProcessGroup
(
cmd
)
if
err
:=
os
.
RemoveAll
(
scratchDir
);
err
!=
nil
{
if
err
:=
waitServer
(
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Do the git clone
cloneCmd
:=
exec
.
Command
(
"git"
,
"clone"
,
remote
,
path
.
Join
(
scratchDir
,
"test"
))
if
out
,
err
:=
cloneCmd
.
CombinedOutput
();
err
!=
nil
{
t
.
Logf
(
"%s"
,
out
)
...
...
@@ -67,6 +75,9 @@ func TestAllowedPush(t *testing.T) {
t
.
Fatal
(
err
)
}
defer
cleanUpProcessGroup
(
cmd
)
if
err
:=
waitServer
();
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Perform the git push
pushCmd
:=
exec
.
Command
(
"git"
,
"push"
,
remote
,
branch
)
...
...
@@ -84,29 +95,22 @@ func testAuthServer(code int, body string) *httptest.Server {
}))
}
func
startServer
(
ts
*
httptest
.
Server
)
(
cmd
*
exec
.
Cmd
,
err
error
)
{
var
conn
net
.
Conn
// Start our server process
cmd
=
exec
.
Command
(
"go"
,
"run"
,
"main.go"
,
fmt
.
Sprintf
(
"-authBackend=%s"
,
ts
.
URL
),
fmt
.
Sprintf
(
"-listenAddr=%s"
,
servAddr
),
testRepoRoot
)
func
startServer
(
ts
*
httptest
.
Server
)
(
*
exec
.
Cmd
,
error
)
{
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
}
err
=
cmd
.
Start
()
if
err
!=
nil
{
return
}
return
cmd
,
cmd
.
Start
()
}
func
waitServer
()
(
err
error
)
{
var
conn
net
.
Conn
// Wait for the server to start accepting TCP connections
for
i
:=
0
;
i
<
servWaitListen
/
servWaitSleep
;
i
++
{
conn
,
err
=
net
.
Dial
(
"tcp"
,
servAddr
)
if
err
==
nil
{
conn
.
Close
()
break
return
}
time
.
Sleep
(
servWaitSleep
*
time
.
Millisecond
)
}
if
err
!=
nil
{
cleanUpProcessGroup
(
cmd
)
}
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