Skip to content

Commit

Permalink
add support for list network area and test (#381) (#387)
Browse files Browse the repository at this point in the history
  • Loading branch information
larrytamnjong authored Oct 31, 2024
1 parent c4c0fab commit 18ba35f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
25 changes: 22 additions & 3 deletions Consul.Test/OperatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
// </copyright>
// -----------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

Expand Down Expand Up @@ -98,11 +101,27 @@ public async Task Segment_List()
}

[EnterpriseOnlyFact]
public async Task Operator_CreateArea()
public async Task Operator_AreaCreate()
{
var check = new AreaRequest { PeerDatacenter = "dc2", UseTLS = false, RetryJoin = null };
var response = await _client.Operator.CreateArea(check);
var peerDataCenter = KVTest.GenerateTestKeyName();
var check = new AreaRequest { PeerDatacenter = peerDataCenter, UseTLS = false, RetryJoin = null };

var response = await _client.Operator.AreaCreate(check);
Assert.NotNull(response.Response);
}
[EnterpriseOnlyFact]
public async Task Operator_AreaList()
{
var peerDataCenter = KVTest.GenerateTestKeyName();
var area = new AreaRequest { PeerDatacenter = peerDataCenter, UseTLS = false, RetryJoin = new string[] { "10.1.2.3", "10.1.2.4" } };

await _client.Operator.AreaCreate(area);

var req = await _client.Operator.AreaList();
var result = req.Response.Single(x => x.PeerDatacenter == area.PeerDatacenter);

Assert.Equal(area.UseTLS, result.UseTLS);
Assert.Equal(area.RetryJoin, result.RetryJoin);
}
}
}
7 changes: 4 additions & 3 deletions Consul/Interfaces/IOperatorEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ public interface IOperatorEndpoint
Task<QueryResult<ConsulLicense>> GetConsulLicense(string datacenter = "", CancellationToken ct = default);
Task<QueryResult<string[]>> SegmentList(QueryOptions q, CancellationToken cancellationToken = default);
Task<QueryResult<string[]>> SegmentList(CancellationToken cancellationToken = default);
Task<WriteResult<string>> CreateArea(AreaRequest area, WriteOptions q, CancellationToken ct = default);
Task<WriteResult<string>> CreateArea(AreaRequest area, CancellationToken ct = default);

Task<WriteResult<string>> AreaCreate(AreaRequest area, WriteOptions q, CancellationToken ct = default);
Task<WriteResult<string>> AreaCreate(AreaRequest area, CancellationToken ct = default);
Task<QueryResult<List<Area>>> AreaList(CancellationToken cancellationToken = default);
Task<QueryResult<List<Area>>> AreaList(QueryOptions q, CancellationToken cancellationToken = default);
}
}
22 changes: 19 additions & 3 deletions Consul/Operator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,19 +283,35 @@ public Task<QueryResult<string[]>> SegmentList(CancellationToken ct = default)
/// <summary>
/// CreateArea will create a new network area, a generated ID will be returned on success.
/// </summary>
public Task<WriteResult<string>> CreateArea(AreaRequest area, CancellationToken ct = default)
public Task<WriteResult<string>> AreaCreate(AreaRequest area, CancellationToken ct = default)
{
return CreateArea(area, WriteOptions.Default, ct);
return AreaCreate(area, WriteOptions.Default, ct);
}

/// <summary>
/// CreateArea will create a new network area, a generated ID will be returned on success.
/// </summary>
public async Task<WriteResult<string>> CreateArea(AreaRequest area, WriteOptions q, CancellationToken ct = default)
public async Task<WriteResult<string>> AreaCreate(AreaRequest area, WriteOptions q, CancellationToken ct = default)
{
var req = await _client.Post<AreaRequest, Area>("/v1/operator/area", area, q).Execute(ct).ConfigureAwait(false);
return new WriteResult<string>(req, req.Response.ID);
}

/// <summary>
/// AreaList returns all the available network areas
/// </summary>
public Task<QueryResult<List<Area>>> AreaList(CancellationToken ct = default)
{
return AreaList(QueryOptions.Default, ct);
}

/// <summary>
/// AreaList returns all the available network areas
/// </summary>
public Task<QueryResult<List<Area>>> AreaList(QueryOptions q, CancellationToken ct = default)
{
return _client.Get<List<Area>>("/v1/operator/area", q).Execute(ct);
}
}

public class ConsulLicense
Expand Down

0 comments on commit 18ba35f

Please sign in to comment.