diff --git a/user/user.go b/user/user.go index 78abcd0..64b9db0 100644 --- a/user/user.go +++ b/user/user.go @@ -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 diff --git a/user/user_test.go b/user/user_test.go index cf3e3aa..94c0f1e 100644 --- a/user/user_test.go +++ b/user/user_test.go @@ -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) {