на оценку 4

This commit is contained in:
2026-11-22 23:33:11 +03:00
parent 20afc2c790
commit cc41f601e3
207 changed files with 22098 additions and 120 deletions
+35
View File
@@ -0,0 +1,35 @@
package config
import "testing"
func TestInstanceIDFromEnvironment(t *testing.T) {
t.Setenv("INSTANCE_ID", "api-replica_01")
instanceID, err := instanceIDFromEnv()
if err != nil {
t.Fatal(err)
}
if instanceID != "api-replica_01" {
t.Fatalf("got %q, want api-replica_01", instanceID)
}
}
func TestInstanceIDRejectsUnsafeHeaderValue(t *testing.T) {
t.Setenv("INSTANCE_ID", "api-1\r\nX-Forged: true")
if _, err := instanceIDFromEnv(); err == nil {
t.Fatal("expected unsafe instance ID to be rejected")
}
}
func TestInstanceIDGeneratesOpaqueAlias(t *testing.T) {
t.Setenv("INSTANCE_ID", "")
instanceID, err := instanceIDFromEnv()
if err != nil {
t.Fatal(err)
}
if instanceID == "" {
t.Fatal("random alias returned an empty instance ID")
}
}