storage/inmemory: fix Patch() error handling (#4839)

storage/inmemory: fix Patch() error handling (#4838)

The Patch() method was intended to skip any records that do not
currently exist. However, currently inmemory.Backend.Patch() will return
ErrNotFound if the last record in the records slice is not found (it
will ignore any other previous records that are not found).

Update the error handling logic here to be consistent with the postgres
backend, and add a unit test to exercise this case.

Co-authored-by: Kenneth Jenkins <51246568+kenjenkins@users.noreply.github.com>
This commit is contained in:
backport-actions-token[bot] 2023-12-07 14:07:32 -07:00 committed by GitHub
parent 8c5f44ae42
commit 33b4662187
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View file

@ -269,12 +269,12 @@ func (backend *Backend) Patch(
// Skip any record that does not currently exist.
continue
} else if err != nil {
return
return serverVersion, patchedRecords, err
}
patchedRecords = append(patchedRecords, record)
}
return
return serverVersion, patchedRecords, nil
}
// patch updates the specified fields of an existing record, assuming the RWMutex is held.

View file

@ -34,6 +34,17 @@ func TestBackendPatch(t *testing.T, ctx context.Context, backend storage.Backend
}
}
t.Run("not found", func(t *testing.T) {
mask, err := fieldmaskpb.New(&session.Session{}, "oauth_token")
require.NoError(t, err)
s := &session.Session{Id: "session-id-that-does-not-exist"}
_, updated, err := backend.Patch(ctx, []*databroker.Record{mkRecord(s)}, mask)
require.NoError(t, err)
assert.Empty(t, updated)
})
t.Run("basic", func(t *testing.T) {
// Populate an initial set of session records.
s1 := &session.Session{