Skip to content

Commit 6bedb24

Browse files
committed
fix(test): use explicit schema parameter instead of db.Schema() for PostgreSQL/GaussDB tests
In GoFrame, db.Schema() changes the database name, not the PostgreSQL/GaussDB schema (namespace). For proper schema support, use db.Tables(ctx, schema) parameter instead. This fixes CI test failures where db.Schema("test_schema") was trying to connect to a non-existent database named "test_schema".
1 parent ca9bccf commit 6bedb24

2 files changed

Lines changed: 20 additions & 19 deletions

File tree

contrib/drivers/gaussdb/gaussdb_z_unit_issue_test.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -305,16 +305,16 @@ func Test_Issue4495_CacheIsolation(t *testing.T) {
305305
}
306306

307307
gtest.C(t, func(t *gtest.T) {
308-
// Get tables from schema1
309-
db1 := db.Schema(schema1)
310-
tables1, err := db1.Tables(ctx)
308+
// Get tables from schema1 using explicit schema parameter
309+
// Note: db.Schema() in GoFrame changes database name, not GaussDB schema.
310+
// For GaussDB schema support, we use db.Tables(ctx, schema) parameter.
311+
tables1, err := db.Tables(ctx, schema1)
311312
t.AssertNil(err)
312313
t.Assert(gstr.InArray(tables1, table1), true)
313314
t.Assert(gstr.InArray(tables1, table2), false)
314315

315316
// Get tables from schema2 - should NOT return schema1's cached result
316-
db2 := db.Schema(schema2)
317-
tables2, err := db2.Tables(ctx)
317+
tables2, err := db.Tables(ctx, schema2)
318318
t.AssertNil(err)
319319
t.Assert(gstr.InArray(tables2, table2), true)
320320
t.Assert(gstr.InArray(tables2, table1), false)
@@ -373,7 +373,9 @@ func Test_Issue4495_TableFields_KeyConstraints(t *testing.T) {
373373
}
374374

375375
// https://github.com/gogf/gf/issues/4495
376-
// Test Tables() with Namespace configuration.
376+
// Test Tables() with explicit schema parameter.
377+
// Note: In GaussDB (like PostgreSQL), db.Schema() changes the database name, not the schema.
378+
// For GaussDB schema support, use db.Tables(ctx, schema) parameter instead.
377379
func Test_Issue4495_Tables_WithNamespace(t *testing.T) {
378380
var (
379381
schema = fmt.Sprintf("test_ns_schema_%d", gtime.TimestampNano())
@@ -393,9 +395,8 @@ func Test_Issue4495_Tables_WithNamespace(t *testing.T) {
393395
}
394396

395397
gtest.C(t, func(t *gtest.T) {
396-
// Create a new db instance with Schema method
397-
dbWithSchema := db.Schema(schema)
398-
tables, err := dbWithSchema.Tables(ctx)
398+
// Use explicit schema parameter to get tables from specific schema
399+
tables, err := db.Tables(ctx, schema)
399400
t.AssertNil(err)
400401
t.Assert(gstr.InArray(tables, table), true)
401402
})

contrib/drivers/pgsql/pgsql_z_unit_issue_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -580,16 +580,16 @@ func Test_Issue4495_CacheIsolation(t *testing.T) {
580580
}
581581

582582
gtest.C(t, func(t *gtest.T) {
583-
// Get tables from schema1
584-
db1 := db.Schema(schema1)
585-
tables1, err := db1.Tables(ctx)
583+
// Get tables from schema1 using explicit schema parameter
584+
// Note: db.Schema() in GoFrame changes database name, not PostgreSQL schema.
585+
// For PostgreSQL schema support, we use db.Tables(ctx, schema) parameter.
586+
tables1, err := db.Tables(ctx, schema1)
586587
t.AssertNil(err)
587588
t.Assert(gstr.InArray(tables1, table1), true)
588589
t.Assert(gstr.InArray(tables1, table2), false)
589590

590591
// Get tables from schema2 - should NOT return schema1's cached result
591-
db2 := db.Schema(schema2)
592-
tables2, err := db2.Tables(ctx)
592+
tables2, err := db.Tables(ctx, schema2)
593593
t.AssertNil(err)
594594
t.Assert(gstr.InArray(tables2, table2), true)
595595
t.Assert(gstr.InArray(tables2, table1), false)
@@ -699,7 +699,9 @@ func Test_Issue4495_TableFields_FieldTypes(t *testing.T) {
699699
}
700700

701701
// https://github.com/gogf/gf/issues/4495
702-
// Test Tables() with Namespace configuration.
702+
// Test Tables() with explicit schema parameter.
703+
// Note: In PostgreSQL, db.Schema() changes the database name, not the PostgreSQL schema.
704+
// For PostgreSQL schema support, use db.Tables(ctx, schema) parameter instead.
703705
func Test_Issue4495_Tables_WithNamespace(t *testing.T) {
704706
var (
705707
schema = fmt.Sprintf("test_ns_schema_%d", gtime.TimestampNano())
@@ -719,10 +721,8 @@ func Test_Issue4495_Tables_WithNamespace(t *testing.T) {
719721
}
720722

721723
gtest.C(t, func(t *gtest.T) {
722-
// Create a new db instance with Namespace config
723-
// Note: This tests that Schema() method works correctly
724-
dbWithSchema := db.Schema(schema)
725-
tables, err := dbWithSchema.Tables(ctx)
724+
// Use explicit schema parameter to get tables from specific schema
725+
tables, err := db.Tables(ctx, schema)
726726
t.AssertNil(err)
727727
t.Assert(gstr.InArray(tables, table), true)
728728
})

0 commit comments

Comments
 (0)