package transcode import ( "testing" "time" ) // TestDefaultLimitsPinnedToDesign 把 design/25 §2.5 的**取值**钉在测试里: // 谁改了默认限额(比如把输入上限从 5 MiB 调大),这条断言就会红,逼他回设计对账。 // 设计原文:5 MiB 进 / 64 MiB 出 / 10 分钟 / 并发 2 / 超时 10s。 func TestDefaultLimitsPinnedToDesign(t *testing.T) { got := DefaultLimits() if got.MaxInputBytes != 5<<20 { t.Errorf("MaxInputBytes = %d, want %d (5 MiB)", got.MaxInputBytes, 5<<20) } if got.MaxOutputBytes != 64<<20 { t.Errorf("MaxOutputBytes = %d, want %d (64 MiB)", got.MaxOutputBytes, 64<<20) } if got.MaxDuration != 10*time.Minute { t.Errorf("MaxDuration = %s, want %s", got.MaxDuration, 10*time.Minute) } if got.Concurrency != 2 { t.Errorf("Concurrency = %d, want 2", got.Concurrency) } if got.Timeout != 10*time.Second { t.Errorf("Timeout = %s, want %s", got.Timeout, 10*time.Second) } } // TestLimitsWithDefaults 断言零值与负值都被补成默认(限额的零值若照字面生效 // 会变成「一字节都不许」,那不是任何调用方想要的行为)。 func TestLimitsWithDefaults(t *testing.T) { zero := Limits{}.withDefaults() if zero != DefaultLimits() { t.Fatalf("zero limits = %+v, want %+v", zero, DefaultLimits()) } negative := Limits{ MaxInputBytes: -1, MaxOutputBytes: -1, MaxDuration: -1, Concurrency: -1, Timeout: -1, }.withDefaults() if negative != DefaultLimits() { t.Fatalf("negative limits = %+v, want %+v", negative, DefaultLimits()) } } // TestWAVSizeLimitIsBelowOutputLimit 断言 64 MiB 的产物上限落在 44 字节头能如实 // 声明的范围内(否则会出现「闸放过了、头写不出」的死角)。 func TestWAVSizeLimitIsBelowOutputLimit(t *testing.T) { if uint64(DefaultMaxOutputBytes) > uint64(wavMaxDataBytes) { t.Fatalf("MaxOutputBytes %d exceeds the RIFF limit %d", DefaultMaxOutputBytes, wavMaxDataBytes) } }