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
607696ee
Commit
607696ee
authored
9 years ago
by
Simon Lindblad
Browse files
Options
Downloads
Patches
Plain Diff
Add unit tests for list management
parent
a1bc39ba
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
+83
-0
83 additions, 0 deletions
todo_test.go
with
83 additions
and
0 deletions
todo_test.go
0 → 100644
+
83
−
0
View file @
607696ee
package
main
import
(
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
"strings"
"encoding/json"
"bytes"
)
func
checkFail
(
t
*
testing
.
T
,
err
error
)
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
func
setup
(
t
*
testing
.
T
)
{
db
:=
ConnectDb
()
defer
db
.
Close
()
sqlData
,
err
:=
ioutil
.
ReadFile
(
"schema.sql"
)
checkFail
(
t
,
err
)
sqlStmts
:=
string
(
sqlData
)
for
_
,
stmt
:=
range
strings
.
Split
(
sqlStmts
,
";"
)
{
_
,
err
:=
db
.
Exec
(
stmt
)
checkFail
(
t
,
err
)
}
}
func
TestList
(
test
*
testing
.
T
)
{
setup
(
test
)
testServer
:=
httptest
.
NewServer
(
Handlers
())
defer
testServer
.
Close
()
res
,
err
:=
http
.
Get
(
testServer
.
URL
+
"/list"
)
checkFail
(
test
,
err
)
body
,
err
:=
ioutil
.
ReadAll
(
res
.
Body
)
res
.
Body
.
Close
()
if
res
.
StatusCode
!=
200
{
test
.
Errorf
(
"Expected status code 200 got %d"
,
res
.
StatusCode
)
}
var
lists
[]
List
err
=
json
.
Unmarshal
(
body
,
&
lists
)
checkFail
(
test
,
err
)
if
len
(
lists
)
!=
0
{
test
.
Errorf
(
"Expected [] got %s"
,
lists
)
}
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
)
if
res
.
StatusCode
!=
200
{
test
.
Errorf
(
"Expected status code 200 got %d"
,
res
.
StatusCode
)
}
res
,
err
=
http
.
Get
(
testServer
.
URL
+
"/list"
)
checkFail
(
test
,
err
)
body
,
err
=
ioutil
.
ReadAll
(
res
.
Body
)
res
.
Body
.
Close
()
if
res
.
StatusCode
!=
200
{
test
.
Errorf
(
"Expected status code 200 got %d"
,
res
.
StatusCode
)
}
err
=
json
.
Unmarshal
(
body
,
&
lists
)
checkFail
(
test
,
err
)
if
len
(
lists
)
!=
1
{
test
.
Errorf
(
"Expected [] got %s"
,
lists
)
}
}
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