63187ee905
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>
46 lines
835 B
Go
46 lines
835 B
Go
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())
|
|
}
|