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
b06db824
Commit
b06db824
authored
Mar 07, 2017
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for new jobs request and artifacts upload paths
parent
458c9fc7
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
927 additions
and
12 deletions
+927
-12
jobs_test.go
jobs_test.go
+60
-0
upload_test.go
upload_test.go
+28
-12
vendor/github.com/stretchr/testify/require/doc.go
vendor/github.com/stretchr/testify/require/doc.go
+28
-0
vendor/github.com/stretchr/testify/require/forward_requirements.go
...thub.com/stretchr/testify/require/forward_requirements.go
+16
-0
vendor/github.com/stretchr/testify/require/require.go
vendor/github.com/stretchr/testify/require/require.go
+423
-0
vendor/github.com/stretchr/testify/require/require.go.tmpl
vendor/github.com/stretchr/testify/require/require.go.tmpl
+6
-0
vendor/github.com/stretchr/testify/require/require_forward.go
...or/github.com/stretchr/testify/require/require_forward.go
+347
-0
vendor/github.com/stretchr/testify/require/require_forward.go.tmpl
...thub.com/stretchr/testify/require/require_forward.go.tmpl
+4
-0
vendor/github.com/stretchr/testify/require/requirements.go
vendor/github.com/stretchr/testify/require/requirements.go
+9
-0
vendor/vendor.json
vendor/vendor.json
+6
-0
No files found.
build
s_test.go
→
job
s_test.go
View file @
b06db824
...
...
@@ -16,29 +16,45 @@ func startWorkhorseServerWithLongPolling(authBackend string, pollingDuration tim
return
startWorkhorseServerWithConfig
(
uc
)
}
func
postBuildsRegister
(
url
string
,
body
io
.
Reader
)
(
*
http
.
Response
,
error
)
{
type
requestJobFunction
func
(
url
string
,
body
io
.
Reader
)
(
*
http
.
Response
,
error
)
func
requestJobV1
(
url
string
,
body
io
.
Reader
)
(
*
http
.
Response
,
error
)
{
resource
:=
`/ci/api/v1/builds/register.json`
return
http
.
Post
(
url
+
resource
,
`application/json`
,
body
)
}
func
TestBuildsLongPullingEndpointDisabled
(
t
*
testing
.
T
)
{
ws
:=
startWorkhorseServerWithLongPolling
(
"http://localhost/"
,
0
)
func
requestJobV4
(
url
string
,
body
io
.
Reader
)
(
*
http
.
Response
,
error
)
{
resource
:=
`/api/v4/jobs/request`
return
http
.
Post
(
url
+
resource
,
`application/json`
,
body
)
}
func
testJobsLongPolling
(
t
*
testing
.
T
,
pollingDuration
time
.
Duration
,
requestJob
requestJobFunction
)
*
http
.
Response
{
ws
:=
startWorkhorseServerWithLongPolling
(
"http://localhost/"
,
pollingDuration
)
defer
ws
.
Close
()
resp
,
err
:=
postBuildsRegister
(
ws
.
URL
,
nil
)
resp
,
err
:=
requestJob
(
ws
.
URL
,
nil
)
assert
.
NoError
(
t
,
err
)
defer
resp
.
Body
.
Close
()
return
resp
}
func
testJobsLongPollingEndpointDisabled
(
t
*
testing
.
T
,
requestJob
requestJobFunction
)
{
resp
:=
testJobsLongPolling
(
t
,
0
,
requestJob
)
assert
.
NotEqual
(
t
,
"yes"
,
resp
.
Header
.
Get
(
"Gitlab-Ci-Builds-Polling"
))
}
func
TestBuildsLongPullingEndpoint
(
t
*
testing
.
T
)
{
ws
:=
startWorkhorseServerWithLongPolling
(
"http://localhost/"
,
time
.
Minute
)
defer
ws
.
Close
()
func
testJobsLongPollingEndpoint
(
t
*
testing
.
T
,
requestJob
requestJobFunction
)
{
resp
:=
testJobsLongPolling
(
t
,
time
.
Minute
,
requestJob
)
assert
.
Equal
(
t
,
"yes"
,
resp
.
Header
.
Get
(
"Gitlab-Ci-Builds-Polling"
))
}
resp
,
err
:=
postBuildsRegister
(
ws
.
URL
,
nil
)
assert
.
NoError
(
t
,
err
)
defer
resp
.
Body
.
Close
()
func
TestJobsLongPollingEndpointDisabled
(
t
*
testing
.
T
)
{
testJobsLongPollingEndpointDisabled
(
t
,
requestJobV1
)
testJobsLongPollingEndpointDisabled
(
t
,
requestJobV4
)
}
assert
.
Equal
(
t
,
"yes"
,
resp
.
Header
.
Get
(
"Gitlab-Ci-Builds-Polling"
))
func
TestJobsLongPollingEndpoint
(
t
*
testing
.
T
)
{
testJobsLongPollingEndpoint
(
t
,
requestJobV1
)
testJobsLongPollingEndpoint
(
t
,
requestJobV4
)
}
upload_test.go
View file @
b06db824
...
...
@@ -17,28 +17,44 @@ import (
"gitlab.com/gitlab-org/gitlab-workhorse/internal/upload"
"github.com/dgrijalva/jwt-go"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func
TestArtifactsUpload
(
t
*
testing
.
T
)
{
type
uploadArtifactsFunction
func
(
url
,
contentType
string
,
body
io
.
Reader
)
(
*
http
.
Response
,
error
,
string
)
func
uploadArtifactsV1
(
url
,
contentType
string
,
body
io
.
Reader
)
(
*
http
.
Response
,
error
,
string
)
{
resource
:=
`/ci/api/v1/builds/123/artifacts`
resp
,
err
:=
http
.
Post
(
url
+
resource
,
contentType
,
body
)
return
resp
,
err
,
resource
}
func
uploadArtifactsV4
(
url
,
contentType
string
,
body
io
.
Reader
)
(
*
http
.
Response
,
error
,
string
)
{
resource
:=
`/api/v4/jobs/123/artifacts`
resp
,
err
:=
http
.
Post
(
url
+
resource
,
contentType
,
body
)
return
resp
,
err
,
resource
}
func
testArtifactsUpload
(
t
*
testing
.
T
,
uploadArtifacts
uploadArtifactsFunction
)
{
reqBody
,
contentType
,
err
:=
multipartBodyWithFile
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
require
.
NoError
(
t
,
err
)
ts
:=
uploadTestServer
(
t
,
nil
)
defer
ts
.
Close
()
ws
:=
startWorkhorseServer
(
ts
.
URL
)
defer
ws
.
Close
()
resource
:=
`/ci/api/v1/builds/123/artifacts`
resp
,
err
:=
http
.
Post
(
ws
.
URL
+
resource
,
contentType
,
reqBody
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
resp
,
err
,
resource
:=
uploadArtifacts
(
ws
.
URL
,
contentType
,
reqBody
)
assert
.
NoError
(
t
,
err
)
defer
resp
.
Body
.
Close
()
if
resp
.
StatusCode
!=
200
{
t
.
Errorf
(
"GET %q: expected 200, got %d"
,
resource
,
resp
.
StatusCode
)
}
assert
.
Equal
(
t
,
200
,
resp
.
StatusCode
,
"GET %q: expected 200, got %d"
,
resource
,
resp
.
StatusCode
)
}
func
TestArtifactsUpload
(
t
*
testing
.
T
)
{
testArtifactsUpload
(
t
,
uploadArtifactsV1
)
testArtifactsUpload
(
t
,
uploadArtifactsV4
)
}
func
uploadTestServer
(
t
*
testing
.
T
,
extraTests
func
(
r
*
http
.
Request
))
*
httptest
.
Server
{
...
...
vendor/github.com/stretchr/testify/require/doc.go
0 → 100644
View file @
b06db824
// Package require implements the same assertions as the `assert` package but
// stops test execution when a test fails.
//
// Example Usage
//
// The following is a complete example using require in a standard test function:
// import (
// "testing"
// "github.com/stretchr/testify/require"
// )
//
// func TestSomething(t *testing.T) {
//
// var a string = "Hello"
// var b string = "Hello"
//
// require.Equal(t, a, b, "The two words should be the same.")
//
// }
//
// Assertions
//
// The `require` package have same global functions as in the `assert` package,
// but instead of returning a boolean result they call `t.FailNow()`.
//
// Every assertion function also takes an optional string message as the final argument,
// allowing custom error messages to be appended to the message the assertion method outputs.
package
require
vendor/github.com/stretchr/testify/require/forward_requirements.go
0 → 100644
View file @
b06db824
package
require
// Assertions provides assertion methods around the
// TestingT interface.
type
Assertions
struct
{
t
TestingT
}
// New makes a new Assertions object for the specified TestingT.
func
New
(
t
TestingT
)
*
Assertions
{
return
&
Assertions
{
t
:
t
,
}
}
//go:generate go run ../_codegen/main.go -output-package=require -template=require_forward.go.tmpl
vendor/github.com/stretchr/testify/require/require.go
0 → 100644
View file @
b06db824
This diff is collapsed.
Click to expand it.
vendor/github.com/stretchr/testify/require/require.go.tmpl
0 → 100644
View file @
b06db824
{{.Comment}}
func {{.DocInfo.Name}}(t TestingT, {{.Params}}) {
if !assert.{{.DocInfo.Name}}(t, {{.ForwardedParams}}) {
t.FailNow()
}
}
vendor/github.com/stretchr/testify/require/require_forward.go
0 → 100644
View file @
b06db824
This diff is collapsed.
Click to expand it.
vendor/github.com/stretchr/testify/require/require_forward.go.tmpl
0 → 100644
View file @
b06db824
{{.CommentWithoutT "a"}}
func (a *Assertions) {{.DocInfo.Name}}({{.Params}}) {
{{.DocInfo.Name}}(a.t, {{.ForwardedParams}})
}
vendor/github.com/stretchr/testify/require/requirements.go
0 → 100644
View file @
b06db824
package
require
// TestingT is an interface wrapper around *testing.T
type
TestingT
interface
{
Errorf
(
format
string
,
args
...
interface
{})
FailNow
()
}
//go:generate go run ../_codegen/main.go -output-package=require -template=require.go.tmpl
vendor/vendor.json
View file @
b06db824
...
...
@@ -115,6 +115,12 @@
"revision"
:
"18a02ba4a312f95da08ff4cfc0055750ce50ae9e"
,
"revisionTime"
:
"2016-11-17T07:43:51Z"
},
{
"checksumSHA1"
:
"omdvCNu8sJIc9FbOfObC484M7Dg="
,
"path"
:
"github.com/stretchr/testify/require"
,
"revision"
:
"18a02ba4a312f95da08ff4cfc0055750ce50ae9e"
,
"revisionTime"
:
"2016-11-17T07:43:51Z"
},
{
"checksumSHA1"
:
"HWuFvDMQ5zp554X4QpVjBUgW5wk="
,
"path"
:
"gitlab.com/gitlab-org/gitaly-proto/go"
,
...
...
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