54 lines
1.4 KiB
Go
54 lines
1.4 KiB
Go
package config
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"pve-confsync/internal/adapter"
|
|
"pve-confsync/internal/model"
|
|
)
|
|
|
|
func TestValidate(t *testing.T) {
|
|
c := &Config{
|
|
Reference: Cluster{Name: "ref"},
|
|
Clients: []Client{{Cluster: Cluster{Name: "ref"}}},
|
|
Kinds: []model.Kind{model.KindPassword},
|
|
Policies: map[model.Kind]map[string]adapter.Policy{model.KindDatacenter: {"u2f": adapter.Sync, "x": "bogus"}},
|
|
}
|
|
err := c.Validate()
|
|
if err == nil {
|
|
t.Fatal("expected errors")
|
|
}
|
|
for _, want := range []string{"duplicate name", "cannot be synchronized", "unknown policy", "pve-password needs pve-user"} {
|
|
if !strings.Contains(err.Error(), want) {
|
|
t.Errorf("missing %q in %v", want, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSSHOptions(t *testing.T) {
|
|
cl := Cluster{URL: "https://pve1.lab:8006", Password: "p"}
|
|
if o := cl.SSHOptions(); o.Host != "pve1.lab" || o.User != "root" {
|
|
t.Fatalf("%+v", o)
|
|
}
|
|
cl.SSHHost = "10.0.0.1"
|
|
if o := cl.SSHOptions(); o.Host != "10.0.0.1" {
|
|
t.Fatalf("%+v", o)
|
|
}
|
|
}
|
|
|
|
func TestNormalizeURL(t *testing.T) {
|
|
for in, want := range map[string]string{
|
|
"https://pve1": "https://pve1:8006",
|
|
" https://pve1/ ": "https://pve1:8006",
|
|
"https://pve1:443": "https://pve1:443",
|
|
"https://10.0.0.1": "https://10.0.0.1:8006",
|
|
"https://[fd00::1]": "https://[fd00::1]:8006",
|
|
"https://pve1:8006/": "https://pve1:8006",
|
|
} {
|
|
if got := NormalizeURL(in); got != want {
|
|
t.Errorf("NormalizeURL(%q) = %q, want %q", in, got, want)
|
|
}
|
|
}
|
|
}
|