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
0ef15b36
Commit
0ef15b36
authored
Jan 12, 2017
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test git receive-pack
parent
8950dfc1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
10 deletions
+36
-10
internal/git/git-http_test.go
internal/git/git-http_test.go
+36
-10
No files found.
internal/git/git-http_test.go
View file @
0ef15b36
...
...
@@ -2,6 +2,7 @@ package git
import
(
"bytes"
"fmt"
"io"
"io/ioutil"
"net/http"
...
...
@@ -36,13 +37,22 @@ func createTestPayload() []byte {
return
data
}
func
TestRunUploadPack
(
t
*
testing
.
T
)
{
func
TestHandleUploadPack
(
t
*
testing
.
T
)
{
testHandlePostRpc
(
t
,
"git-upload-pack"
)
}
func
TestHandleReceivePack
(
t
*
testing
.
T
)
{
testHandlePostRpc
(
t
,
"git-receive-pack"
)
}
func
testHandlePostRpc
(
t
*
testing
.
T
,
action
string
)
{
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
)
url
:=
fmt
.
Sprintf
(
"/gitlab/gitlab-ce.git/?service=%s"
,
action
)
req
,
err
:=
http
.
NewRequest
(
"GET"
,
url
,
body
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
@@ -59,11 +69,12 @@ func TestRunUploadPack(t *testing.T) {
http
.
StatusOK
,
status
)
}
ct
:=
fmt
.
Sprintf
(
"application/x-%s-result"
,
action
)
headers
:=
[]
struct
{
key
string
value
string
}{
{
"Content-Type"
,
"application/x-git-upload-pack-result"
},
{
"Content-Type"
,
ct
},
{
"Cache-Control"
,
"no-cache"
},
}
...
...
@@ -81,6 +92,15 @@ func TestRunUploadPack(t *testing.T) {
}
}
func
stringInSlice
(
a
string
,
list
[]
string
)
bool
{
for
_
,
b
:=
range
list
{
if
b
==
a
{
return
true
}
}
return
false
}
func
TestGitCommandProcess
(
t
*
testing
.
T
)
{
if
os
.
Getenv
(
"GL_ID"
)
!=
GL_ID
{
return
...
...
@@ -88,12 +108,18 @@ func TestGitCommandProcess(t *testing.T) {
defer
os
.
Exit
(
0
)
// First, send a large payload to stdout so that this executable will be blocked
// until the reader consumes the data
testInput
:=
createTestPayload
()
body
:=
bytes
.
NewReader
([]
byte
(
testInput
))
io
.
Copy
(
os
.
Stdout
,
body
)
uploadPack
:=
stringInSlice
(
"upload-pack"
,
os
.
Args
)
if
uploadPack
{
// First, send a large payload to stdout so that this executable will be blocked
// until the reader consumes the data
testInput
:=
createTestPayload
()
body
:=
bytes
.
NewReader
([]
byte
(
testInput
))
io
.
Copy
(
os
.
Stdout
,
body
)
// Now consume all the data to unblock the sender
ioutil
.
ReadAll
(
os
.
Stdin
)
// Now consume all the data to unblock the sender
ioutil
.
ReadAll
(
os
.
Stdin
)
}
else
{
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