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
...
@@ -2,6 +2,7 @@ package git
import
(
import
(
"bytes"
"bytes"
"fmt"
"io"
"io"
"io/ioutil"
"io/ioutil"
"net/http"
"net/http"
...
@@ -36,13 +37,22 @@ func createTestPayload() []byte {
...
@@ -36,13 +37,22 @@ func createTestPayload() []byte {
return
data
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
execCommand
=
fakeExecCommand
defer
func
()
{
execCommand
=
exec
.
Command
}()
defer
func
()
{
execCommand
=
exec
.
Command
}()
testInput
:=
createTestPayload
()
testInput
:=
createTestPayload
()
body
:=
bytes
.
NewReader
([]
byte
(
testInput
))
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
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
...
@@ -59,11 +69,12 @@ func TestRunUploadPack(t *testing.T) {
...
@@ -59,11 +69,12 @@ func TestRunUploadPack(t *testing.T) {
http
.
StatusOK
,
status
)
http
.
StatusOK
,
status
)
}
}
ct
:=
fmt
.
Sprintf
(
"application/x-%s-result"
,
action
)
headers
:=
[]
struct
{
headers
:=
[]
struct
{
key
string
key
string
value
string
value
string
}{
}{
{
"Content-Type"
,
"application/x-git-upload-pack-result"
},
{
"Content-Type"
,
ct
},
{
"Cache-Control"
,
"no-cache"
},
{
"Cache-Control"
,
"no-cache"
},
}
}
...
@@ -81,6 +92,15 @@ func TestRunUploadPack(t *testing.T) {
...
@@ -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
)
{
func
TestGitCommandProcess
(
t
*
testing
.
T
)
{
if
os
.
Getenv
(
"GL_ID"
)
!=
GL_ID
{
if
os
.
Getenv
(
"GL_ID"
)
!=
GL_ID
{
return
return
...
@@ -88,12 +108,18 @@ func TestGitCommandProcess(t *testing.T) {
...
@@ -88,12 +108,18 @@ func TestGitCommandProcess(t *testing.T) {
defer
os
.
Exit
(
0
)
defer
os
.
Exit
(
0
)
// First, send a large payload to stdout so that this executable will be blocked
uploadPack
:=
stringInSlice
(
"upload-pack"
,
os
.
Args
)
// until the reader consumes the data
testInput
:=
createTestPayload
()
if
uploadPack
{
body
:=
bytes
.
NewReader
([]
byte
(
testInput
))
// First, send a large payload to stdout so that this executable will be blocked
io
.
Copy
(
os
.
Stdout
,
body
)
// 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
// Now consume all the data to unblock the sender
ioutil
.
ReadAll
(
os
.
Stdin
)
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