Files
lijiaoqiao/projects/ai-customer-service/internal/domain/message/message_test.go
Your Name d88369f880 test(P1): 补齐 domain/intent、domain/message、domain/ticketstats、platform/logging、service/intent、config 测试
**新增测试文件**:
- internal/domain/intent/intent_test.go: 6 个测试(Recognize 各意图分支、containsAny)
- internal/domain/message/message_test.go: 4 个测试(UnifiedMessage 各字段)
- internal/domain/ticketstats/stats_test.go: 5 个测试(Stats 各字段、零值、nil map)
- internal/platform/logging/logger_test.go: 6 个测试(NewLogger 各日志级别)
- internal/service/intent/service_test.go: 6 个新增测试(通用意图、大小写、空格、containsAny)

**增强测试文件**:
- internal/config/config_test.go: +11 个测试(getEnvBool 全部分支、getEnvInt 无效值、getEnvInt64)
- internal/app/app_test.go: +3 个测试(Shutdown 关闭器顺序、nil 分支)

**覆盖率提升**:
- internal/service/intent: 80.8% → **100.0%** 
- internal/platform/logging: 0% → **100.0%** 
- internal/config: 70.6% → **82.4%** (+11.8%)
- 整体覆盖率: 76.6% → **77.1%** (+0.5%)

Ref: test/PHASE2_TEST_PLAN.md P1-1, P1-2
2026-05-01 11:43:05 +08:00

77 lines
1.6 KiB
Go

package message
import (
"testing"
"time"
)
func TestUnifiedMessage_Fields(t *testing.T) {
now := time.Now()
msg := UnifiedMessage{
MessageID: "msg_123",
Channel: "widget",
OpenID: "user_456",
UserID: "internal_789",
Content: "hello world",
ContentType: "text/plain",
Timestamp: now,
ReplyTo: "parent_msg",
}
if msg.MessageID != "msg_123" {
t.Errorf("MessageID = %q, want %q", msg.MessageID, "msg_123")
}
if msg.Channel != "widget" {
t.Errorf("Channel = %q, want %q", msg.Channel, "widget")
}
if msg.Content != "hello world" {
t.Errorf("Content = %q, want %q", msg.Content, "hello world")
}
if msg.ReplyTo != "parent_msg" {
t.Errorf("ReplyTo = %q, want %q", msg.ReplyTo, "parent_msg")
}
}
func TestUnifiedMessage_OptionalFields(t *testing.T) {
msg := UnifiedMessage{
MessageID: "msg_1",
Channel: "web",
OpenID: "u1",
Content: "hi",
}
if msg.UserID != "" {
t.Errorf("UserID = %q, want empty", msg.UserID)
}
if msg.ContentType != "" {
t.Errorf("ContentType = %q, want empty", msg.ContentType)
}
if msg.ReplyTo != "" {
t.Errorf("ReplyTo = %q, want empty", msg.ReplyTo)
}
}
func TestUnifiedMessage_Timestamp(t *testing.T) {
now := time.Now()
msg := UnifiedMessage{
MessageID: "msg_1",
Channel: "widget",
OpenID: "u1",
Content: "test",
Timestamp: now,
}
if msg.Timestamp.IsZero() {
t.Error("Timestamp is zero, want time.Time")
}
}
func TestUnifiedMessage_EmptyContent(t *testing.T) {
msg := UnifiedMessage{
MessageID: "msg_1",
Channel: "widget",
OpenID: "u1",
Content: "",
}
if msg.Content != "" {
t.Errorf("Content = %q, want empty", msg.Content)
}
}