26 lines
729 B
Go
26 lines
729 B
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestIdempotencyKeyValidation(t *testing.T) {
|
|
for _, key := range []string{"a", "retry-1._:ABC09", strings.Repeat("a", 128)} {
|
|
if !idempotencyKeyPattern.MatchString(key) {
|
|
t.Fatalf("valid key rejected: %q", key)
|
|
}
|
|
}
|
|
for _, key := range []string{"", " ", "a b", "ключ", "a\n", strings.Repeat("a", 129)} {
|
|
// Nil DB ensures invalid input is rejected before any storage call.
|
|
m := NewPersistentMessenger(nil)
|
|
_, err := m.CreateMessage(context.Background(), "actor",
|
|
"12345678-1234-4234-8234-123456789abc", "hello", key)
|
|
if !errors.Is(err, ErrInvalidRequest) {
|
|
t.Fatalf("key %q: got %v, want invalid request", key, err)
|
|
}
|
|
}
|
|
}
|