Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
git-web-server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
large-scale-dev
git-web-server
Commits
05ddf332
Commit
05ddf332
authored
9 years ago
by
Simon Lindblad
Browse files
Options
Downloads
Patches
Plain Diff
Add unit tests for task management
parent
607696ee
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
todo_test.go
+63
-0
63 additions, 0 deletions
todo_test.go
with
63 additions
and
0 deletions
todo_test.go
+
63
−
0
View file @
05ddf332
...
...
@@ -6,6 +6,7 @@ import (
"net/http/httptest"
"testing"
"strings"
"strconv"
"encoding/json"
"bytes"
)
...
...
@@ -31,6 +32,68 @@ func setup(t *testing.T) {
}
func
TestTask
(
test
*
testing
.
T
)
{
setup
(
test
)
testServer
:=
httptest
.
NewServer
(
Handlers
())
defer
testServer
.
Close
()
b
,
err
:=
json
.
Marshal
(
ListCreateRequest
{
Name
:
"Work"
})
checkFail
(
test
,
err
)
res
,
err
:=
http
.
Post
(
testServer
.
URL
+
"/list"
,
"application/json"
,
bytes
.
NewReader
(
b
))
checkFail
(
test
,
err
)
listResp
:=
ListCreateResponse
{}
body
,
err
:=
ioutil
.
ReadAll
(
res
.
Body
)
defer
res
.
Body
.
Close
()
err
=
json
.
Unmarshal
(
body
,
&
listResp
)
res
,
err
=
http
.
Get
(
testServer
.
URL
+
"/list/"
+
strconv
.
Itoa
(
listResp
.
Id
))
checkFail
(
test
,
err
)
if
res
.
StatusCode
!=
200
{
test
.
Errorf
(
"Expected 200 got %d"
,
res
.
StatusCode
)
}
body
,
err
=
ioutil
.
ReadAll
(
res
.
Body
)
defer
res
.
Body
.
Close
()
var
tasks
[]
Task
err
=
json
.
Unmarshal
(
body
,
&
tasks
)
checkFail
(
test
,
err
)
if
len
(
tasks
)
!=
0
{
test
.
Errorf
(
"Expected len(tasks) == 0 got %d"
,
len
(
tasks
))
}
b
,
err
=
json
.
Marshal
(
CreateTaskRequest
{
Name
:
"Work"
,
ListId
:
listResp
.
Id
})
checkFail
(
test
,
err
)
res
,
err
=
http
.
Post
(
testServer
.
URL
+
"/task"
,
"application/json"
,
bytes
.
NewReader
(
b
))
checkFail
(
test
,
err
)
if
res
.
StatusCode
!=
200
{
test
.
Errorf
(
"Expected 200, got %d"
)
}
res
,
err
=
http
.
Get
(
testServer
.
URL
+
"/list/"
+
strconv
.
Itoa
(
listResp
.
Id
))
checkFail
(
test
,
err
)
if
res
.
StatusCode
!=
200
{
test
.
Errorf
(
"Expected 200 got %d"
,
res
.
StatusCode
)
}
body
,
err
=
ioutil
.
ReadAll
(
res
.
Body
)
defer
res
.
Body
.
Close
()
err
=
json
.
Unmarshal
(
body
,
&
tasks
)
checkFail
(
test
,
err
)
if
len
(
tasks
)
!=
1
{
test
.
Errorf
(
"Expected len(tasks) == 1 got %d"
,
len
(
tasks
))
}
}
func
TestList
(
test
*
testing
.
T
)
{
setup
(
test
)
testServer
:=
httptest
.
NewServer
(
Handlers
())
...
...
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