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:
2026-06-29 17:50:31 -07:00
parent 8d697eda5b
commit 63187ee905
5 changed files with 105 additions and 5 deletions
+45
View File
@@ -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())
}