Preserve the underlying database error across all drivers and cover the wrapping behavior with focused tests. Make creation tests wait for the asynchronous completion callbacks to avoid timing-dependent assertions.
26 lines
571 B
Go
26 lines
571 B
Go
package postgres
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/usememos/memos/store"
|
|
)
|
|
|
|
type failingPostgresSpaceSummaryRow struct {
|
|
err error
|
|
}
|
|
|
|
func (row failingPostgresSpaceSummaryRow) Scan(...any) error {
|
|
return row.err
|
|
}
|
|
|
|
func TestScanPostgresSpaceSummaryWrapsErrors(t *testing.T) {
|
|
cause := errors.New("scan failed")
|
|
err := scanPostgresSpaceSummary(failingPostgresSpaceSummaryRow{err: cause}, &store.Space{})
|
|
|
|
require.ErrorIs(t, err, cause)
|
|
require.ErrorContains(t, err, "failed to populate PostgreSQL space summary")
|
|
}
|