Make agent copy-ownership expectations independent

Freeze the source expectation as serialized bytes before mutating returned records. A broken clone cannot change both the tested state and its reference, so module, update and applied-config alias regressions must be detected.

Change-source: pulse-maintainer
This commit is contained in:
pulse-triage[bot]
2026-10-05 01:45:52 +01:00
parent 39906a220a
commit 36fc9fbf89
+10 -2
View File
@@ -1,6 +1,8 @@
package models
import (
"bytes"
"encoding/json"
"fmt"
"reflect"
"sync"
@@ -92,7 +94,12 @@ func TestStatePointLookupsMatchWholeLists(t *testing.T) {
t.Fatalf("exact source lookup %q differs from the existing whole-list lookup", id)
}
}
before := s.GetSnapshot()
// Freeze the expectation independently of the clone under test. A
// defective clone must not mutate both the source and its reference.
before, err := json.Marshal(s.GetSnapshot())
if err != nil {
t.Fatal(err)
}
for _, fromList := range []bool{false, true} {
host, _ := s.GetHost("host")
docker, _ := s.GetDockerHost("docker")
@@ -111,7 +118,8 @@ func TestStatePointLookupsMatchWholeLists(t *testing.T) {
docker.Containers[0].Labels["app"] = "changed"
docker.NetworkInterfaces[0].Addresses[0] = "changed"
docker.AgentModules[0].State = "changed"
if !reflect.DeepEqual(before, s.GetSnapshot()) {
after, err := json.Marshal(s.GetSnapshot())
if err != nil || !bytes.Equal(before, after) {
t.Fatal("point or list result aliases mutable source fields")
}
}