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
1263f2c5
Commit
1263f2c5
authored
Jan 10, 2017
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unit test for upload-pack handling
parent
c8589c13
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
1 deletion
+95
-1
internal/git/command.go
internal/git/command.go
+3
-1
internal/git/git-http_test.go
internal/git/git-http_test.go
+92
-0
No files found.
internal/git/command.go
View file @
1263f2c5
...
...
@@ -7,9 +7,11 @@ import (
"syscall"
)
var
execCommand
=
exec
.
Command
// Git subprocess helpers
func
gitCommand
(
gl_id
string
,
name
string
,
args
...
string
)
*
exec
.
Cmd
{
cmd
:=
exec
.
Command
(
name
,
args
...
)
cmd
:=
execCommand
(
name
,
args
...
)
// Start the command in its own process group (nice for signalling)
cmd
.
SysProcAttr
=
&
syscall
.
SysProcAttr
{
Setpgid
:
true
}
// Explicitly set the environment for the Git command
...
...
internal/git/git-http_test.go
0 → 100644
View file @
1263f2c5
package
git
import
(
"bytes"
"io"
"net/http"
"net/http/httptest"
"os"
"os/exec"
"testing"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/api"
)
const
(
expectedBytes
=
102400
GL_ID
=
"test-user"
)
// From https://npf.io/2015/06/testing-exec-command/
func
fakeExecCommand
(
command
string
,
args
...
string
)
*
exec
.
Cmd
{
cs
:=
[]
string
{
"-test.run=TestGitCommandProcess"
,
"--"
,
command
}
cs
=
append
(
cs
,
args
...
)
cmd
:=
exec
.
Command
(
os
.
Args
[
0
],
cs
...
)
return
cmd
}
func
createTestPayload
()
[]
byte
{
data
:=
make
([]
byte
,
expectedBytes
)
for
i
:=
0
;
i
<
expectedBytes
;
i
++
{
data
[
i
]
=
'0'
}
return
data
}
func
TestRunUploadPack
(
t
*
testing
.
T
)
{
execCommand
=
fakeExecCommand
defer
func
()
{
execCommand
=
exec
.
Command
}()
testInput
:=
createTestPayload
()
body
:=
bytes
.
NewReader
([]
byte
(
testInput
))
req
,
err
:=
http
.
NewRequest
(
"GET"
,
"/gitlab/gitlab-ce.git/?service=git-upload-pack"
,
body
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
resp
:=
&
api
.
Response
{
GL_ID
:
GL_ID
}
rr
:=
httptest
.
NewRecorder
()
handlePostRPC
(
rr
,
req
,
resp
)
// Check HTTP status code
if
status
:=
rr
.
Code
;
status
!=
http
.
StatusOK
{
t
.
Errorf
(
"handler returned wrong status code: expected: %v, got %v"
,
http
.
StatusOK
,
status
)
}
headers
:=
[]
struct
{
key
string
value
string
}{
{
"Content-Type"
,
"application/x-git-upload-pack-result"
},
{
"Cache-Control"
,
"no-cache"
},
}
// Check HTTP headers
for
_
,
h
:=
range
headers
{
if
value
:=
rr
.
Header
()
.
Get
(
h
.
key
);
value
!=
h
.
value
{
t
.
Errorf
(
"HTTP header %v does not match: expected: %v, got %v"
,
h
.
key
,
h
.
value
,
value
)
}
}
if
rr
.
Body
.
String
()
!=
string
(
testInput
)
{
t
.
Errorf
(
"handler did not echo back properly: got %d, expected %d bytes"
,
len
(
rr
.
Body
.
String
()),
len
(
testInput
))
}
}
func
TestGitCommandProcess
(
t
*
testing
.
T
)
{
if
os
.
Getenv
(
"GL_ID"
)
!=
GL_ID
{
return
}
defer
os
.
Exit
(
0
)
// Echo back the input to test sender
io
.
Copy
(
os
.
Stdout
,
os
.
Stdin
)
}
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