fix: 修复写队列 busy 恢复、关闭安全、备份与配置构建问题

This commit is contained in:
Nixevol
2026-09-30 16:21:05 +08:00
parent 4059a1576b
commit 57c2f70678
23 changed files with 825 additions and 101 deletions
+56
View File
@@ -48,6 +48,62 @@ func TestLoadAndValidate(t *testing.T) {
}
}
func TestLoadExplicitZeroGraceSeconds(t *testing.T) {
t.Parallel()
dir := t.TempDir()
path := filepath.Join(dir, "config.yaml")
body := "listen: \"127.0.0.1:0\"\ndata_dir: \"" + filepath.ToSlash(dir) + "\"\nlimits:\n grace_seconds: 0\n"
if err := os.WriteFile(path, []byte(body), 0o644); err != nil {
t.Fatal(err)
}
cfg, err := Load(path)
if err != nil {
t.Fatal(err)
}
if err := cfg.Validate(); err != nil {
t.Fatal(err)
}
if cfg.Limits.GraceSeconds != 0 {
t.Fatalf("grace_seconds=%d, want 0", cfg.Limits.GraceSeconds)
}
if cfg.Limits.MaxBodyBytes != MaxBodyBytesCap {
t.Fatalf("omitted max_body_bytes=%d", cfg.Limits.MaxBodyBytes)
}
}
func TestValidateRejectsMaxFrameBytesTooLarge(t *testing.T) {
t.Parallel()
cfg := Default()
cfg.Limits.MaxFrameBytes = MaxFrameBytesCap + 1
err := cfg.Validate()
if err == nil {
t.Fatal("expected error")
}
if !strings.Contains(err.Error(), "max_frame_bytes") {
t.Fatalf("unexpected error: %v", err)
}
}
func TestLoadExplicitZeroMaxBodyBytesRejected(t *testing.T) {
t.Parallel()
dir := t.TempDir()
path := filepath.Join(dir, "config.yaml")
body := "listen: \"127.0.0.1:0\"\ndata_dir: \"" + filepath.ToSlash(dir) + "\"\nlimits:\n max_body_bytes: 0\n"
if err := os.WriteFile(path, []byte(body), 0o644); err != nil {
t.Fatal(err)
}
cfg, err := Load(path)
if err != nil {
t.Fatal(err)
}
if cfg.Limits.MaxBodyBytes != 0 {
t.Fatalf("max_body_bytes=%d, want explicit 0", cfg.Limits.MaxBodyBytes)
}
if err := cfg.Validate(); err == nil || !strings.Contains(err.Error(), "max_body_bytes") {
t.Fatalf("want max_body_bytes error, got %v", err)
}
}
func TestValidateTrustedProxies(t *testing.T) {
t.Parallel()
cfg := Default()