agent/structs: tests for PartialClone and IsSame for proxy fields

This commit is contained in:
Mitchell Hashimoto 2018-03-09 17:21:26 -08:00
parent 9781cb1ace
commit 125fb96ff1
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 9 additions and 1 deletions

View File

@ -529,7 +529,9 @@ func (s *NodeService) IsSame(other *NodeService) bool {
s.Address != other.Address ||
s.Port != other.Port ||
!reflect.DeepEqual(s.Meta, other.Meta) ||
s.EnableTagOverride != other.EnableTagOverride {
s.EnableTagOverride != other.EnableTagOverride ||
s.Kind != other.Kind ||
s.ProxyDestination != other.ProxyDestination {
return false
}

View File

@ -134,6 +134,7 @@ func testServiceNode() *ServiceNode {
NodeMeta: map[string]string{
"tag": "value",
},
ServiceKind: ServiceKindTypical,
ServiceID: "service1",
ServiceName: "dogs",
ServiceTags: []string{"prod", "v1"},
@ -143,6 +144,7 @@ func testServiceNode() *ServiceNode {
"service": "metadata",
},
ServiceEnableTagOverride: true,
ServiceProxyDestination: "cats",
RaftIndex: RaftIndex{
CreateIndex: 1,
ModifyIndex: 2,
@ -275,6 +277,7 @@ func TestStructs_NodeService_IsSame(t *testing.T) {
},
Port: 1234,
EnableTagOverride: true,
ProxyDestination: "db",
}
if !ns.IsSame(ns) {
t.Fatalf("should be equal to itself")
@ -292,6 +295,7 @@ func TestStructs_NodeService_IsSame(t *testing.T) {
"meta2": "value2",
"meta1": "value1",
},
ProxyDestination: "db",
RaftIndex: RaftIndex{
CreateIndex: 1,
ModifyIndex: 2,
@ -325,6 +329,8 @@ func TestStructs_NodeService_IsSame(t *testing.T) {
check(func() { other.Port = 9999 }, func() { other.Port = 1234 })
check(func() { other.Meta["meta2"] = "wrongValue" }, func() { other.Meta["meta2"] = "value2" })
check(func() { other.EnableTagOverride = false }, func() { other.EnableTagOverride = true })
check(func() { other.Kind = ServiceKindConnectProxy }, func() { other.Kind = "" })
check(func() { other.ProxyDestination = "" }, func() { other.ProxyDestination = "db" })
}
func TestStructs_HealthCheck_IsSame(t *testing.T) {