fix(bolt): handle user not found error

pull/10616/head
Chris Goller 2018-10-11 12:06:10 -05:00
parent 9015cb3a83
commit 332caa524e
2 changed files with 19 additions and 1 deletions

View File

@ -91,8 +91,14 @@ func (c *Client) FindUserByName(ctx context.Context, n string) (*platform.User,
}
func (c *Client) findUserByName(ctx context.Context, tx *bolt.Tx, n string) (*platform.User, error) {
u := tx.Bucket(userIndex).Get(userIndexKey(n))
if u == nil {
// TODO: Make standard error
return nil, fmt.Errorf("user not found")
}
var id platform.ID
if err := id.Decode(tx.Bucket(userIndex).Get(userIndexKey(n))); err != nil {
if err := id.Decode(u); err != nil {
return nil, err
}
return c.findUserByID(ctx, tx, id)

View File

@ -563,6 +563,18 @@ func FindUser(
},
},
},
{
name: "user does not exist",
fields: UserFields{
Users: []*platform.User{},
},
args: args{
name: "abc",
},
wants: wants{
err: fmt.Errorf("user not found"),
},
},
}
for _, tt := range tests {