From e70b3cb0f3f66325f2829fa2425c3aec35e606ec Mon Sep 17 00:00:00 2001 From: rcourtman Date: Mon, 1 Dec 2025 14:46:00 +0000 Subject: [PATCH] test: Improve coverage for cluster config handler functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - deriveSchemeAndPort: 87.5% → 100% - Empty/whitespace string handling - Invalid URL parsing fallback - Host without port - ensureHostHasPort: 91.7% → 100% - Empty port returns host unchanged - Protocol-relative URL handling (//host) --- internal/api/config_handlers_cluster_test.go | 49 ++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/internal/api/config_handlers_cluster_test.go b/internal/api/config_handlers_cluster_test.go index e6857180c..61a2b1fab 100644 --- a/internal/api/config_handlers_cluster_test.go +++ b/internal/api/config_handlers_cluster_test.go @@ -35,6 +35,31 @@ func TestDeriveSchemeAndPort(t *testing.T) { wantScheme: "https", wantPort: "9000", }, + // Edge cases for full coverage + { + name: "empty string returns defaults", + host: "", + wantScheme: "https", + wantPort: "8006", + }, + { + name: "whitespace only returns defaults", + host: " ", + wantScheme: "https", + wantPort: "8006", + }, + { + name: "invalid URL returns defaults", + host: "://invalid", + wantScheme: "https", + wantPort: "8006", + }, + { + name: "host only without port", + host: "pve1.local", + wantScheme: "https", + wantPort: "8006", + }, } for _, tt := range tests { @@ -94,6 +119,30 @@ func TestEnsureHostHasPort(t *testing.T) { port: "8006", expected: "", }, + { + name: "empty port returns host unchanged", + host: "pve1.local", + port: "", + expected: "pve1.local", + }, + { + name: "both empty returns empty", + host: "", + port: "", + expected: "", + }, + { + name: "host with scheme but no port strips scheme and adds port", + host: "https://pve1.local", + port: "8006", + expected: "https://pve1.local", + }, + { + name: "protocol-relative URL extracts host and adds port", + host: "//pve1.local", + port: "8006", + expected: "pve1.local:8006", + }, } for _, tt := range tests {