ЛР 3 — БВТ2303 — Брезгунова — на 5

This commit is contained in:
2026-10-22 14:21:19 +03:00
parent 0ab3a341aa
commit 59adbebe68
124 changed files with 125809 additions and 54 deletions
+38
View File
@@ -0,0 +1,38 @@
package main
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
)
func TestIdempotencyKeySyntax(t *testing.T) {
for _, key := range []string{"a", "A._:-012", strings.Repeat("x", 128)} {
if !idempotencyPattern.MatchString(key) {
t.Fatalf("valid key rejected: %q", key)
}
}
for _, key := range []string{"", "space key", "ключ", strings.Repeat("a", 129), "a\nb"} {
if idempotencyPattern.MatchString(key) {
t.Fatalf("invalid key accepted: %q", key)
}
}
}
func TestDrainingReadinessAndBusiness(t *testing.T) {
a := &app{instanceID: "replica-under-test", limits: loadLimits()}
a.draining.Store(true)
for _, path := range []string{"/health/ready", "/api/v1/users/me"} {
w := httptest.NewRecorder()
a.routes().ServeHTTP(w, httptest.NewRequest(http.MethodGet, path, nil))
if w.Code != 503 || w.Header().Get("X-Instance-Id") != a.instanceID {
t.Fatalf("draining request %s: %d", path, w.Code)
}
}
w := httptest.NewRecorder()
a.routes().ServeHTTP(w, httptest.NewRequest(http.MethodGet, "/health/live", nil))
if w.Code != 200 {
t.Fatal("liveness lost during drain")
}
}