feat: add fake send connector contract
This commit is contained in:
77
internal/tools/send_message_connector.go
Normal file
77
internal/tools/send_message_connector.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user