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,32 @@
|
||||
package dbxshared
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type testDialect string
|
||||
|
||||
func (d testDialect) String() string { return string(d) }
|
||||
|
||||
type stubLogger struct{}
|
||||
|
||||
func (stubLogger) InitLogger() {}
|
||||
|
||||
func TestInitLogger_UnregisteredDialect(t *testing.T) {
|
||||
ResetLoggerRegistry()
|
||||
t.Cleanup(ResetLoggerRegistry)
|
||||
|
||||
err := InitLogger(testDialect("mysql"))
|
||||
assert.ErrorContains(t, err, "blank-import dbxm")
|
||||
}
|
||||
|
||||
func TestInitLogger_RegisteredDialect(t *testing.T) {
|
||||
ResetLoggerRegistry()
|
||||
t.Cleanup(ResetLoggerRegistry)
|
||||
|
||||
RegisterLogger(testDialect("mysql"), stubLogger{})
|
||||
err := InitLogger(testDialect("mysql"))
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
Reference in New Issue
Block a user