Skip to content

Commit

Permalink
enhancement!: Add ICerbosClient interface for testing (#144)
Browse files Browse the repository at this point in the history
This PR adds `ICerbosClient` interface and modifies `Build` method of
the `CerbosClientBuilder` to return `ICerbosClient` instead. Resolves
#143.

Signed-off-by: Oğuzhan Durgun <oguzhandurgun95@gmail.com>
  • Loading branch information
oguzhand95 authored Aug 13, 2024
1 parent 6a921ca commit ef439ab
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Sdk.UnitTests/Cerbos/Sdk/UnitTests/CerbosClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public class CerbosClientTest

private IContainer? _container;

private CerbosClient? _client;
private CerbosClient? _clientPlayground;
private ICerbosClient? _client;
private ICerbosClient? _clientPlayground;

private readonly string _jwt =
"eyJhbGciOiJFUzM4NCIsImtpZCI6IjE5TGZaYXRFZGc4M1lOYzVyMjNndU1KcXJuND0iLCJ0eXAiOiJKV1QifQ.eyJhdWQiOlsiY2VyYm9zLWp3dC10ZXN0cyJdLCJjdXN0b21BcnJheSI6WyJBIiwiQiIsIkMiXSwiY3VzdG9tSW50Ijo0MiwiY3VzdG9tTWFwIjp7IkEiOiJBQSIsIkIiOiJCQiIsIkMiOiJDQyJ9LCJjdXN0b21TdHJpbmciOiJmb29iYXIiLCJleHAiOjE5NTAyNzc5MjYsImlzcyI6ImNlcmJvcy10ZXN0LXN1aXRlIn0._nCHIsuFI3wczeuUv_xjSwaVnIQUdYA9sGf_jVsrsDWloLs3iPWDaA1bXpuIUJVsi8-G6qqdrPI0cOBxEocg1NCm8fyD9T_3hsZV0fYWon_Je6Kl93a3JIW3S6kbvjsL";
Expand Down
2 changes: 1 addition & 1 deletion src/Sdk/Cerbos/Sdk/Builder/CerbosClientBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public CerbosClientBuilder WithGrpcChannelOptions(GrpcChannelOptions grpcChannel
return this;
}

public CerbosClient Build()
public ICerbosClient Build()
{
if (string.IsNullOrEmpty(Target))
{
Expand Down
2 changes: 1 addition & 1 deletion src/Sdk/Cerbos/Sdk/CerbosClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Cerbos.Sdk
/// <summary>
/// CerbosClient provides a client implementation that communicates with the PDP.
/// </summary>
public sealed class CerbosClient
public sealed class CerbosClient: ICerbosClient
{
private Api.V1.Svc.CerbosService.CerbosServiceClient CerbosServiceClient { get; }
private readonly Metadata _metadata;
Expand Down
14 changes: 14 additions & 0 deletions src/Sdk/Cerbos/Sdk/ICerbosClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Threading.Tasks;
using Cerbos.Sdk.Response;
using Grpc.Core;

namespace Cerbos.Sdk
{
public interface ICerbosClient
{
CheckResourcesResponse CheckResources(Builder.CheckResourcesRequest request, Metadata headers = null);
Task<CheckResourcesResponse> CheckResourcesAsync(Builder.CheckResourcesRequest request, Metadata headers = null);
PlanResourcesResponse PlanResources(Builder.PlanResourcesRequest request, Metadata headers = null);
Task<PlanResourcesResponse> PlanResourcesAsync(Builder.PlanResourcesRequest request, Metadata headers = null);
}
}

0 comments on commit ef439ab

Please sign in to comment.