mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-28 02:40:53 +08:00
A model-supplied limit on list_worker_traces, list_assets, and list_untested_assets was only defaulted. A huge value became a slice capacity or a SQL page size. Clamp the limit and page size to 100, and bound the page number and offset.
31 lines
848 B
Go
31 lines
848 B
Go
package agent
|
|
|
|
import "testing"
|
|
|
|
func TestClampToolLimit(t *testing.T) {
|
|
if got := clampToolLimit(0, 10); got != 10 {
|
|
t.Fatalf("default = %d, want 10", got)
|
|
}
|
|
if got := clampToolLimit(-4, 50); got != 50 {
|
|
t.Fatalf("negative = %d, want 50", got)
|
|
}
|
|
if got := clampToolLimit(20, 10); got != 20 {
|
|
t.Fatalf("in range = %d, want 20", got)
|
|
}
|
|
if got := clampToolLimit(1<<30, 10); got != toolPageMax {
|
|
t.Fatalf("huge = %d, want %d", got, toolPageMax)
|
|
}
|
|
if got := clampToolOffset(-1); got != 0 {
|
|
t.Fatalf("negative offset = %d", got)
|
|
}
|
|
if got := clampToolOffset(toolOffsetMax + 1); got != toolOffsetMax {
|
|
t.Fatalf("huge offset = %d", got)
|
|
}
|
|
if got := clampToolPage(0); got != 1 {
|
|
t.Fatalf("page = %d, want 1", got)
|
|
}
|
|
if got := clampToolPage(toolPageIndexMax + 5); got != toolPageIndexMax {
|
|
t.Fatalf("huge page = %d", got)
|
|
}
|
|
}
|