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
a7872691
Commit
a7872691
authored
Aug 02, 2018
by
Jacob Vosmaer (GitLab)
Committed by
Nick Thomas
Aug 02, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor ad-hoc protobuf marshaling in gitaly test server
parent
75f39661
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
28 deletions
+56
-28
gitaly_test.go
gitaly_test.go
+32
-17
internal/testhelper/gitaly.go
internal/testhelper/gitaly.go
+24
-11
No files found.
gitaly_test.go
View file @
a7872691
...
...
@@ -87,14 +87,26 @@ func TestGetInfoRefsProxiedToGitalySuccessfully(t *testing.T) {
gitProtocol
:=
"fake git protocol"
resource
:=
"/gitlab-org/gitlab-test.git/info/refs?service="
+
tc
.
gitRpc
_
,
body
:=
httpGet
(
t
,
ws
.
URL
+
resource
,
map
[
string
]
string
{
"Git-Protocol"
:
gitProtocol
})
resp
,
body
:=
httpGet
(
t
,
ws
.
URL
+
resource
,
map
[
string
]
string
{
"Git-Protocol"
:
gitProtocol
})
expectedContent
:=
fmt
.
Sprintf
(
"
\n
\0
00%s
\0
00%s
\0
00%s
\0
00"
,
gitProtocol
,
tc
.
gitRpc
,
testhelper
.
GitalyInfoRefsResponseMock
)
require
.
Equal
(
t
,
200
,
resp
.
StatusCode
)
bodySplit
:=
strings
.
SplitN
(
body
,
"
\0
00"
,
3
)
require
.
Len
(
t
,
bodySplit
,
3
)
gitalyRequest
:=
&
pb
.
InfoRefsRequest
{}
require
.
NoError
(
t
,
jsonpb
.
UnmarshalString
(
bodySplit
[
0
],
gitalyRequest
))
require
.
Equal
(
t
,
gitProtocol
,
gitalyRequest
.
GitProtocol
)
if
tc
.
showAllRefs
{
expectedContent
=
git
.
GitConfigShowAllRefs
+
expectedContent
require
.
Equal
(
t
,
[]
string
{
git
.
GitConfigShowAllRefs
},
gitalyRequest
.
GitConfigOptions
)
}
else
{
require
.
Empty
(
t
,
gitalyRequest
.
GitConfigOptions
)
}
require
.
Equal
(
t
,
expectedContent
,
body
,
"GET %q: response body"
,
resource
)
require
.
Equal
(
t
,
tc
.
gitRpc
,
bodySplit
[
1
])
require
.
Equal
(
t
,
string
(
testhelper
.
GitalyInfoRefsResponseMock
),
bodySplit
[
2
],
"GET %q: response body"
,
resource
)
})
}
}
...
...
@@ -248,23 +260,26 @@ func TestPostUploadPackProxiedToGitalySuccessfully(t *testing.T) {
testhelper
.
GitalyUploadPackResponseMock
,
)
expectedBodyParts
:=
[]
string
{
apiResponse
.
Repository
.
StorageName
,
apiResponse
.
Repository
.
RelativePath
,
gitProtocol
,
}
require
.
Equal
(
t
,
200
,
resp
.
StatusCode
,
"POST %q"
,
resource
)
testhelper
.
AssertResponseHeader
(
t
,
resp
,
"Content-Type"
,
"application/x-git-upload-pack-result"
)
bodySplit
:=
strings
.
SplitN
(
body
,
"
\0
00"
,
2
)
require
.
Len
(
t
,
bodySplit
,
2
)
gitalyRequest
:=
&
pb
.
PostUploadPackRequest
{}
require
.
NoError
(
t
,
jsonpb
.
UnmarshalString
(
bodySplit
[
0
],
gitalyRequest
))
require
.
Equal
(
t
,
apiResponse
.
Repository
.
StorageName
,
gitalyRequest
.
Repository
.
StorageName
)
require
.
Equal
(
t
,
apiResponse
.
Repository
.
RelativePath
,
gitalyRequest
.
Repository
.
RelativePath
)
require
.
Equal
(
t
,
gitProtocol
,
gitalyRequest
.
GitProtocol
)
if
tc
.
showAllRefs
{
expectedBodyParts
=
append
(
expectedBodyParts
,
git
.
GitConfigShowAllRefs
+
"
\n
"
)
require
.
Equal
(
t
,
[]
string
{
git
.
GitConfigShowAllRefs
},
gitalyRequest
.
GitConfigOptions
)
}
else
{
expectedBodyParts
=
append
(
expectedBodyParts
,
"
\n
"
)
require
.
Empty
(
t
,
gitalyRequest
.
GitConfigOptions
)
}
expectedBodyParts
=
append
(
expectedBodyParts
,
string
(
testhelper
.
GitalyUploadPackResponseMock
))
expectedBody
:=
strings
.
Join
(
expectedBodyParts
,
"
\0
00"
)
assert
.
Equal
(
t
,
200
,
resp
.
StatusCode
,
"POST %q"
,
resource
)
assert
.
Equal
(
t
,
expectedBody
,
body
,
"POST %q: response body"
,
resource
)
testhelper
.
AssertResponseHeader
(
t
,
resp
,
"Content-Type"
,
"application/x-git-upload-pack-result"
)
require
.
Equal
(
t
,
string
(
testhelper
.
GitalyUploadPackResponseMock
),
bodySplit
[
1
],
"POST %q: response body"
,
resource
)
})
}
}
...
...
internal/testhelper/gitaly.go
View file @
a7872691
...
...
@@ -8,6 +8,7 @@ import (
"strings"
"sync"
"github.com/golang/protobuf/jsonpb"
log
"github.com/sirupsen/logrus"
pb
"gitlab.com/gitlab-org/gitaly-proto/go"
...
...
@@ -59,12 +60,17 @@ func (s *GitalyTestServer) InfoRefsUploadPack(in *pb.InfoRefsRequest, stream pb.
fmt
.
Printf
(
"Result: %+v
\n
"
,
in
)
marshaler
:=
&
jsonpb
.
Marshaler
{}
jsonString
,
err
:=
marshaler
.
MarshalToString
(
in
)
if
err
!=
nil
{
return
err
}
data
:=
[]
byte
(
strings
.
Join
([]
string
{
strings
.
Join
(
in
.
GitConfigOptions
,
"
\n
"
)
+
"
\n
"
,
in
.
GitProtocol
,
jsonString
,
"git-upload-pack"
,
GitalyInfoRefsResponseMock
,
},
"
\0
00"
)
+
"
\0
00"
)
},
"
\0
00"
))
nSends
,
err
:=
sendBytes
(
data
,
100
,
func
(
p
[]
byte
)
error
{
return
stream
.
Send
(
&
pb
.
InfoRefsResponse
{
Data
:
p
})
...
...
@@ -89,12 +95,17 @@ func (s *GitalyTestServer) InfoRefsReceivePack(in *pb.InfoRefsRequest, stream pb
fmt
.
Printf
(
"Result: %+v
\n
"
,
in
)
marshaler
:=
&
jsonpb
.
Marshaler
{}
jsonString
,
err
:=
marshaler
.
MarshalToString
(
in
)
if
err
!=
nil
{
return
err
}
data
:=
[]
byte
(
strings
.
Join
([]
string
{
strings
.
Join
(
in
.
GitConfigOptions
,
"
\n
"
)
+
"
\n
"
,
in
.
GitProtocol
,
jsonString
,
"git-receive-pack"
,
GitalyInfoRefsResponseMock
,
},
"
\0
00"
)
+
"
\0
00"
)
},
"
\0
00"
))
nSends
,
err
:=
sendBytes
(
data
,
100
,
func
(
p
[]
byte
)
error
{
return
stream
.
Send
(
&
pb
.
InfoRefsResponse
{
Data
:
p
})
...
...
@@ -165,16 +176,18 @@ func (s *GitalyTestServer) PostUploadPack(stream pb.SmartHTTPService_PostUploadP
return
err
}
repo
:=
req
.
GetRepository
()
if
err
:=
validateRepository
(
req
.
GetRepository
());
err
!=
nil
{
return
err
}
marshaler
:=
&
jsonpb
.
Marshaler
{}
jsonString
,
err
:=
marshaler
.
MarshalToString
(
req
)
if
err
!=
nil
{
return
err
}
data
:=
[]
byte
(
strings
.
Join
([]
string
{
repo
.
GetStorageName
(),
repo
.
GetRelativePath
(),
req
.
GitProtocol
,
strings
.
Join
(
req
.
GitConfigOptions
,
"
\n
"
)
+
"
\n
"
,
jsonString
,
},
"
\0
00"
)
+
"
\0
00"
)
// The body of the request starts in the second message
...
...
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