fix: harden module lifecycle and debug log setup
Export CurrentDialect(), return setup errors when debug logger is not registered, and guard DestName logging when the module is uninitialized. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package dbx
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gitea.auvem.com/go-toolkit/dbx/internal/dbxshared"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestDestName_MissingFieldWithoutModule(t *testing.T) {
|
||||
type Foo struct {
|
||||
Bar int
|
||||
}
|
||||
|
||||
name := DestName(Foo{}, "Missing")
|
||||
assert.Empty(t, name)
|
||||
}
|
||||
|
||||
func TestDestName_ValidPath(t *testing.T) {
|
||||
type Inner struct {
|
||||
Value string
|
||||
}
|
||||
type Foo struct {
|
||||
Inner Inner
|
||||
}
|
||||
|
||||
name := DestName(Foo{}, "Inner", "Value")
|
||||
assert.Equal(t, "Foo.Inner.Value", name)
|
||||
}
|
||||
|
||||
func TestDialect_AfterModuleDB(t *testing.T) {
|
||||
if dbxshared.DBModule != nil {
|
||||
t.Skip("database module already initialized")
|
||||
}
|
||||
|
||||
_ = ModuleDB(DialectPostgres, &DBConfig{
|
||||
User: "user",
|
||||
Password: "pass",
|
||||
URI: "localhost:5432",
|
||||
Name: "test",
|
||||
MaxConn: 1,
|
||||
}, false)
|
||||
|
||||
assert.Equal(t, DialectPostgres, CurrentDialect())
|
||||
}
|
||||
Reference in New Issue
Block a user