Added host URL normalization
Build Docker image on push / docker (push) Successful in 22s
Build and push Docker image on tag / docker (push) Successful in 23s

This commit is contained in:
2026-08-17 23:04:28 +02:00
parent 462eb4f80c
commit 6e3bb0ff7b
4 changed files with 92 additions and 1 deletions
+49
View File
@@ -0,0 +1,49 @@
package proxmox
import (
"testing"
"time"
)
func TestNewApiClientNormalizesEndpointHosts(t *testing.T) {
tests := []struct {
name string
host string
want string
}{
{
name: "IP without trailing slash",
host: "https://192.168.0.10:8006",
want: "https://192.168.0.10:8006/",
},
{
name: "IP with trailing slash",
host: "https://192.168.0.10:8006/",
want: "https://192.168.0.10:8006/",
},
{
name: "DNS without trailing slash",
host: "https://pve.example.com:8006",
want: "https://pve.example.com:8006/",
},
{
name: "DNS with trailing slash",
host: "https://pve.example.com:8006/",
want: "https://pve.example.com:8006/",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
client := NewApiClient([]string{tt.host}, "token", "secret", time.Second)
defer client.httpClient.CloseIdleConnections()
if got := client.endpoints[0].host; got != tt.want {
t.Fatalf("normalized endpoint host = %q, want %q", got, tt.want)
}
if got := client.endpoints[0].host + "api2/json/"; got != tt.want+"api2/json/" {
t.Fatalf("liveness URL = %q, want %q", got, tt.want+"api2/json/")
}
})
}
}