Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dex
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
dex
Commits
2ed28598
Commit
2ed28598
authored
Sep 29, 2015
by
Joe Bowers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
repo: functional repo tests
includes changes to ensure uniform errors for DB and in-memory repos
parent
e5db3023
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
2 deletions
+65
-2
user.go
db/user.go
+6
-2
user_repo_test.go
functional/repo/user_repo_test.go
+56
-0
user.go
user/user.go
+3
-0
No files found.
db/user.go
View file @
2ed28598
...
...
@@ -112,8 +112,12 @@ func (r *userRepo) Disable(tx repo.Transaction, userID string, disable bool) err
return
err
}
if
ct
,
err
:=
result
.
RowsAffected
();
err
==
nil
&&
ct
==
0
{
return
user
.
ErrorInvalidID
ct
,
err
:=
result
.
RowsAffected
()
switch
{
case
err
!=
nil
:
return
err
case
ct
==
0
:
return
user
.
ErrorNotFound
}
return
nil
...
...
functional/repo/user_repo_test.go
View file @
2ed28598
...
...
@@ -35,6 +35,7 @@ var (
ID
:
"ID-2"
,
Email
:
"Email-2@example.com"
,
CreatedAt
:
time
.
Now
(),
Disabled
:
true
,
},
RemoteIdentities
:
[]
user
.
RemoteIdentity
{
{
...
...
@@ -232,6 +233,61 @@ func TestUpdateUser(t *testing.T) {
}
}
func
TestDisableUser
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
id
string
disable
bool
err
error
}{
{
id
:
"ID-1"
,
},
{
id
:
"ID-1"
,
disable
:
true
,
},
{
id
:
"ID-2"
,
},
{
id
:
"ID-2"
,
disable
:
true
,
},
{
id
:
"NO SUCH ID"
,
err
:
user
.
ErrorNotFound
,
},
{
id
:
"NO SUCH ID"
,
err
:
user
.
ErrorNotFound
,
disable
:
true
,
},
{
id
:
""
,
err
:
user
.
ErrorInvalidID
,
},
}
for
i
,
tt
:=
range
tests
{
repo
:=
makeTestUserRepo
()
err
:=
repo
.
Disable
(
nil
,
tt
.
id
,
tt
.
disable
)
switch
{
case
err
!=
tt
.
err
:
t
.
Errorf
(
"case %d: want=%q, got=%q"
,
i
,
tt
.
err
,
err
)
case
tt
.
err
==
nil
:
gotUser
,
err
:=
repo
.
Get
(
nil
,
tt
.
id
)
if
err
!=
nil
{
t
.
Fatalf
(
"case %d: want nil err, got %q"
,
i
,
err
)
}
if
gotUser
.
Disabled
!=
tt
.
disable
{
t
.
Errorf
(
"case %d: disabled status want=%v got=%v"
,
i
,
tt
.
disable
,
gotUser
.
Disabled
)
}
}
}
}
func
TestAttachRemoteIdentity
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
id
string
...
...
user/user.go
View file @
2ed28598
...
...
@@ -257,6 +257,9 @@ func (r *memUserRepo) Update(_ repo.Transaction, user User) error {
}
func
(
r
*
memUserRepo
)
Disable
(
_
repo
.
Transaction
,
id
string
,
disable
bool
)
error
{
if
id
==
""
{
return
ErrorInvalidID
}
user
,
ok
:=
r
.
usersByID
[
id
]
if
!
ok
{
return
ErrorNotFound
...
...
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