test: 补充单元测试覆盖率 29.9% → 36.6%
测试构建 / 代码检查 (push) Has been cancelled
测试构建 / 单元测试和构建 (push) Has been cancelled
测试构建 / 构建验证 (push) Has been cancelled

新建 18 个测试文件,追加 30 个已有测试文件,覆盖协议解析、
错误分类、CEL 表达式求值、YAML 反序列化、字节编码等纯函数。
This commit is contained in:
ZacharyZcR
2026-06-15 19:11:15 +08:00
parent d7dbccab76
commit 353d525642
48 changed files with 7556 additions and 1 deletions
+23
View File
@@ -6,6 +6,7 @@ import (
"bytes"
"encoding/base64"
"encoding/binary"
"errors"
"strings"
"testing"
"time"
@@ -128,3 +129,25 @@ func TestBuildMongoSCRAMClientFinalBuildsProof(t *testing.T) {
t.Fatalf("client final = %q", got)
}
}
func TestClassifyMongoDBErrorType(t *testing.T) {
tests := []struct {
name string
err error
want ErrorType
}{
{"nil", nil, ErrorTypeUnknown},
{"authentication failed", errors.New("authentication failed"), ErrorTypeAuth},
{"bad auth", errors.New("bad auth"), ErrorTypeAuth},
{"dial tcp", errors.New("dial tcp connection refused"), ErrorTypeNetwork},
{"eof", errors.New("eof"), ErrorTypeNetwork},
{"unknown", errors.New("random mongodb error"), ErrorTypeUnknown},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := classifyMongoDBErrorType(tt.err); got != tt.want {
t.Errorf("classifyMongoDBErrorType() = %v, want %v", got, tt.want)
}
})
}
}