Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
go-gitlab
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
go-gitlab
Commits
eb011b7a
Commit
eb011b7a
authored
Mar 20, 2018
by
pityonline
Committed by
Sander van Harmelen
Mar 22, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add tests for validate
* valid case * invalid case
parent
c074f053
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
0 deletions
+76
-0
validate_test.go
validate_test.go
+76
-0
No files found.
validate_test.go
0 → 100644
View file @
eb011b7a
package
gitlab
import
(
"fmt"
"net/http"
"reflect"
"testing"
)
// TODO: better test posting empty string
func
TestValidate
(
t
*
testing
.
T
)
{
validContent
:=
`
build1:
stage: build
script:
- echo "Do your build here"`
invalidContent
:=
`
build1:
- echo "Do your build here"`
validRes
:=
`{
"status": "valid",
"errors": []
}`
invalidRes
:=
`{
"status": "invalid",
"errors": [
"error message when content is invalid"
]
}`
wantValid
:=
&
LintResult
{
Status
:
"valid"
,
Errors
:
[]
string
{},
}
wantInvalid
:=
&
LintResult
{
Status
:
"invalid"
,
Errors
:
[]
string
{
"error message when content is invalid"
},
}
testCases
:=
[]
struct
{
desc
string
content
string
res
string
want
*
LintResult
}{
{
"valid"
,
validContent
,
validRes
,
wantValid
},
{
"invalid"
,
invalidContent
,
invalidRes
,
wantInvalid
},
}
for
_
,
tc
:=
range
testCases
{
t
.
Run
(
tc
.
desc
,
func
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
mux
.
HandleFunc
(
"/ci/lint"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"POST"
)
fmt
.
Fprintf
(
w
,
tc
.
res
)
})
got
,
_
,
err
:=
client
.
Validate
.
Lint
(
tc
.
content
)
if
err
!=
nil
{
t
.
Errorf
(
"Validate returned error: %v"
,
err
)
}
want
:=
tc
.
want
if
!
reflect
.
DeepEqual
(
got
,
want
)
{
t
.
Errorf
(
"Validate returned
\n
got:
\n
%v
\n
want:
\n
%v"
,
Stringify
(
got
),
Stringify
(
want
))
}
})
}
}
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