mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-09-25 20:51:52 +08:00
test: 补充单元测试覆盖率 29.9% → 36.6%
新建 18 个测试文件,追加 30 个已有测试文件,覆盖协议解析、 错误分类、CEL 表达式求值、YAML 反序列化、字节编码等纯函数。
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -32,3 +33,24 @@ func (c *redisReplyTestConn) RemoteAddr() net.Addr { return nil }
|
||||
func (c *redisReplyTestConn) SetDeadline(time.Time) error { return nil }
|
||||
func (c *redisReplyTestConn) SetReadDeadline(time.Time) error { return nil }
|
||||
func (c *redisReplyTestConn) SetWriteDeadline(time.Time) error { return nil }
|
||||
|
||||
func TestClassifyRedisErrorType(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
err error
|
||||
want ErrorType
|
||||
}{
|
||||
{"nil", nil, ErrorTypeUnknown},
|
||||
{"wrongpass", errors.New("wrongpass invalid password"), ErrorTypeAuth},
|
||||
{"noauth", errors.New("noauth authentication required"), ErrorTypeAuth},
|
||||
{"connection refused", errors.New("connection refused"), ErrorTypeNetwork},
|
||||
{"unknown", errors.New("random redis error"), ErrorTypeUnknown},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := classifyRedisErrorType(tt.err); got != tt.want {
|
||||
t.Errorf("classifyRedisErrorType() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user