From b2db3d5eb441671037266c58c3e16629c8dd63fb Mon Sep 17 00:00:00 2001 From: Dhia Ayachi Date: Thu, 11 Jan 2024 11:45:48 -0500 Subject: [PATCH] add endpoint test for NodesOnly flag --- agent/consul/internal_endpoint_test.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/agent/consul/internal_endpoint_test.go b/agent/consul/internal_endpoint_test.go index 3f853df7ce..c11f43494c 100644 --- a/agent/consul/internal_endpoint_test.go +++ b/agent/consul/internal_endpoint_test.go @@ -1779,10 +1779,11 @@ func TestInternal_ServiceDump_Peering(t *testing.T) { // prep the cluster with some data we can use in our filters registerTestCatalogEntries(t, codec) - doRequest := func(t *testing.T, filter string) structs.IndexedNodesWithGateways { + doRequest := func(t *testing.T, filter string, onlyNodes bool) structs.IndexedNodesWithGateways { t.Helper() - args := structs.DCSpecificRequest{ + args := structs.ServiceDumpRequest{ QueryOptions: structs.QueryOptions{Filter: filter}, + NodesOnly: onlyNodes, } var out structs.IndexedNodesWithGateways @@ -1792,7 +1793,7 @@ func TestInternal_ServiceDump_Peering(t *testing.T) { } t.Run("No peerings", func(t *testing.T) { - nodes := doRequest(t, "") + nodes := doRequest(t, "", false) // redis (3), web (3), critical (1), warning (1) and consul (1) require.Len(t, nodes.Nodes, 9) require.Len(t, nodes.ImportedNodes, 0) @@ -1809,19 +1810,27 @@ func TestInternal_ServiceDump_Peering(t *testing.T) { require.NoError(t, err) t.Run("peerings", func(t *testing.T) { - nodes := doRequest(t, "") + nodes := doRequest(t, "", false) // redis (3), web (3), critical (1), warning (1) and consul (1) require.Len(t, nodes.Nodes, 9) // service (1) require.Len(t, nodes.ImportedNodes, 1) }) + t.Run("peerings onlynodes", func(t *testing.T) { + nodes := doRequest(t, "", true) + // redis (3), web (3), critical (1), warning (1) and consul (1) + require.Len(t, nodes.Nodes, 9) + // service (1) + require.Len(t, nodes.ImportedNodes, 0) + }) + t.Run("peerings w filter", func(t *testing.T) { - nodes := doRequest(t, "Node.PeerName == foo") + nodes := doRequest(t, "Node.PeerName == foo", false) require.Len(t, nodes.Nodes, 0) require.Len(t, nodes.ImportedNodes, 0) - nodes2 := doRequest(t, "Node.PeerName == peer1") + nodes2 := doRequest(t, "Node.PeerName == peer1", false) require.Len(t, nodes2.Nodes, 0) require.Len(t, nodes2.ImportedNodes, 1) })