50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
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/")
|
|
}
|
|
})
|
|
}
|
|
}
|