test: Improve coverage for cluster config handler functions
- 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)
This commit is contained in:
parent
c6030d1b13
commit
4973eb4c8a
1 changed files with 49 additions and 0 deletions
|
|
@ -35,6 +35,31 @@ func TestDeriveSchemeAndPort(t *testing.T) {
|
||||||
wantScheme: "https",
|
wantScheme: "https",
|
||||||
wantPort: "9000",
|
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 {
|
for _, tt := range tests {
|
||||||
|
|
@ -94,6 +119,30 @@ func TestEnsureHostHasPort(t *testing.T) {
|
||||||
port: "8006",
|
port: "8006",
|
||||||
expected: "",
|
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 {
|
for _, tt := range tests {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue