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
d5898459
Commit
d5898459
authored
Nov 23, 2015
by
Martin Sefcik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Used local instead of global vars
parent
30b9d9e6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
32 deletions
+24
-32
gitlab_test.go
gitlab_test.go
+12
-20
projects_test.go
projects_test.go
+12
-12
No files found.
gitlab_test.go
View file @
d5898459
...
...
@@ -10,32 +10,25 @@ import (
"testing"
)
var
(
// mux is the HTTP request multiplexer used with the test server.
mux
*
http
.
ServeMux
// client is the Gitlab client being tested.
client
*
Client
// server is a test HTTP server used to provide mock API responses.
server
*
httptest
.
Server
)
// setup sets up a test HTTP server along with a gitlab.Client that is
// configured to talk to that test server. Tests should register handlers on
// mux which provide mock responses for the API method being tested.
func
setup
()
{
// test server
mux
=
http
.
NewServeMux
()
server
=
httptest
.
NewServer
(
mux
)
func
setup
()
(
*
http
.
ServeMux
,
*
httptest
.
Server
,
*
Client
)
{
// mux is the HTTP request multiplexer used with the test server.
mux
:=
http
.
NewServeMux
()
// gitlab client configured to use test server
client
=
NewClient
(
nil
,
""
)
// server is a test HTTP server used to provide mock API responses.
server
:=
httptest
.
NewServer
(
mux
)
// client is the Gitlab client being tested.
client
:=
NewClient
(
nil
,
""
)
client
.
SetBaseURL
(
server
.
URL
)
return
mux
,
server
,
client
}
// teardown closes the test HTTP server.
func
teardown
()
{
func
teardown
(
server
*
httptest
.
Server
)
{
server
.
Close
()
}
...
...
@@ -112,4 +105,4 @@ func TestCheckResponse(t *testing.T) {
if
!
reflect
.
DeepEqual
(
err
,
want
)
{
t
.
Errorf
(
"Error = %#v, want %#v"
,
err
,
want
)
}
}
\ No newline at end of file
}
projects_test.go
View file @
d5898459
...
...
@@ -8,8 +8,8 @@ import (
)
func
TestListProjects
(
t
*
testing
.
T
)
{
setup
()
defer
teardown
()
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
mux
.
HandleFunc
(
"/projects"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"GET"
)
...
...
@@ -39,8 +39,8 @@ func TestListProjects(t *testing.T) {
}
func
TestListOwnedProjects
(
t
*
testing
.
T
)
{
setup
()
defer
teardown
()
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
mux
.
HandleFunc
(
"/projects/owned"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"GET"
)
...
...
@@ -70,8 +70,8 @@ func TestListOwnedProjects(t *testing.T) {
}
func
TestListAllProjects
(
t
*
testing
.
T
)
{
setup
()
defer
teardown
()
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
mux
.
HandleFunc
(
"/projects/all"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"GET"
)
...
...
@@ -101,8 +101,8 @@ func TestListAllProjects(t *testing.T) {
}
func
TestGetProject
(
t
*
testing
.
T
)
{
setup
()
defer
teardown
()
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
mux
.
HandleFunc
(
"/projects/1"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"GET"
)
...
...
@@ -122,8 +122,8 @@ func TestGetProject(t *testing.T) {
}
func
TestSearchProjects
(
t
*
testing
.
T
)
{
setup
()
defer
teardown
()
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
mux
.
HandleFunc
(
"/projects/search/query"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"GET"
)
...
...
@@ -150,8 +150,8 @@ func TestSearchProjects(t *testing.T) {
}
func
TestCreateProject
(
t
*
testing
.
T
)
{
setup
()
defer
teardown
()
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
mux
.
HandleFunc
(
"/projects"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"POST"
)
...
...
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