Files
qitongxue-api/internal/logic/event_query_log_test.go
2026-09-29 10:57:01 +08:00

54 lines
1.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package logic
import (
"testing"
"tool-api/internal/consts"
)
// TestMaskOpenid 覆盖 A19 的 openid 脱敏:保留前 6 位 + "***",空串原样返回。
func TestMaskOpenid(t *testing.T) {
cases := map[string]string{
"": "",
" ": "",
"oABCDEFghijklmnop": "oABCDE***",
"oABCDE": "oABCDE***", // 恰好 6 位
"abc": "abc***", // 不足 6 位:全保留 + ***
"o6_bmjrPTlm6_2sgVt7hMZOPfL2M": "o6_bmj***",
}
for in, want := range cases {
if got := maskOpenid(in); got != want {
t.Fatalf("maskOpenid(%q)=%q want %q", in, got, want)
}
}
}
// TestSeatResultEnum 审计结果枚举与契约一致(0 失败 / 1 成功 / -1 全部)。
func TestSeatResultEnum(t *testing.T) {
if consts.SeatResultFail != 0 {
t.Fatalf("SeatResultFail=%d want 0", consts.SeatResultFail)
}
if consts.SeatResultSuccess != 1 {
t.Fatalf("SeatResultSuccess=%d want 1", consts.SeatResultSuccess)
}
if consts.SeatResultAll != -1 {
t.Fatalf("SeatResultAll=%d want -1", consts.SeatResultAll)
}
}
// TestQueryLogFilterVerdict 校验结果筛选判据:仅 0/1 触发过滤,其余(含 -1)视为全部。
func TestQueryLogFilterVerdict(t *testing.T) {
shouldFilter := func(result int) bool {
return result == consts.SeatResultFail || result == consts.SeatResultSuccess
}
if !shouldFilter(0) || !shouldFilter(1) {
t.Fatalf("0/1 应触发结果过滤")
}
if shouldFilter(-1) {
t.Fatalf("-1(全部)不应过滤")
}
if shouldFilter(99) {
t.Fatalf("非法值应视为全部,不应过滤")
}
}