56 lines
1.8 KiB
Go
56 lines
1.8 KiB
Go
package tools
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestBRouteSendMessageConnectorDisabledMode(t *testing.T) {
|
|
connector := NewBRouteSendMessageConnector(BRouteSendAdapterConfig{Mode: "disabled"})
|
|
result, err := connector.ExecuteSendMessage(context.Background(), SendMessageConnectorRequest{
|
|
TargetType: "direct",
|
|
TargetID: "u1",
|
|
TargetRef: "contact:u1",
|
|
ContentSHA256: "abc",
|
|
ContentLength: 3,
|
|
IdempotencyKeySHA256: "idem",
|
|
ExecutionMode: "production",
|
|
})
|
|
if err == nil {
|
|
t.Fatalf("expected disabled error")
|
|
}
|
|
if result.ErrorCode != "broute_mode_blocked" {
|
|
t.Fatalf("unexpected error code: %s", result.ErrorCode)
|
|
}
|
|
if result.ConnectorMode != "broute-disabled" {
|
|
t.Fatalf("connector mode = %q, want broute-disabled", result.ConnectorMode)
|
|
}
|
|
}
|
|
|
|
func TestBRouteSendMessageConnectorDryRunContract(t *testing.T) {
|
|
connector := NewBRouteSendMessageConnector(BRouteSendAdapterConfig{
|
|
SidecarPath: `Z:\path\that\must\not\be\started\SendSidecar.exe`,
|
|
TimeoutSeconds: 5,
|
|
Mode: "dry_run_contract",
|
|
})
|
|
result, err := connector.ExecuteSendMessage(context.Background(), SendMessageConnectorRequest{
|
|
TargetType: "direct",
|
|
TargetID: "u1",
|
|
TargetRef: "contact:u1",
|
|
ContentSHA256: strings.Repeat("a", 64),
|
|
ContentLength: 3,
|
|
IdempotencyKeySHA256: strings.Repeat("b", 64),
|
|
ExecutionMode: "production",
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("dry-run contract should not try to start a sidecar or return process error: %v", err)
|
|
}
|
|
if result.Accepted {
|
|
t.Fatalf("dry-run contract must not accept a real send: %+v", result)
|
|
}
|
|
if result.ConnectorMode != "broute-dry-run-contract" || result.ErrorCode != "broute_dry_run_only" {
|
|
t.Fatalf("unexpected dry-run result: %+v", result)
|
|
}
|
|
}
|