chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、 Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。 今日开发的培训推送管理改动随后单独提交。
This commit is contained in:
commit
7ec21f35b0
5767 files changed
+1436788
No files matched your search
@@ -0,0 +1,52 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
werrors "academy/internal/errors"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
func TestDocReaderFailure(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
err error
|
||||
code string
|
||||
}{
|
||||
{
|
||||
"scanned PDF wrapped connection failure",
|
||||
fmt.Errorf("anydoc fallback: %w",
|
||||
fmt.Errorf("read stream: %w",
|
||||
status.Error(codes.Unavailable,
|
||||
"private-address secret-token"))),
|
||||
werrors.ErrCodeDocReaderUnavailable,
|
||||
},
|
||||
{
|
||||
"HTTP connection failure",
|
||||
&net.OpError{
|
||||
Op: "dial",
|
||||
Err: errors.New("private-address secret-token"),
|
||||
},
|
||||
werrors.ErrCodeDocReaderUnavailable,
|
||||
},
|
||||
{"context timeout", fmt.Errorf("parse: %w", context.DeadlineExceeded), werrors.ErrCodeDocReaderTimeout},
|
||||
{"RPC timeout", status.Error(codes.DeadlineExceeded, "private-address"), werrors.ErrCodeDocReaderTimeout},
|
||||
{"parser failure", errors.New("private-address secret-token"), werrors.ErrCodeDocReaderParseFailed},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
code, message := docReaderFailure(tc.err)
|
||||
if code != tc.code || message == "" {
|
||||
t.Fatalf("got %q %q, want code %q", code, message, tc.code)
|
||||
}
|
||||
if strings.Contains(message, "private-address") || strings.Contains(message, "secret-token") {
|
||||
t.Fatal("raw transport diagnostics leaked into public message")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user