Files
sendico/api/payments/storage/model/gateway_affinity_identity_test.go
2026-02-18 20:38:08 +01:00

30 lines
1.1 KiB
Go

package model
import "testing"
func TestGatewayIdentityKey(t *testing.T) {
if got, want := GatewayIdentityKey(" gw ", "inst-1", "grpc://one"), "gw|inst-1"; got != want {
t.Fatalf("unexpected gateway identity key: got=%q want=%q", got, want)
}
if got, want := GatewayIdentityKey("gw", "", " grpc://one "), "gw|grpc://one"; got != want {
t.Fatalf("unexpected gateway identity key with invoke fallback: got=%q want=%q", got, want)
}
if got, want := GatewayIdentityKey(" gw ", "", ""), "gw"; got != want {
t.Fatalf("unexpected gateway identity key with id only: got=%q want=%q", got, want)
}
if got := GatewayIdentityKey("", "inst-1", "grpc://one"); got != "" {
t.Fatalf("expected empty key when gateway id missing, got=%q", got)
}
}
func TestLessGatewayDescriptor(t *testing.T) {
a := &GatewayInstanceDescriptor{ID: "gw", InstanceID: "inst-a", InvokeURI: "grpc://a"}
b := &GatewayInstanceDescriptor{ID: "gw", InstanceID: "inst-b", InvokeURI: "grpc://b"}
if !LessGatewayDescriptor(a, b) {
t.Fatalf("expected inst-a to sort before inst-b")
}
if LessGatewayDescriptor(b, a) {
t.Fatalf("expected inst-b not to sort before inst-a")
}
}