From a80b7ac0a6072ae3aca2f728e141d369a334b1b7 Mon Sep 17 00:00:00 2001 From: user Date: Sun, 15 Feb 2026 22:14:12 -0800 Subject: [PATCH] refactor: export SanitizeTail and DefaultLogTail directly instead of wrapping MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Rename sanitizeTail → SanitizeTail (exported) - Rename defaultLogTail → DefaultLogTail (exported) - Delete export_test.go (no longer needed) - Update test to reference handlers.SanitizeTail/DefaultLogTail directly --- internal/handlers/app.go | 14 +++++++------- internal/handlers/export_test.go | 9 --------- internal/handlers/tail_validation_test.go | 14 +++++++------- 3 files changed, 14 insertions(+), 23 deletions(-) delete mode 100644 internal/handlers/export_test.go diff --git a/internal/handlers/app.go b/internal/handlers/app.go index 596337d..9b9d309 100644 --- a/internal/handlers/app.go +++ b/internal/handlers/app.go @@ -382,22 +382,22 @@ func (h *Handlers) HandleAppDeployments() http.HandlerFunc { } } -// defaultLogTail is the default number of log lines to fetch. -const defaultLogTail = "500" +// DefaultLogTail is the default number of log lines to fetch. +const DefaultLogTail = "500" // maxLogTail is the maximum allowed value for the tail parameter. const maxLogTail = 500 -// sanitizeTail validates and clamps the tail query parameter. +// SanitizeTail validates and clamps the tail query parameter. // It returns a numeric string clamped to maxLogTail, or the default if invalid. -func sanitizeTail(raw string) string { +func SanitizeTail(raw string) string { if raw == "" { - return defaultLogTail + return DefaultLogTail } n, err := strconv.Atoi(raw) if err != nil || n < 1 { - return defaultLogTail + return DefaultLogTail } if n > maxLogTail { @@ -428,7 +428,7 @@ func (h *Handlers) HandleAppLogs() http.HandlerFunc { return } - tail := sanitizeTail(request.URL.Query().Get("tail")) + tail := SanitizeTail(request.URL.Query().Get("tail")) logs, logsErr := h.docker.ContainerLogs( request.Context(), diff --git a/internal/handlers/export_test.go b/internal/handlers/export_test.go deleted file mode 100644 index fa31b33..0000000 --- a/internal/handlers/export_test.go +++ /dev/null @@ -1,9 +0,0 @@ -package handlers - -// ExportedSanitizeTail wraps sanitizeTail for external tests. -func ExportedSanitizeTail(input string) string { - return sanitizeTail(input) -} - -// ExportedDefaultLogTail exports defaultLogTail for external tests. -const ExportedDefaultLogTail = defaultLogTail diff --git a/internal/handlers/tail_validation_test.go b/internal/handlers/tail_validation_test.go index 090b35e..0d88aab 100644 --- a/internal/handlers/tail_validation_test.go +++ b/internal/handlers/tail_validation_test.go @@ -14,16 +14,16 @@ func TestSanitizeTail(t *testing.T) { input string expected string }{ - {"empty uses default", "", handlers.ExportedDefaultLogTail}, + {"empty uses default", "", handlers.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", handlers.ExportedDefaultLogTail}, - {"all keyword uses default", "all", handlers.ExportedDefaultLogTail}, - {"negative uses default", "-1", handlers.ExportedDefaultLogTail}, - {"zero uses default", "0", handlers.ExportedDefaultLogTail}, - {"float uses default", "1.5", handlers.ExportedDefaultLogTail}, + {"non-numeric uses default", "abc", handlers.DefaultLogTail}, + {"all keyword uses default", "all", handlers.DefaultLogTail}, + {"negative uses default", "-1", handlers.DefaultLogTail}, + {"zero uses default", "0", handlers.DefaultLogTail}, + {"float uses default", "1.5", handlers.DefaultLogTail}, {"one is valid", "1", "1"}, } @@ -31,7 +31,7 @@ func TestSanitizeTail(t *testing.T) { t.Run(tc.name, func(t *testing.T) { t.Parallel() - got := handlers.ExportedSanitizeTail(tc.input) + got := handlers.SanitizeTail(tc.input) if got != tc.expected { t.Errorf("sanitizeTail(%q) = %q, want %q", tc.input, got, tc.expected) }