Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Consul.Test/CoordinateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,20 @@ public async Task Coordinate_GetNodes()
// get an error. - from offical API.
Assert.NotNull(nodes);
}

[Fact]
public async Task Coordinate_GetNode()
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous version of the test was better, we did actually use a real node name in the query before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is that with the node name I was receiving errors in the base fixture class

var info = await _client.Agent.Self();
var nodes = await _client.Coordinate.Nodes();

Assert.NotNull(nodes.Response);
Assert.True(nodes.Response.Length > 0);

var node = await _client.Coordinate.Node(nodes.Response[0].Node);

Assert.NotNull(node.Response);
Assert.Equal(nodes.Response[0].Node, node.Response.Node);
}
}
}
12 changes: 12 additions & 0 deletions Consul/Coordinate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ public Task<QueryResult<CoordinateEntry[]>> Nodes(QueryOptions q, CancellationTo
{
return _client.Get<CoordinateEntry[]>(string.Format("/v1/coordinate/nodes"), q).Execute(ct);
}

/// <summary>
/// Node returns the coordinates of a given node in the LAN pool.
/// </summary>
/// <param name="node">The node to query</param>"
/// <param name="ct">The cancellation token</param>"
/// <param name="q">Customized query options</param>"
/// <remarks>Node is used to return the coordinates of a given node in the LAN pool.</returns>
public Task<QueryResult<CoordinateEntry>> Node(string node, QueryOptions q, CancellationToken ct = default)
{
return _client.Get<CoordinateEntry>(string.Format("/v1/coordinate/node/{0}", node), q).Execute(ct);
}
}

public partial class ConsulClient : IConsulClient
Expand Down
1 change: 1 addition & 0 deletions Consul/Interfaces/ICoordinateEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public interface ICoordinateEndpoint
{
Task<QueryResult<CoordinateDatacenterMap[]>> Datacenters(CancellationToken ct = default);
Task<QueryResult<CoordinateEntry[]>> Nodes(CancellationToken ct = default);
Task<QueryResult<CoordinateEntry>> Node(string node, QueryOptions q, CancellationToken ct = default);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two overloads of Nodes endpoint (with and without QueryOptions q parameter).
We can Apply the same pattern for the new Node endpoint`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure noted! Already fixed 🚀

Task<QueryResult<CoordinateEntry[]>> Nodes(QueryOptions q, CancellationToken ct = default);
}
}