mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-12-03 02:24:21 +01:00
Keep selection on the registry ID through context, sessions and command routing so same-name resources cannot cross provider boundaries. Retain native executor coordinates, legacy inputs that resolve uniquely, policy redaction and paid execution modes. Refs #2681
30 lines
1.3 KiB
Go
30 lines
1.3 KiB
Go
package tools
|
|
|
|
import (
|
|
"github.com/rcourtman/pulse-go-rewrite/internal/models"
|
|
"github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources"
|
|
"testing"
|
|
)
|
|
|
|
func TestCurrentResourceAddressingKeepsTheSelectedCanonicalOwner(t *testing.T) {
|
|
rr := unifiedresources.NewRegistry(nil)
|
|
rr.IngestSnapshot(models.StateSnapshot{VMs: []models.VM{
|
|
{ID: "a:node1:101", Instance: "a", Node: "node1", VMID: 101, Name: "first", Type: "qemu"},
|
|
{ID: "b:node1:101", Instance: "b", Node: "node1", VMID: 101, Name: "second", Type: "qemu"},
|
|
}})
|
|
selected := unifiedresources.ProxmoxGuestCanonicalID(unifiedresources.ResourceTypeVM, "b", 101)
|
|
resource := &mockResource{resourceID: selected, providerUID: "101", kind: "vm", aliases: []string{"first"}, targetHost: "node1"}
|
|
executor := NewPulseToolExecutor(ExecutorConfig{ReadState: rr})
|
|
target, err := executor.commandTargetForResolvedResource(resource)
|
|
if err != nil || target != selected {
|
|
t.Fatalf("selected owner rebound through provider UID or alias: %q %v", target, err)
|
|
}
|
|
if got := canonicalQueryIDForResolvedResource(resource); got != selected {
|
|
t.Fatalf("selected read uses unscoped ID %s", got)
|
|
}
|
|
resource.resourceID = "vm-unknown"
|
|
if target, err := executor.commandTargetForResolvedResource(resource); err == nil {
|
|
t.Fatalf("missing owner rebound to %s", target)
|
|
}
|
|
}
|