Tests : faux serveur PVE 9.x, tests config et CLI
This commit is contained in:
1 parent
5a5422ca78
commit
30f770ed8f
3 files changed
+440
No files matched your search
@@ -0,0 +1,53 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"pve-confsync/internal/pve/pvetest"
|
||||
)
|
||||
|
||||
func TestCLIDiffExportApply(t *testing.T) {
|
||||
ref := pvetest.New("9.1.4")
|
||||
defer ref.Close()
|
||||
cli := pvetest.New("9.1.4")
|
||||
defer cli.Close()
|
||||
ref.Options["registered-tags"] = "prod"
|
||||
ref.Pending.Zones["vlanz"] = map[string]any{"type": "vlan", "bridge": "vmbr0"}
|
||||
ref.Pending.VNets["v10"] = map[string]any{"zone": "vlanz", "tag": 10}
|
||||
ref.Commit()
|
||||
|
||||
dir := t.TempDir()
|
||||
t.Setenv("SECRET", "s3cr3t")
|
||||
cfg := filepath.Join(dir, "c.yaml")
|
||||
_ = os.WriteFile(cfg, []byte(fmt.Sprintf(`reference: {name: ref, url: %s, token_id: a@pve!ro, token_secret_env: SECRET, insecure: true}
|
||||
clients:
|
||||
- {name: c1, url: %s, token_id: a@pve!rw, token_secret_env: SECRET, insecure: true,
|
||||
mapping: {sdn-zone: {vlanz: {bridge: vmbr1}}}}
|
||||
`, ref.URL, cli.URL)), 0o600)
|
||||
ctx := context.Background()
|
||||
|
||||
if code, err := cmdDiff(ctx, cfg, nil); err != nil || code != 2 {
|
||||
t.Fatalf("diff: code=%d err=%v", code, err)
|
||||
}
|
||||
snap := filepath.Join(dir, "ref.yaml")
|
||||
if err := cmdExport(ctx, cfg, []string{"-o", snap}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// dry-run by default: nothing written
|
||||
if err := cmdApply(ctx, cfg, []string{"-source", snap}); err != nil || len(cli.Calls) != 0 {
|
||||
t.Fatalf("dry-run wrote: %v %v", err, cli.Calls)
|
||||
}
|
||||
if err := cmdApply(ctx, cfg, []string{"-source", snap, "-confirm", "-yes"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if cli.Running.VNets["v10"] == nil || cli.Options["registered-tags"] != "prod" {
|
||||
t.Fatalf("not applied: %v %v", cli.Running.VNets, cli.Options)
|
||||
}
|
||||
if code, err := cmdDiff(ctx, cfg, nil); err != nil || code != 0 {
|
||||
t.Fatalf("diff after apply: code=%d err=%v", code, err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user