Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
cloudProject
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Job Bahner
cloudProject
Commits
c3904ba7
Commit
c3904ba7
authored
5 years ago
by
Johannes Borgen
Browse files
Options
Downloads
Patches
Plain Diff
added test for unvalid review post
parent
917396b7
No related branches found
No related tags found
1 merge request
!4
Finished app
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
reviews_test.go
+46
-0
46 additions, 0 deletions
reviews_test.go
with
46 additions
and
0 deletions
reviews_test.go
+
46
−
0
View file @
c3904ba7
package
cloudproject
package
cloudproject
import
(
import
(
"bytes"
"encoding/json"
"encoding/json"
"net/http"
"net/http"
"net/http/httptest"
"net/http/httptest"
...
@@ -53,3 +54,48 @@ func TestReviewHandleGet(t *testing.T) {
...
@@ -53,3 +54,48 @@ func TestReviewHandleGet(t *testing.T) {
}
}
}
}
func
TestReviewHandlePostBogus
(
t
*
testing
.
T
)
{
/**
Need to set up DB so reviewhandler can test connectivity
*/
const
projectID
=
"altocumulus-5c3b3"
const
reviews
=
"reviews"
DB
=
FirestoreDatabase
{
ProjectID
:
projectID
,
CollectionName
:
reviews
}
err
:=
DB
.
Init
()
if
err
!=
nil
{
t
.
Error
(
err
)
}
defer
DB
.
Close
()
/**
make new request to review handler
*/
data
:=
[]
byte
(
`{"navn": "", "turid": "", "beskrivelse": "", "terningkast": 100}`
)
req
,
err
:=
http
.
NewRequest
(
"POST"
,
"/review/"
,
bytes
.
NewBuffer
(
data
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
rr
:=
httptest
.
NewRecorder
()
/**
check if handler response is 200
*/
if
status
:=
rr
.
Code
;
status
!=
http
.
StatusOK
{
t
.
Errorf
(
"handler returned wrong status code: got %v want %v"
,
status
,
http
.
StatusOK
)
}
handler
:=
http
.
HandlerFunc
(
ReviewHandler
)
handler
.
ServeHTTP
(
rr
,
req
)
/**
Check the response body is what we expect.
*/
// check if bogus input returns a badrequest
response
:=
rr
.
Code
if
response
!=
http
.
StatusBadRequest
{
t
.
Errorf
(
"Bogus input passed: %d"
,
response
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment