Files
pve-confsync/internal/config/config_test.go
T

39 lines
1001 B
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)
}
}