Skip to content

Commit e40bf3e

Browse files
committed
Improved error checking in tests
1 parent 620b1ca commit e40bf3e

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

bun_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,17 @@ func TestBun(t *testing.T) {
7979
sqldb := sql.OpenDB(pgconn)
8080
db := bun.NewDB(sqldb, pgdialect.New())
8181

82-
db.Exec("CREATE EXTENSION IF NOT EXISTS vector")
83-
db.Exec("DROP TABLE IF EXISTS bun_items")
82+
_, err := db.Exec("CREATE EXTENSION IF NOT EXISTS vector")
83+
if err != nil {
84+
panic(err)
85+
}
86+
87+
_, err = db.Exec("DROP TABLE IF EXISTS bun_items")
88+
if err != nil {
89+
panic(err)
90+
}
8491

85-
_, err := db.NewCreateTable().Model((*BunItem)(nil)).Exec(ctx)
92+
_, err = db.NewCreateTable().Model((*BunItem)(nil)).Exec(ctx)
8693
if err != nil {
8794
panic(err)
8895
}

gorm_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ func TestGorm(t *testing.T) {
5757
db.Exec("CREATE EXTENSION IF NOT EXISTS vector")
5858
db.Exec("DROP TABLE IF EXISTS gorm_items")
5959

60-
db.AutoMigrate(&GormItem{})
60+
err = db.AutoMigrate(&GormItem{})
61+
if err != nil {
62+
panic(err)
63+
}
6164

6265
db.Exec("CREATE INDEX ON gorm_items USING hnsw (embedding vector_l2_ops)")
6366

pg_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,17 @@ func TestPg(t *testing.T) {
6262
})
6363
defer db.Close()
6464

65-
db.Exec("CREATE EXTENSION IF NOT EXISTS vector")
66-
db.Exec("DROP TABLE IF EXISTS pg_items")
65+
_, err := db.Exec("CREATE EXTENSION IF NOT EXISTS vector")
66+
if err != nil {
67+
panic(err)
68+
}
69+
70+
_, err = db.Exec("DROP TABLE IF EXISTS pg_items")
71+
if err != nil {
72+
panic(err)
73+
}
6774

68-
err := db.Model((*PgItem)(nil)).CreateTable(&orm.CreateTableOptions{})
75+
err = db.Model((*PgItem)(nil)).CreateTable(&orm.CreateTableOptions{})
6976
if err != nil {
7077
panic(err)
7178
}

sqlx_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ func TestSqlx(t *testing.T) {
5858
CreateSqlxItems(db)
5959

6060
var items []SqlxItem
61-
db.Select(&items, "SELECT * FROM sqlx_items ORDER BY embedding <-> $1 LIMIT 5", pgvector.NewVector([]float32{1, 1, 1}))
61+
err := db.Select(&items, "SELECT * FROM sqlx_items ORDER BY embedding <-> $1 LIMIT 5", pgvector.NewVector([]float32{1, 1, 1}))
62+
if err != nil {
63+
panic(err)
64+
}
6265
if items[0].Id != 1 || items[1].Id != 3 || items[2].Id != 2 {
6366
t.Error()
6467
}

0 commit comments

Comments
 (0)