Skip to content
This repository has been archived by the owner on Apr 26, 2021. It is now read-only.

Commit

Permalink
user: improve error reporting for Remove
Browse files Browse the repository at this point in the history
Related to #183.
  • Loading branch information
Francisco Souza committed Feb 19, 2015
1 parent df183b9 commit e33c216
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ func Remove(name string) error {
}
defer conn.Close()
if err := conn.User().Find(bson.M{"_id": name}).One(&u); err != nil {
return fmt.Errorf("Could not remove user: %s", err)
if err == mgo.ErrNotFound {
return ErrUserNotFound
}
return err
}
if err := u.handleAssociatedRepositories(); err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions user/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ func (s *S) TestRemoveRemovesKeyFromAuthorizedKeysFile(c *check.C) {
c.Assert(got, check.Equals, "")
}

func (s *S) TestRemoveInexistentUserReturnsDescriptiveMessage(c *check.C) {
func (s *S) TestRemoveNotFound(c *check.C) {
err := Remove("otheruser")
c.Assert(err, check.ErrorMatches, "Could not remove user: not found")
c.Assert(err, check.Equals, ErrUserNotFound)
}

func (s *S) TestRemoveDoesNotRemovesUserWhenUserIsTheOnlyOneAssciatedWithOneRepository(c *check.C) {
Expand Down

0 comments on commit e33c216

Please sign in to comment.