CI / Nginx config check (push) Successful in 13s
CI / Env docs check (push) Successful in 15s
CI / Docker compose check (push) Successful in 15s
CI / Frontend major deps (push) Failing after 24s
CI / Frontend deps check (push) Successful in 30s
CI / Secrets scan (push) Successful in 38s
CI / Go build (push) Successful in 39s
CI / Frontend build (push) Successful in 1m3s
CI / Knip (push) Successful in 45s
CI / Go vet (prod) (push) Failing after 1m42s
CI / Frontend a11y check (push) Successful in 2m34s
CI / Go vet (dev) (push) Successful in 2m29s
CI / Staticcheck (prod) (push) Failing after 2m38s
CI / go mod tidy (push) Successful in 1m3s
CI / Staticcheck (dev) (push) Successful in 2m55s
CI / Frontend QC (audit) (push) Successful in 51s
CI / golangci-lint (push) Successful in 3m22s
CI / Go vulnerabilities (push) Successful in 1m26s
CI / Frontend QC (typecheck) (push) Successful in 2m18s
CI / Security scan (prod) (push) Successful in 4m18s
CI / Security scan (dev) (push) Successful in 4m40s
CI / Tests (prod) (push) Has been skipped
CI / Tests (dev) (push) Has been skipped
CI / Race (prod) (push) Has been skipped
CI / Race (dev) (push) Has been skipped
CI / Frontend QC (lint) (push) Successful in 2m18s
CI / Svelte strict check (push) Successful in 43s
New test files cover previously untested paths across DAV, validators, S3, Square, mw, bookings, user, and payments packages. Includes mock fix: HoldCheckouts flag on MockClient allows tests to pause auto-complete goroutine for testing PENDING checkout states. Coverage: 50.4% → 65.0% (+14.6pp)
163 lines
4.4 KiB
Go
163 lines
4.4 KiB
Go
//go:build test
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// =============================================================================
|
|
// ContextWithTx / TxFromContext round-trip
|
|
// =============================================================================
|
|
|
|
func TestContextWithTx_RoundTrip(t *testing.T) {
|
|
closePool()
|
|
resetEnv()
|
|
err := Connect()
|
|
require.NoError(t, err)
|
|
defer closePool()
|
|
|
|
ctx := context.Background()
|
|
pool := Conn.Pool()
|
|
|
|
tx, err := pool.Begin(ctx)
|
|
require.NoError(t, err)
|
|
defer tx.Rollback(ctx) //nolint:errcheck
|
|
|
|
txCtx := ContextWithTx(ctx, tx)
|
|
extracted := TxFromContext(txCtx)
|
|
|
|
assert.NotNil(t, extracted, "TxFromContext should return a non-nil tx")
|
|
assert.Equal(t, tx, extracted, "extracted tx should be the same as the one stored")
|
|
}
|
|
|
|
// =============================================================================
|
|
// TxFromContext with no transaction in context
|
|
// =============================================================================
|
|
|
|
func TestTxFromContext_NoTx(t *testing.T) {
|
|
ctx := context.Background()
|
|
tx := TxFromContext(ctx)
|
|
assert.Nil(t, tx, "TxFromContext should return nil when no tx in context")
|
|
}
|
|
|
|
// =============================================================================
|
|
// PoolProxy.Exec routes through context transaction
|
|
// =============================================================================
|
|
|
|
func TestPoolProxy_Exec_RoutesThroughTx(t *testing.T) {
|
|
closePool()
|
|
resetEnv()
|
|
err := Connect()
|
|
require.NoError(t, err)
|
|
defer closePool()
|
|
|
|
ctx := context.Background()
|
|
pool := Conn.Pool()
|
|
|
|
tx, err := pool.Begin(ctx)
|
|
require.NoError(t, err)
|
|
defer tx.Rollback(ctx) //nolint:errcheck
|
|
|
|
txCtx := ContextWithTx(ctx, tx)
|
|
|
|
_, err = Conn.Exec(txCtx, "CREATE TEMP TABLE test_exec_routing (id INT PRIMARY KEY)")
|
|
require.NoError(t, err)
|
|
|
|
_, err = Conn.Exec(txCtx, "INSERT INTO test_exec_routing VALUES (1)")
|
|
require.NoError(t, err)
|
|
|
|
var count int
|
|
err = Conn.QueryRow(txCtx, "SELECT COUNT(*) FROM test_exec_routing").Scan(&count)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, 1, count)
|
|
|
|
err = tx.Rollback(ctx)
|
|
require.NoError(t, err)
|
|
|
|
_, err = Conn.Exec(ctx, "SELECT COUNT(*) FROM test_exec_routing")
|
|
assert.Error(t, err, "expected error querying temp table after rollback")
|
|
}
|
|
|
|
// =============================================================================
|
|
// PoolProxy.QueryRow routes through context transaction
|
|
// =============================================================================
|
|
|
|
func TestPoolProxy_QueryRow_RoutesThroughTx(t *testing.T) {
|
|
closePool()
|
|
resetEnv()
|
|
err := Connect()
|
|
require.NoError(t, err)
|
|
defer closePool()
|
|
|
|
ctx := context.Background()
|
|
pool := Conn.Pool()
|
|
|
|
tx, err := pool.Begin(ctx)
|
|
require.NoError(t, err)
|
|
defer tx.Rollback(ctx) //nolint:errcheck
|
|
|
|
txCtx := ContextWithTx(ctx, tx)
|
|
|
|
_, err = Conn.Exec(txCtx, "CREATE TEMP TABLE test_queryrow_routing (id INT PRIMARY KEY, val TEXT)")
|
|
require.NoError(t, err)
|
|
|
|
_, err = Conn.Exec(txCtx, "INSERT INTO test_queryrow_routing VALUES (42, 'routed')")
|
|
require.NoError(t, err)
|
|
|
|
var id int
|
|
var val string
|
|
err = Conn.QueryRow(txCtx, "SELECT id, val FROM test_queryrow_routing WHERE id = 42").Scan(&id, &val)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, 42, id)
|
|
assert.Equal(t, "routed", val)
|
|
|
|
err = tx.Rollback(ctx)
|
|
require.NoError(t, err)
|
|
|
|
err = Conn.QueryRow(ctx, "SELECT id, val FROM test_queryrow_routing WHERE id = 42").Scan(&id, &val)
|
|
assert.Error(t, err, "expected error querying temp table via pool after rollback")
|
|
}
|
|
|
|
// =============================================================================
|
|
// PoolProxy.Begin returns a real transaction
|
|
// =============================================================================
|
|
|
|
func TestPoolProxy_Begin_ReturnsTx(t *testing.T) {
|
|
closePool()
|
|
resetEnv()
|
|
err := Connect()
|
|
require.NoError(t, err)
|
|
defer closePool()
|
|
|
|
ctx := context.Background()
|
|
|
|
tx, err := Conn.Begin(ctx)
|
|
require.NoError(t, err)
|
|
assert.NotNil(t, tx)
|
|
|
|
err = tx.Rollback(ctx)
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
// =============================================================================
|
|
// PoolProxy.Ping works
|
|
// =============================================================================
|
|
|
|
func TestPoolProxy_Ping_Works(t *testing.T) {
|
|
closePool()
|
|
resetEnv()
|
|
err := Connect()
|
|
require.NoError(t, err)
|
|
defer closePool()
|
|
|
|
ctx := context.Background()
|
|
|
|
err = Conn.Ping(ctx)
|
|
assert.NoError(t, err)
|
|
}
|