feat: add fake send connector contract

This commit is contained in:
zhaoyilun
2026-07-10 20:22:02 +08:00
parent 9eb7f382cc
commit dadf42817c
6 changed files with 343 additions and 18 deletions

View File

@@ -0,0 +1,77 @@
package tools
import (
"context"
"strings"
)
type SendMessageConnector interface {
ExecuteSendMessage(context.Context, SendMessageConnectorRequest) (SendMessageConnectorResult, error)
}
type SendMessageConnectorRequest struct {
TargetType string
TargetID string
TargetRef string
ContentSHA256 string
ContentLength int
IdempotencyKeySHA256 string
ExecutionMode string
}
type SendMessageConnectorResult struct {
Accepted bool
Status string
AckRef string
ErrorCode string
ErrorMessage string
ConnectorMode string
}
func sendMessageConnectorRequestFromNormalized(input normalizedSendMessageArgs) SendMessageConnectorRequest {
return SendMessageConnectorRequest{
TargetType: input.TargetType,
TargetID: input.TargetID,
TargetRef: input.TargetRef,
ContentSHA256: input.ContentSHA256,
ContentLength: input.ContentLength,
IdempotencyKeySHA256: input.IdempotencyKeySHA256,
ExecutionMode: input.ExecutionMode,
}
}
func normalizeSendMessageConnectorResult(result SendMessageConnectorResult, err error) SendMessageConnectorResult {
normalized := result
normalized.Status = strings.TrimSpace(normalized.Status)
normalized.AckRef = strings.TrimSpace(normalized.AckRef)
normalized.ErrorCode = strings.TrimSpace(normalized.ErrorCode)
normalized.ErrorMessage = strings.TrimSpace(normalized.ErrorMessage)
normalized.ConnectorMode = strings.TrimSpace(normalized.ConnectorMode)
if normalized.ConnectorMode == "" {
normalized.ConnectorMode = sendMessageConnectorMode
}
if err != nil {
normalized.Accepted = false
if normalized.Status == "" {
normalized.Status = "failed"
}
if normalized.ErrorCode == "" {
normalized.ErrorCode = "connector_error"
}
if normalized.ErrorMessage == "" {
normalized.ErrorMessage = err.Error()
}
return normalized
}
if normalized.Status == "" {
if normalized.Accepted {
normalized.Status = "accepted"
} else {
normalized.Status = "failed"
}
}
if !normalized.Accepted && normalized.ErrorCode == "" {
normalized.ErrorCode = "connector_rejected"
}
return normalized
}