Files
mtusi2026lab3/app/internal/common/idempotency_key_test.go
T
2026-10-30 18:11:30 +03:00

31 lines
712 B
Go

package common
import (
"strings"
"testing"
)
func TestValidateIdempotencyKey(t *testing.T) {
tests := []struct {
name string
key string
ok bool
}{
{name: "hex", key: "4f8c2d1e", ok: true},
{name: "allowed punctuation", key: "load-1_a.b:c", ok: true},
{name: "empty", key: "", ok: false},
{name: "space", key: "two words", ok: false},
{name: "slash", key: "a/b", ok: false},
{name: "too long", key: strings.Repeat("a", 129), ok: false},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got := ValidateIdempotencyKey(test.key) == ""
if got != test.ok {
t.Fatalf("ValidateIdempotencyKey(%q) valid = %v, want %v", test.key, got, test.ok)
}
})
}
}