Skip to content

Commit 31b566d

Browse files
authored
Fix error message for missing user (#113)
1 parent cf5cb07 commit 31b566d

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

auth/user_mgt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ func (c *Client) getUser(ctx context.Context, request *identitytoolkit.Identityt
567567
return nil, err
568568
}
569569
if len(resp.Users) == 0 {
570-
return nil, fmt.Errorf("cannot find user from params: %v", request)
570+
return nil, fmt.Errorf("cannot find user given params: id:%v, phone:%v, email: %v", request.LocalId, request.PhoneNumber, request.Email)
571571
}
572572

573573
eu, err := makeExportedUser(resp.Users[0])

auth/user_mgt_test.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,24 @@ func TestGetNonExistingUser(t *testing.T) {
148148
s := echoServer([]byte(resp), t)
149149
defer s.Close()
150150

151-
user, err := s.Client.GetUser(context.Background(), "ignored_id")
152-
if user != nil || err == nil {
153-
t.Errorf("GetUser(non-existing) = (%v, %v); want = (nil, error)", user, err)
151+
want := "cannot find user given params: id:[%s], phone:[%s], email: [%s]"
152+
153+
we := fmt.Sprintf(want, "id-nonexisting", "", "")
154+
user, err := s.Client.GetUser(context.Background(), "id-nonexisting")
155+
if user != nil || err == nil || err.Error() != we {
156+
t.Errorf("GetUser(non-existing) = (%v, %q); want = (nil, %q)", user, err, we)
154157
}
155-
user, err = s.Client.GetUserByEmail(context.Background(), "[email protected]")
156-
if user != nil || err == nil {
157-
t.Errorf("GetUserByEmail(non-existing) = (%v, %v); want = (nil, error)", user, err)
158+
159+
we = fmt.Sprintf(want, "", "", "[email protected]")
160+
user, err = s.Client.GetUserByEmail(context.Background(), "[email protected]")
161+
if user != nil || err == nil || err.Error() != we {
162+
t.Errorf("GetUserByEmail(non-existing) = (%v, %q); want = (nil, %q)", user, err, we)
158163
}
159-
user, err = s.Client.GetUserByPhoneNumber(context.Background(), "+1234567890")
160-
if user != nil || err == nil {
161-
t.Errorf("GetUserPhoneNumber(non-existing) = (%v, %v); want = (nil, error)", user, err)
164+
165+
we = fmt.Sprintf(want, "", "+12345678901", "")
166+
user, err = s.Client.GetUserByPhoneNumber(context.Background(), "+12345678901")
167+
if user != nil || err == nil || err.Error() != we {
168+
t.Errorf("GetUserPhoneNumber(non-existing) = (%v, %q); want = (nil, %q)", user, err, we)
162169
}
163170
}
164171

integration/auth/user_mgt_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ func TestUserManagement(t *testing.T) {
4040
}{
4141
{"Create test users", testCreateUsers},
4242
{"Get user", testGetUser},
43+
{"Get user by phone", testGetUserByPhoneNumber},
44+
{"Get user by email", testGetUserByEmail},
4345
{"Iterate users", testUserIterator},
4446
{"Paged iteration", testPager},
4547
{"Disable user account", testDisableUser},
@@ -96,7 +98,8 @@ func testCreateUsers(t *testing.T) {
9698
UID(uid).
9799
Email(uid + "[email protected]").
98100
DisplayName("display_name").
99-
Password("password")
101+
Password("password").
102+
PhoneNumber("+12223334444")
100103

101104
if u, err = client.CreateUser(context.Background(), params); err != nil {
102105
t.Fatal(err)

0 commit comments

Comments
 (0)