mirror of https://github.com/status-im/consul.git
Adds a clone method to HealthCheck and uses that in local.go.
This commit is contained in:
parent
cfe0651208
commit
ed86e5cc72
|
@ -436,13 +436,11 @@ func (l *localState) setSyncState() error {
|
||||||
} else {
|
} else {
|
||||||
// Copy the existing check before potentially modifying
|
// Copy the existing check before potentially modifying
|
||||||
// it before the compare operation.
|
// it before the compare operation.
|
||||||
eCopy := new(structs.HealthCheck)
|
eCopy := existing.Clone()
|
||||||
*eCopy = *existing
|
|
||||||
|
|
||||||
// Copy the server's check before modifying, otherwise
|
// Copy the server's check before modifying, otherwise
|
||||||
// in-memory RPC-based unit tests will have side effects.
|
// in-memory RPC-based unit tests will have side effects.
|
||||||
cCopy := new(structs.HealthCheck)
|
cCopy := check.Clone()
|
||||||
*cCopy = *check
|
|
||||||
|
|
||||||
// If there's a defer timer active then we've got a
|
// If there's a defer timer active then we've got a
|
||||||
// potentially spammy check so we don't sync the output
|
// potentially spammy check so we don't sync the output
|
||||||
|
|
|
@ -396,6 +396,13 @@ func (c *HealthCheck) IsSame(other *HealthCheck) bool {
|
||||||
return true
|
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
|
type HealthChecks []*HealthCheck
|
||||||
|
|
||||||
// CheckServiceNode is used to provide the node, its service
|
// CheckServiceNode is used to provide the node, its service
|
||||||
|
|
|
@ -211,6 +211,28 @@ func TestStructs_HealthCheck_IsSame(t *testing.T) {
|
||||||
check(&other.ServiceName)
|
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) {
|
func TestStructs_CheckServiceNodes_Shuffle(t *testing.T) {
|
||||||
// Make a huge list of nodes.
|
// Make a huge list of nodes.
|
||||||
var nodes CheckServiceNodes
|
var nodes CheckServiceNodes
|
||||||
|
|
Loading…
Reference in New Issue