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
1a4272eb
Commit
1a4272eb
authored
Aug 01, 2015
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add end-to-end 'git clone' test
parent
85e4d75c
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
70 additions
and
0 deletions
+70
-0
.gitignore
.gitignore
+2
-0
Makefile
Makefile
+10
-0
main_test.go
main_test.go
+58
-0
test/.gitkeep
test/.gitkeep
+0
-0
No files found.
.gitignore
View file @
1a4272eb
gitlab-git-http-server
test/data
test/scratch
Makefile
View file @
1a4272eb
...
...
@@ -6,3 +6,13 @@ gitlab-git-http-server: main.go
install
:
gitlab-git-http-server
install
gitlab-git-http-server
${PREFIX}
/bin/
.PHONY
:
test
test
:
test/data/test.git
go
test
test/data/test.git
:
test/data
git clone
--bare
https://gitlab.com/gitlab-org/gitlab-test.git
test
/data/test.git
test/data
:
mkdir
-p
test
/data
main_test.go
0 → 100644
View file @
1a4272eb
package
main
import
(
"fmt"
"net"
"net/http"
"net/http/httptest"
"os"
"os/exec"
"path"
"syscall"
"testing"
"time"
)
const
servAddr
=
"127.0.0.1:8181"
const
servWaitListen
=
10000
// milliseconds to wait for server to start listening
const
servWaitSleep
=
100
// milliseconds sleep interval
const
scratchDir
=
"test/scratch"
const
testRepoRoot
=
"test/data"
func
TestAllowedClone
(
t
*
testing
.
T
)
{
ts
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
fmt
.
Fprintln
(
w
,
`{"GL_ID":"user-123"}`
)
}))
defer
ts
.
Close
()
defer
cleanUpProcessGroup
(
startServer
(
t
,
ts
))
if
err
:=
os
.
RemoveAll
(
scratchDir
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
cloneCmd
:=
exec
.
Command
(
"git"
,
"clone"
,
fmt
.
Sprintf
(
"http://%s/test.git"
,
servAddr
),
path
.
Join
(
scratchDir
,
"test"
))
if
out
,
err
:=
cloneCmd
.
CombinedOutput
();
err
!=
nil
{
t
.
Logf
(
"%s"
,
out
)
t
.
Fatal
(
err
)
}
}
func
startServer
(
t
*
testing
.
T
,
ts
*
httptest
.
Server
)
(
cmd
*
exec
.
Cmd
)
{
var
conn
net
.
Conn
var
err
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
}
if
err
:=
cmd
.
Start
();
err
!=
nil
{
t
.
Fatal
(
err
)
}
for
i
:=
0
;
i
<
servWaitListen
/
servWaitSleep
;
i
++
{
conn
,
err
=
net
.
Dial
(
"tcp"
,
servAddr
)
if
err
==
nil
{
conn
.
Close
()
break
}
time
.
Sleep
(
servWaitSleep
*
time
.
Millisecond
)
}
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
return
}
test/.gitkeep
0 → 100644
View file @
1a4272eb
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