- Add sanitizeTail() helper that validates tail is numeric and positive - Clamp values to max 500 - Default to 500 when empty, non-numeric, zero, or negative - Add comprehensive test cases
39 lines
904 B
Go
39 lines
904 B
Go
package handlers
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestSanitizeTail(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
expected string
|
|
}{
|
|
{"empty uses default", "", defaultLogTail},
|
|
{"valid small number", "50", "50"},
|
|
{"valid max boundary", "500", "500"},
|
|
{"exceeds max clamped", "501", "500"},
|
|
{"very large clamped", "999999", "500"},
|
|
{"non-numeric uses default", "abc", defaultLogTail},
|
|
{"all keyword uses default", "all", defaultLogTail},
|
|
{"negative uses default", "-1", defaultLogTail},
|
|
{"zero uses default", "0", defaultLogTail},
|
|
{"float uses default", "1.5", defaultLogTail},
|
|
{"one is valid", "1", "1"},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
got := sanitizeTail(tc.input)
|
|
if got != tc.expected {
|
|
t.Errorf("sanitizeTail(%q) = %q, want %q", tc.input, got, tc.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|