Перенес основы lab3 в lab4

This commit is contained in:
Daria0w0
2026-11-06 14:44:30 +03:00
parent ec540a1a72
commit 9197e151ba
59 changed files with 4761 additions and 3 deletions
+25
View File
@@ -0,0 +1,25 @@
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)
}
}
}