feat(postgres)!: promote to v1.0.0 — BeginTx with pgx options, Stats, bump all deps to v1.0.0
Add BeginTx(ctx, pgx.TxOptions) to Client interface for explicit isolation level and
read-only transaction control; Begin refactored as a convenience wrapper calling
BeginTx(ctx, pgx.TxOptions{}). Add Stats() *pgxpool.Stat to Component interface for
connection pool observability. Bump all micro-lib dependencies (logz, health, launcher,
xerrors) from v0.9.0 to v1.0.0. API committed as stable.
This commit is contained in:
@@ -105,9 +105,10 @@ func (m *mockTx) Rollback(ctx context.Context) error
|
||||
|
||||
type mockClient struct{ tx *mockTx }
|
||||
|
||||
func (m *mockClient) Begin(ctx context.Context) (Tx, error) { return m.tx, nil }
|
||||
func (m *mockClient) Ping(ctx context.Context) error { return nil }
|
||||
func (m *mockClient) HandleError(err error) error { return HandleError(err) }
|
||||
func (m *mockClient) Begin(ctx context.Context) (Tx, error) { return m.tx, nil }
|
||||
func (m *mockClient) BeginTx(ctx context.Context, opts pgx.TxOptions) (Tx, error) { return m.tx, nil }
|
||||
func (m *mockClient) Ping(ctx context.Context) error { return nil }
|
||||
func (m *mockClient) HandleError(err error) error { return HandleError(err) }
|
||||
func (m *mockClient) GetExecutor(ctx context.Context) Executor {
|
||||
if tx, ok := ctx.Value(ctxTxKey{}).(Executor); ok {
|
||||
return tx
|
||||
@@ -149,6 +150,24 @@ func TestUnitOfWork_InjectsExecutor(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// --- BeginTx / Stats ---
|
||||
|
||||
func TestComponent_BeginTx_NilPool(t *testing.T) {
|
||||
c := &pgComponent{logger: newLogger()}
|
||||
_, err := c.BeginTx(context.Background(), pgx.TxOptions{})
|
||||
if err == nil {
|
||||
t.Error("expected error for nil pool")
|
||||
}
|
||||
}
|
||||
|
||||
func TestComponent_Stats_NilPool(t *testing.T) {
|
||||
c := &pgComponent{logger: newLogger()}
|
||||
stats := c.Stats()
|
||||
if stats == nil {
|
||||
t.Error("Stats() should return non-nil zero value when pool is nil")
|
||||
}
|
||||
}
|
||||
|
||||
// --- helpers ---
|
||||
|
||||
func assertCode(t *testing.T, err error, want xerrors.Code) {
|
||||
|
||||
Reference in New Issue
Block a user