fix: validate and clamp container log tail parameter (closes #24)
- 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
This commit is contained in:
38
internal/handlers/tail_validation_test.go
Normal file
38
internal/handlers/tail_validation_test.go
Normal file
@@ -0,0 +1,38 @@
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user