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
f4839529
Commit
f4839529
authored
Apr 27, 2018
by
Joe Rocklin
Committed by
Sander van Harmelen
Mar 07, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add user_test for unblock
parent
9941edd6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
0 deletions
+88
-0
users.go
users.go
+6
-0
users_test.go
users_test.go
+82
-0
No files found.
users.go
View file @
f4839529
...
...
@@ -22,6 +22,12 @@ import (
"time"
)
var
(
UserBlockPreventedError
=
fmt
.
Errorf
(
"Cannot block a user that is already blocked by LDAP synchronization"
)
UserNotFoundError
=
fmt
.
Errorf
(
"User does not exist"
)
UserUnblockPreventedError
=
fmt
.
Errorf
(
"Cannot unblock a user that is blocked by LDAP synchronization"
)
)
// UsersService handles communication with the user related methods of
// the GitLab API.
//
...
...
users_test.go
0 → 100644
View file @
f4839529
package
gitlab
import
(
"fmt"
"net/http"
"reflect"
"testing"
)
func
TestUnblockUser
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
mux
.
HandleFunc
(
"/users/1/unblock"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"POST"
)
w
.
WriteHeader
(
http
.
StatusCreated
)
})
err
:=
client
.
Users
.
UnblockUser
(
1
)
if
err
!=
nil
{
t
.
Errorf
(
"Users.UnblockUser returned error: %v"
,
err
)
}
}
func
TestUnblockUser_UserNotFound
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
mux
.
HandleFunc
(
"/users/1/unblock"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"POST"
)
w
.
WriteHeader
(
http
.
StatusNotFound
)
})
err
:=
client
.
Users
.
UnblockUser
(
1
)
if
err
!=
UserNotFoundError
{
t
.
Errorf
(
"Users.UnblockUser error.
\n
Expected: %+v
\n
Got: %+v"
,
UserNotFoundError
,
err
)
}
}
func
TestUnblockUser_UnblockPrevented
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
mux
.
HandleFunc
(
"/users/1/unblock"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"POST"
)
w
.
WriteHeader
(
http
.
StatusForbidden
)
})
err
:=
client
.
Users
.
UnblockUser
(
1
)
if
err
!=
UserUnblockPreventedError
{
t
.
Errorf
(
"Users.UnblockUser error.
\n
Expected: %+v
\n
Got: %+v"
,
UserUnblockPreventedError
,
err
)
}
}
func
TestUnblockUser_UnknownError
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
mux
.
HandleFunc
(
"/users/1/unblock"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"POST"
)
w
.
WriteHeader
(
http
.
StatusTeapot
)
})
want
:=
fmt
.
Errorf
(
"Received unexpected result code: %d"
,
http
.
StatusTeapot
)
err
:=
client
.
Users
.
UnblockUser
(
1
)
if
!
reflect
.
DeepEqual
(
err
,
want
)
{
t
.
Errorf
(
"Users.UnblockUser error.
\n
Expected: %+v
\n
Got: %+v"
,
want
,
err
)
}
}
func
TestUnblockUser_BadResponseFromNet
(
t
*
testing
.
T
)
{
client
:=
NewClient
(
nil
,
""
)
client
.
SetBaseURL
(
""
)
want
:=
"Post /users/1/unblock: unsupported protocol scheme
\"\"
"
err
:=
client
.
Users
.
UnblockUser
(
1
)
if
err
.
Error
()
!=
want
{
t
.
Errorf
(
"Users.UnblockUser error.
\n
Expected: %+v
\n
Got: %+v"
,
want
,
err
)
}
}
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