Skip to content

Commit

Permalink
Add area get support (#392)
Browse files Browse the repository at this point in the history
* add area get support and test (#381)

* style: fix whitespaces

* change return type to Area[] instead of Area

---------

Co-authored-by: octocat <[email protected]>
  • Loading branch information
larrytamnjong and octocat authored Nov 6, 2024
1 parent ee6228e commit cf87234
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Consul.Test/OperatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,21 @@ public async Task Operator_AreaUpdate()
Assert.Equal(area.RetryJoin, updatedArea.RetryJoin);
Assert.Equal(area.PeerDatacenter, updatedArea.PeerDatacenter);
}
[EnterpriseOnlyFact]
public async Task Operator_AreaGet()
{
var peerDataCenter = KVTest.GenerateTestKeyName();
var area = new AreaRequest { PeerDatacenter = peerDataCenter, UseTLS = true, RetryJoin = new string[] { "10.1.2.7", "10.1.2.0" } };
var createResult = await _client.Operator.AreaCreate(area);
var areaId = createResult.Response;

var req = await _client.Operator.AreaGet(areaId);
var result = req.Response.Single(x => x.ID == areaId);

Assert.Equal(areaId, result.ID);
Assert.Equal(area.UseTLS, result.UseTLS);
Assert.Equal(area.RetryJoin, result.RetryJoin);
Assert.Equal(area.PeerDatacenter, result.PeerDatacenter);
}
}
}
2 changes: 2 additions & 0 deletions Consul/Interfaces/IOperatorEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,7 @@ public interface IOperatorEndpoint
Task<QueryResult<List<Area>>> AreaList(QueryOptions q, CancellationToken cancellationToken = default);
Task<WriteResult<string>> AreaUpdate(AreaRequest area, string areaId, CancellationToken cancellationToken = default);
Task<WriteResult<string>> AreaUpdate(AreaRequest area, string areaId, WriteOptions q, CancellationToken cancellationToken = default);
Task<QueryResult<Area[]>> AreaGet(string areaId, CancellationToken cancellationToken = default);
Task<QueryResult<Area[]>> AreaGet(string areaId, QueryOptions q, CancellationToken cancellationToken = default);
}
}
14 changes: 14 additions & 0 deletions Consul/Operator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,20 @@ public async Task<WriteResult<string>> AreaUpdate(AreaRequest area, string areaI
var req = await _client.Put<AreaRequest, Area>($"/v1/operator/area/{areaId}", area, q).Execute(ct).ConfigureAwait(false);
return new WriteResult<string>(req, req.Response.ID);
}
/// <summary>
/// AreaGet returns a single network area
/// </summary>
public Task<QueryResult<Area[]>> AreaGet(string areaId, CancellationToken ct = default)
{
return AreaGet(areaId, QueryOptions.Default, ct);
}
/// <summary>
/// AreaGet returns a single network area
/// </summary>
public Task<QueryResult<Area[]>> AreaGet(string areaId, QueryOptions q, CancellationToken ct = default)
{
return _client.Get<Area[]>($"/v1/operator/area/{areaId}", q).Execute(ct);
}
}

public class ConsulLicense
Expand Down

0 comments on commit cf87234

Please sign in to comment.