feat: complete contract-driven business development and MySQL integration
This commit is contained in:
33
logx/adapters_test.go
Normal file
33
logx/adapters_test.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package logx
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"log/slog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestValidateBeforeOpeningWriter(t *testing.T) {
|
||||
p := filepath.Join(t.TempDir(), "must-not-exist.log")
|
||||
for _, cfg := range []Config{{File: p, Format: "typo"}, {File: p, Level: "typo"}, {File: p, Output: "typo"}} {
|
||||
if cfg.Validate() == nil {
|
||||
t.Fatal("invalid configuration accepted")
|
||||
}
|
||||
if _, err := New(cfg); err == nil {
|
||||
t.Fatal("invalid logger created")
|
||||
}
|
||||
if _, err := os.Stat(p); !os.IsNotExist(err) {
|
||||
t.Fatal("validation touched filesystem", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
func TestStandardLoggerUsesBorrowedInstance(t *testing.T) {
|
||||
var out bytes.Buffer
|
||||
l, _ := New(Config{Writer: &out})
|
||||
l.Standard(slog.LevelWarn).Print("driver diagnostic")
|
||||
if !strings.Contains(out.String(), `"level":"WARN"`) || !strings.Contains(out.String(), "driver diagnostic") {
|
||||
t.Fatal(out.String())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user