forked from mtusi2026/mtusi2026lab5
chore(migrate) moved codebase from lab4
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
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) == nil
|
||||
if got != test.ok {
|
||||
t.Fatalf("ValidateIdempotencyKey(%q) valid = %v, want %v", test.key, got, test.ok)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user