mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-12-02 18:19:07 +01:00
Assert refreshed status and CPU on the same canonical VM instead of requiring a Proxmox rename that the existing source-priority merge intentionally rejects. Use the mock runtime's supported maximum cadence. The initial fixture and assertion failures remain retained; no production behaviour is changed. Refs: #2199 Contract-Neutral: Correct independent test assumptions only; no runtime or resource contract delta. Change-source: pulse-maintainer
92 lines
3.1 KiB
Go
92 lines
3.1 KiB
Go
package unifiedresources_test
|
|
|
|
import (
|
|
"encoding/json"
|
|
"reflect"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/rcourtman/pulse-go-rewrite/internal/mock"
|
|
"github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources"
|
|
)
|
|
|
|
// Use the real multi-provider demo graph, including its metadata-heavy
|
|
// Kubernetes estate, rather than accepting a VM-only copying oracle.
|
|
func TestRegistryMaterializedMetadataConnectedDemo(t *testing.T) {
|
|
previousEnabled := mock.IsMockEnabled()
|
|
previousConfig := mock.GetConfig()
|
|
t.Cleanup(func() {
|
|
_ = mock.SetEnabled(false)
|
|
mock.SetMockConfig(previousConfig)
|
|
if previousEnabled {
|
|
if err := mock.SetEnabled(true); err != nil {
|
|
t.Error(err)
|
|
}
|
|
}
|
|
})
|
|
if err := mock.SetEnabled(false); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
cfg := mock.DefaultConfig
|
|
cfg.UpdateInterval = 5 * time.Minute
|
|
mock.SetMockConfig(cfg)
|
|
if err := mock.SetEnabled(true); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
graph := mock.CurrentFixtureGraph()
|
|
registry := unifiedresources.NewRegistry(nil)
|
|
registry.IngestSnapshot(graph.State)
|
|
for _, source := range []unifiedresources.DataSource{unifiedresources.SourceTrueNAS, unifiedresources.SourceVMware, unifiedresources.SourceAvailability} {
|
|
registry.IngestRecords(source, graph.SupplementalRecords(source))
|
|
}
|
|
assertEqual := func(stage string) {
|
|
t.Helper()
|
|
actual := registry.List()
|
|
expected := unifiedresources.FreshRegistryMetadataListForTest(registry)
|
|
if len(actual) < 1000 {
|
|
t.Fatalf("%s: fixture is not a large estate (%d resources)", stage, len(actual))
|
|
}
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
t.Fatalf("%s: complete demo resources differ from fresh clone", stage)
|
|
}
|
|
a, err := json.Marshal(actual)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
e, err := json.Marshal(expected)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if string(a) != string(e) {
|
|
t.Fatalf("%s: demo wire content differs", stage)
|
|
}
|
|
sources := map[unifiedresources.DataSource]bool{}
|
|
for _, r := range actual {
|
|
for _, source := range r.Sources {
|
|
sources[source] = true
|
|
}
|
|
}
|
|
for _, source := range []unifiedresources.DataSource{unifiedresources.SourceProxmox, unifiedresources.SourceAgent, unifiedresources.SourceDocker, unifiedresources.SourcePBS, unifiedresources.SourcePMG, unifiedresources.SourceK8s, unifiedresources.SourceTrueNAS, unifiedresources.SourceVMware, unifiedresources.SourceAvailability} {
|
|
if !sources[source] {
|
|
t.Fatalf("%s: fixture omits provider %s", stage, source)
|
|
}
|
|
}
|
|
t.Logf("%s: %d complete resources equal the independent fresh-clone oracle", stage, len(actual))
|
|
}
|
|
assertEqual("initial")
|
|
registry.Workloads()
|
|
registry.IngestSnapshot(graph.State)
|
|
assertEqual("snapshot-refresh")
|
|
registry.MarkStale(time.Now().UTC().Add(7*24*time.Hour), nil)
|
|
assertEqual("stale-transition")
|
|
// A normalized re-seed must keep identity, supersession, policy and every
|
|
// native facet, rather than assuming old derived fields are trustworthy.
|
|
resources := registry.List()
|
|
resources[0].Name = "changed-name"
|
|
resources[0].Tags = []string{"customer-data"}
|
|
resources[0].PlatformScopes = []string{"old"}
|
|
resources[0].AISafeSummary = "old"
|
|
registry.IngestResources(resources)
|
|
assertEqual("resource-reseed")
|
|
}
|