Full web : clusters gérés dans l'UI, primaire et cibles, comptes pve

This commit is contained in:
claude Bot committed 2026-10-23 17:20:16 +02:00
1 parent 0fb88cb4b0
commit 3e9cb563be
11 files changed
+93 -414

No files matched your search

+24 -30
View File
@@ -1,44 +1,38 @@
package config
import (
"os"
"path/filepath"
"strings"
"testing"
"pve-confsync/internal/adapter"
"pve-confsync/internal/model"
)
func TestLoadExample(t *testing.T) {
c, err := Load(filepath.Join("..", "..", "examples", "confsync.example.yaml"))
if err != nil {
t.Fatal(err)
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"}},
}
a, _ := adapter.ByKind(model.KindZone)
cl, _ := c.Client("site-a")
if p := c.Policy(cl, a, "mtu"); p != adapter.Ignore {
t.Fatalf("site-a mtu policy = %s", p)
err := c.Validate()
if err == nil {
t.Fatal("expected errors")
}
if p := c.Policy(nil, a, "bridge"); p != adapter.Override {
t.Fatalf("bridge policy = %s", p)
}
if c.Selected(model.KindZone, "lab1") || !c.Selected(model.KindZone, "vlanz") {
t.Fatal("selection")
}
}
func TestRejects(t *testing.T) {
for name, body := range map[string]string{
"clear secret": "reference: {name: r, url: https://x, token_id: a@pve!b, token_secret: s}\n",
"no secret": "reference: {name: r, url: https://x, token_id: a@pve!b}\n",
"forbidden": "reference: {name: r, url: https://x, token_id: a@pve!b, token_secret_env: X}\npolicies: {datacenter-options: {webauthn: sync}}\n",
"bad policy": "reference: {name: r, url: https://x, token_id: a@pve!b, token_secret_env: X}\npolicies: {sdn-zone: {mtu: copy}}\n",
"unknown kind": "reference: {name: r, url: https://x, token_id: a@pve!b, token_secret_env: X}\nkinds: [firewall]\n",
} {
f := filepath.Join(t.TempDir(), "c.yaml")
_ = os.WriteFile(f, []byte(body), 0o600)
if _, err := Load(f); err == nil {
t.Errorf("%s: expected an error", name)
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)
}
}