Files
fn_registry/functions/infra/sqlite_column_exists_test.go
T
egutierrez 03568c88e3 chore: auto-commit (57 archivos)
- frontend/functions/core/format_datetime_short.md
- frontend/functions/core/format_datetime_short.test.ts
- frontend/functions/core/format_datetime_short.ts
- frontend/functions/core/format_duration.md
- frontend/functions/core/format_duration.test.ts
- frontend/functions/core/format_duration.ts
- frontend/functions/core/month_grid.md
- frontend/functions/core/month_grid.test.ts
- frontend/functions/core/month_grid.ts
- frontend/functions/core/string_hash_palette.md
- ...

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 03:41:58 +02:00

60 lines
1.3 KiB
Go

package infra
import (
"database/sql"
"testing"
_ "github.com/mattn/go-sqlite3"
)
func openMemDB(t *testing.T) *sql.DB {
t.Helper()
db, err := sql.Open("sqlite3", ":memory:")
if err != nil {
t.Fatalf("open :memory: db: %v", err)
}
t.Cleanup(func() { db.Close() })
return db
}
func TestColumnExists(t *testing.T) {
t.Run("columna existente retorna true", func(t *testing.T) {
db := openMemDB(t)
if _, err := db.Exec(`CREATE TABLE t (id INTEGER PRIMARY KEY, name TEXT)`); err != nil {
t.Fatal(err)
}
got, err := ColumnExists(db, "t", "name")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if !got {
t.Errorf("expected true for existing column 'name'")
}
})
t.Run("columna inexistente retorna false", func(t *testing.T) {
db := openMemDB(t)
if _, err := db.Exec(`CREATE TABLE t (id INTEGER PRIMARY KEY)`); err != nil {
t.Fatal(err)
}
got, err := ColumnExists(db, "t", "missing")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if got {
t.Errorf("expected false for missing column")
}
})
t.Run("tabla inexistente retorna false sin error", func(t *testing.T) {
db := openMemDB(t)
got, err := ColumnExists(db, "no_such_table", "col")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if got {
t.Errorf("expected false for non-existent table")
}
})
}