mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-10-24 04:33:17 +00:00
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:
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user