chore(init): 初始化解忧商行项目并完成 Phase 0 基座

This commit is contained in:
yml2213
2026-10-30 11:46:10 +08:00
commit 8d9481c251
689 changed files with 138703 additions and 0 deletions
@@ -0,0 +1,36 @@
package logging
import (
"bytes"
"strings"
"testing"
"time"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
func TestTextEncoderProducesReadableSingleLine(t *testing.T) {
var output bytes.Buffer
core := zapcore.NewCore(newTextEncoder(time.UTC), zapcore.AddSync(&output), zapcore.DebugLevel)
logger := zap.New(core)
logger.Info("服务启动",
zap.String("request_id", "req-1"),
zap.String("empty", ""),
zap.String("detail", "line1\nline2"),
)
got := output.String()
if strings.ContainsAny(got, "{}") {
t.Fatalf("output should not use JSON object syntax: %s", got)
}
if !strings.Contains(got, "INFO | 服务启动 | request_id=req-1") {
t.Fatalf("unexpected text output: %s", got)
}
if strings.Contains(got, "empty=") {
t.Fatalf("empty fields should be omitted: %s", got)
}
if strings.Count(got, "\n") != 1 || !strings.Contains(got, `detail="line1\nline2"`) {
t.Fatalf("output should remain one physical line: %q", got)
}
}