Files
ai-customer-service/internal/domain/intent/intent_test.go
Your Name 82a9306819 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

71 lines
1.6 KiB
Go

package intent
import "testing"
func TestResult_Fields(t *testing.T) {
r := Result{
Intent: IntentQuota,
Confidence: 0.95,
Entities: map[string]string{"key": "value"},
NeedsHuman: false,
Sensitive: false,
}
if r.Intent != IntentQuota {
t.Errorf("Intent = %q, want %q", r.Intent, IntentQuota)
}
if r.Confidence != 0.95 {
t.Errorf("Confidence = %f, want 0.95", r.Confidence)
}
if r.NeedsHuman {
t.Error("NeedsHuman = true, want false")
}
}
func TestResult_NeedsHuman(t *testing.T) {
r := Result{NeedsHuman: true}
if !r.NeedsHuman {
t.Error("NeedsHuman = false, want true")
}
}
func TestResult_Sensitive(t *testing.T) {
r := Result{Sensitive: true}
if !r.Sensitive {
t.Error("Sensitive = false, want true")
}
}
func TestResult_EntitiesMap(t *testing.T) {
r := Result{
Intent: IntentGeneral,
Entities: map[string]string{"user": "alice", "action": "refund"},
}
if len(r.Entities) != 2 {
t.Errorf("len(Entities) = %d, want 2", len(r.Entities))
}
if r.Entities["user"] != "alice" {
t.Errorf("Entities[user] = %q, want %q", r.Entities["user"], "alice")
}
}
func TestIntentConstants(t *testing.T) {
intents := []string{IntentQuota, IntentToken, IntentError, IntentHandoff, IntentGeneral, IntentRefund, IntentSecurity}
for _, intent := range intents {
if intent == "" {
t.Errorf("intent constant is empty string")
}
}
}
func TestIntentQuota(t *testing.T) {
if IntentQuota != "quota" {
t.Errorf("IntentQuota = %q, want %q", IntentQuota, "quota")
}
}
func TestIntentHandoff(t *testing.T) {
if IntentHandoff != "handoff" {
t.Errorf("IntentHandoff = %q, want %q", IntentHandoff, "handoff")
}
}