Adds a clone method to HealthCheck and uses that in local.go.
This commit is contained in:
parent
f6fe6a2197
commit
3f340716fd
|
@ -436,13 +436,11 @@ func (l *localState) setSyncState() error {
|
|||
} else {
|
||||
// Copy the existing check before potentially modifying
|
||||
// it before the compare operation.
|
||||
eCopy := new(structs.HealthCheck)
|
||||
*eCopy = *existing
|
||||
eCopy := existing.Clone()
|
||||
|
||||
// Copy the server's check before modifying, otherwise
|
||||
// in-memory RPC-based unit tests will have side effects.
|
||||
cCopy := new(structs.HealthCheck)
|
||||
*cCopy = *check
|
||||
cCopy := check.Clone()
|
||||
|
||||
// If there's a defer timer active then we've got a
|
||||
// potentially spammy check so we don't sync the output
|
||||
|
|
|
@ -396,6 +396,13 @@ func (c *HealthCheck) IsSame(other *HealthCheck) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
// Clone returns a distinct clone of the HealthCheck.
|
||||
func (c *HealthCheck) Clone() *HealthCheck {
|
||||
clone := new(HealthCheck)
|
||||
*clone = *c
|
||||
return clone
|
||||
}
|
||||
|
||||
type HealthChecks []*HealthCheck
|
||||
|
||||
// CheckServiceNode is used to provide the node, its service
|
||||
|
|
|
@ -211,6 +211,28 @@ func TestStructs_HealthCheck_IsSame(t *testing.T) {
|
|||
check(&other.ServiceName)
|
||||
}
|
||||
|
||||
func TestStructs_HealthCheck_Clone(t *testing.T) {
|
||||
hc := &HealthCheck{
|
||||
Node: "node1",
|
||||
CheckID: "check1",
|
||||
Name: "thecheck",
|
||||
Status: HealthPassing,
|
||||
Notes: "it's all good",
|
||||
Output: "lgtm",
|
||||
ServiceID: "service1",
|
||||
ServiceName: "theservice",
|
||||
}
|
||||
clone := hc.Clone()
|
||||
if !hc.IsSame(clone) {
|
||||
t.Fatalf("should be equal to its clone")
|
||||
}
|
||||
|
||||
clone.Output = "different"
|
||||
if hc.IsSame(clone) {
|
||||
t.Fatalf("should not longer be equal to its clone")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStructs_CheckServiceNodes_Shuffle(t *testing.T) {
|
||||
// Make a huge list of nodes.
|
||||
var nodes CheckServiceNodes
|
||||
|
|
Loading…
Reference in New Issue