Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
w1am committed Mar 20, 2024
1 parent 61c20e0 commit 2571caf
Show file tree
Hide file tree
Showing 50 changed files with 390 additions and 143 deletions.
20 changes: 17 additions & 3 deletions .github/workflows/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ on:
docker-tag:
required: true
type: string
docker-registry:
required: false
type: string
default: docker.eventstore.com/eventstore-ce/eventstoredb-ce
build-matrix:
required: false
type: string
default: '["Streams", "PersistentSubscriptions", "Operations", "UserManagement", "ProjectionManagement"]'
test-matrix:
required: false
type: string
default: '["Streams", "PersistentSubscriptions", "Operations", "UserManagement", "ProjectionManagement"]'

jobs:
test:
Expand All @@ -15,7 +27,8 @@ jobs:
matrix:
framework: [ net6.0, net7.0, net8.0 ]
os: [ ubuntu-latest ]
test: [ Streams, PersistentSubscriptions, Operations, UserManagement, ProjectionManagement ]
build: ${{fromJson(inputs.build-matrix)}}
test: ${{fromJson(inputs.test-matrix)}}
configuration: [ release ]
runs-on: ${{ matrix.os }}
name: EventStore.Client.${{ matrix.test }}/${{ matrix.os }}/${{ matrix.framework }}/${{ inputs.docker-tag }}
Expand All @@ -36,7 +49,7 @@ jobs:
- name: Pull EventStore Image
shell: bash
run: |
docker pull docker.eventstore.com/eventstore-ce/eventstoredb-ce:${{ inputs.docker-tag }}
docker pull ${{ inputs.docker-registry }}:${{ inputs.docker-tag }}
- name: Install dotnet SDKs
uses: actions/setup-dotnet@v3
with:
Expand All @@ -47,11 +60,12 @@ jobs:
- name: Compile
shell: bash
run: |
dotnet build --configuration ${{ matrix.configuration }} --framework ${{ matrix.framework }} src/EventStore.Client.${{ matrix.test }}
dotnet build --configuration ${{ matrix.configuration }} --framework ${{ matrix.framework }} src/EventStore.Client.${{ matrix.build }}
- name: Run Tests
shell: bash
env:
ES_DOCKER_TAG: ${{ inputs.docker-tag }}
ES_DOCKER_REGISTRY: ${{ inputs.docker-registry }}
run: |
sudo ./gencert.sh
dotnet test --configuration ${{ matrix.configuration }} --blame \
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/enterprise.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Test CI

on:
pull_request:
push:
branches:
- master
tags:
- v*

jobs:
test:
uses: ./.github/workflows/base.yml
with:
docker-tag: 24.2.0-jammy
docker-registry: docker.eventstore.com/eventstore-ee/eventstoredb-commercial
build-matrix: '["Streams", "PersistentSubscriptions", "Operations", "UserManagement", "ProjectionManagement"]'
test-matrix: '["Plugins"]'
secrets: inherit
7 changes: 7 additions & 0 deletions EventStore.Client.sln
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventStore.Client.UserManag
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventStore.Client.Tests.Common", "test\EventStore.Client.Tests.Common\EventStore.Client.Tests.Common.csproj", "{E326832D-DE52-4DE4-9E54-C800908B75F3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventStore.Client.Plugins.Tests", "test\EventStore.Client.Plugins.Tests\EventStore.Client.Plugins.Tests.csproj", "{315B38AF-4574-4E25-992B-CA0D24C95884}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand Down Expand Up @@ -94,6 +96,10 @@ Global
{E326832D-DE52-4DE4-9E54-C800908B75F3}.Debug|x64.Build.0 = Debug|Any CPU
{E326832D-DE52-4DE4-9E54-C800908B75F3}.Release|x64.ActiveCfg = Release|Any CPU
{E326832D-DE52-4DE4-9E54-C800908B75F3}.Release|x64.Build.0 = Release|Any CPU
{315B38AF-4574-4E25-992B-CA0D24C95884}.Debug|x64.ActiveCfg = Debug|Any CPU
{315B38AF-4574-4E25-992B-CA0D24C95884}.Debug|x64.Build.0 = Debug|Any CPU
{315B38AF-4574-4E25-992B-CA0D24C95884}.Release|x64.ActiveCfg = Release|Any CPU
{315B38AF-4574-4E25-992B-CA0D24C95884}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{D3744A86-DD35-4104-AAEE-84B79062C4A2} = {EA59C1CB-16DA-4F68-AF8A-642A969B4CF8}
Expand All @@ -109,5 +115,6 @@ Global
{6CEB731F-72E1-461F-A6B3-54DBF3FD786C} = {C51F2C69-45A9-4D0D-A708-4FC319D5D340}
{22634CEE-4F7B-4679-A48D-38A2A8580ECA} = {C51F2C69-45A9-4D0D-A708-4FC319D5D340}
{E326832D-DE52-4DE4-9E54-C800908B75F3} = {C51F2C69-45A9-4D0D-A708-4FC319D5D340}
{315B38AF-4574-4E25-992B-CA0D24C95884} = {C51F2C69-45A9-4D0D-A708-4FC319D5D340}
EndGlobalSection
EndGlobal
18 changes: 11 additions & 7 deletions gencert.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ Write-Host ">> Generating certificate..."
New-Item -ItemType Directory -Path .\certs -Force

# Set permissions for the directory
icacls .\certs /grant:r "$($env:UserName):(OI)(CI)RX"
icacls .\certs /grant:r "$($env:UserName):(OI)(CI)F"

# Pull the Docker image
docker pull eventstore/es-gencert-cli:1.0.2
docker pull ghcr.io/eventstore/es-gencert-cli:1.3

# Create CA certificate
docker run --rm --volume ${PWD}\certs:/tmp --user (Get-Process -Id $PID).SessionId eventstore/es-gencert-cli:1.0.2 create-ca -out /tmp/ca
docker run --rm --volume ${PWD}\certs:/tmp ghcr.io/eventstore/es-gencert-cli create-ca -out /tmp/ca

# Create node certificate
docker run --rm --volume ${PWD}\certs:/tmp --user (Get-Process -Id $PID).SessionId eventstore/es-gencert-cli:1.0.2 create-node -ca-certificate /tmp/ca/ca.crt -ca-key /tmp/ca/ca.key -out /tmp/node -ip-addresses 127.0.0.1 -dns-names localhost
docker run --rm --volume ${PWD}\certs:/tmp ghcr.io/eventstore/es-gencert-cli create-node -ca-certificate /tmp/ca/ca.crt -ca-key /tmp/ca/ca.key -out /tmp/node -ip-addresses 127.0.0.1 -dns-names localhost

# Create admin user
docker run --rm --volume ${PWD}\certs:/tmp ghcr.io/eventstore/es-gencert-cli create-user -username admin -ca-certificate /tmp/ca/ca.crt -ca-key /tmp/ca/ca.key -out /tmp/user-admin

# Create an invalid user
docker run --rm --volume ${PWD}\certs:/tmp ghcr.io/eventstore/es-gencert-cli create-user -username invalid -ca-certificate /tmp/ca/ca.crt -ca-key /tmp/ca/ca.key -out /tmp/user-invalid

# Set permissions recursively for the directory
icacls .\certs /grant:r "$($env:UserName):(OI)(CI)RX"
icacls .\certs /grant:r "$($env:UserName):(OI)(CI)F"

Import-Certificate -FilePath ".\certs\ca\ca.crt" -CertStoreLocation Cert:\CurrentUser\Root
10 changes: 7 additions & 3 deletions gencert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ mkdir -p certs

chmod 0755 ./certs

docker pull eventstore/es-gencert-cli:1.0.2
docker pull ghcr.io/eventstore/es-gencert-cli:1.3

docker run --rm --volume $PWD/certs:/tmp --user $(id -u):$(id -g) eventstore/es-gencert-cli:1.0.2 create-ca -out /tmp/ca
docker run --rm --volume $PWD/certs:/tmp --user $(id -u):$(id -g) ghcr.io/eventstore/es-gencert-cli create-ca -out /tmp/ca

docker run --rm --volume $PWD/certs:/tmp --user $(id -u):$(id -g) eventstore/es-gencert-cli:1.0.2 create-node -ca-certificate /tmp/ca/ca.crt -ca-key /tmp/ca/ca.key -out /tmp/node -ip-addresses 127.0.0.1 -dns-names localhost
docker run --rm --volume $PWD/certs:/tmp --user $(id -u):$(id -g) ghcr.io/eventstore/es-gencert-cli create-node -ca-certificate /tmp/ca/ca.crt -ca-key /tmp/ca/ca.key -out /tmp/node -ip-addresses 127.0.0.1 -dns-names localhost

docker run --rm --volume $PWD/certs:/tmp --user $(id -u):$(id -g) ghcr.io/eventstore/es-gencert-cli create-user -username admin -ca-certificate /tmp/ca/ca.crt -ca-key /tmp/ca/ca.key -out /tmp/user-admin

docker run --rm --volume $PWD/certs:/tmp --user $(id -u):$(id -g) ghcr.io/eventstore/es-gencert-cli create-user -username invalid -ca-certificate /tmp/ca/ca.crt -ca-key /tmp/ca/ca.key -out /tmp/user-invalid

chmod -R 0755 ./certs

Expand Down
4 changes: 3 additions & 1 deletion src/EventStore.Client.Common/EventStoreCallOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static CallOptions CreateNonStreaming(
Create(
settings,
deadline ?? settings.DefaultDeadline,
userCredentials?.ClientCertificate != null ? null : userCredentials,
userCredentials,
cancellationToken
);

Expand Down Expand Up @@ -60,6 +60,8 @@ static CallOptions Create(
.GetAuthenticationHeaderValue(credentials!, CancellationToken.None)
.ConfigureAwait(false);

Console.WriteLine("authorizationHeader " + authorizationHeader);

metadata.Add(Constants.Headers.Authorization, authorizationHeader);
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public async Task ShutdownAsync(
TimeSpan? deadline = null,
UserCredentials? userCredentials = null,
CancellationToken cancellationToken = default) {
var channelInfo = await GetChannelInfo(userCredentials, cancellationToken).ConfigureAwait(false);
var channelInfo = await GetChannelInfo(cancellationToken).ConfigureAwait(false);
using var call = new Operations.Operations.OperationsClient(
channelInfo.CallInvoker).ShutdownAsync(EmptyResult,
EventStoreCallOptions.CreateNonStreaming(Settings, deadline, userCredentials, cancellationToken));
Expand All @@ -36,7 +36,7 @@ public async Task MergeIndexesAsync(
TimeSpan? deadline = null,
UserCredentials? userCredentials = null,
CancellationToken cancellationToken = default) {
var channelInfo = await GetChannelInfo(userCredentials, cancellationToken).ConfigureAwait(false);
var channelInfo = await GetChannelInfo(cancellationToken).ConfigureAwait(false);
using var call = new Operations.Operations.OperationsClient(
channelInfo.CallInvoker).MergeIndexesAsync(EmptyResult,
EventStoreCallOptions.CreateNonStreaming(Settings, deadline, userCredentials, cancellationToken));
Expand All @@ -54,7 +54,7 @@ public async Task ResignNodeAsync(
TimeSpan? deadline = null,
UserCredentials? userCredentials = null,
CancellationToken cancellationToken = default) {
var channelInfo = await GetChannelInfo(userCredentials, cancellationToken).ConfigureAwait(false);
var channelInfo = await GetChannelInfo(cancellationToken).ConfigureAwait(false);
using var call = new Operations.Operations.OperationsClient(
channelInfo.CallInvoker).ResignNodeAsync(EmptyResult,
EventStoreCallOptions.CreateNonStreaming(Settings, deadline, userCredentials, cancellationToken));
Expand All @@ -73,7 +73,7 @@ public async Task SetNodePriorityAsync(int nodePriority,
TimeSpan? deadline = null,
UserCredentials? userCredentials = null,
CancellationToken cancellationToken = default) {
var channelInfo = await GetChannelInfo(userCredentials, cancellationToken).ConfigureAwait(false);
var channelInfo = await GetChannelInfo(cancellationToken).ConfigureAwait(false);
using var call = new Operations.Operations.OperationsClient(
channelInfo.CallInvoker).SetNodePriorityAsync(
new SetNodePriorityReq {Priority = nodePriority},
Expand All @@ -92,7 +92,7 @@ public async Task RestartPersistentSubscriptions(
TimeSpan? deadline = null,
UserCredentials? userCredentials = null,
CancellationToken cancellationToken = default) {
var channelInfo = await GetChannelInfo(userCredentials, cancellationToken).ConfigureAwait(false);
var channelInfo = await GetChannelInfo(cancellationToken).ConfigureAwait(false);
using var call = new Operations.Operations.OperationsClient(
channelInfo.CallInvoker).RestartPersistentSubscriptionsAsync(
EmptyResult,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public async Task<DatabaseScavengeResult> StartScavengeAsync(
throw new ArgumentOutOfRangeException(nameof(startFromChunk));
}

var channelInfo = await GetChannelInfo(userCredentials, cancellationToken).ConfigureAwait(false);
var channelInfo = await GetChannelInfo(cancellationToken).ConfigureAwait(false);
using var call = new Operations.Operations.OperationsClient(
channelInfo.CallInvoker).StartScavengeAsync(
new StartScavengeReq {
Expand Down Expand Up @@ -62,7 +62,7 @@ public async Task<DatabaseScavengeResult> StopScavengeAsync(
TimeSpan? deadline = null,
UserCredentials? userCredentials = null,
CancellationToken cancellationToken = default) {
var channelInfo = await GetChannelInfo(userCredentials, cancellationToken).ConfigureAwait(false);
var channelInfo = await GetChannelInfo(cancellationToken).ConfigureAwait(false);
var result = await new Operations.Operations.OperationsClient(
channelInfo.CallInvoker).StopScavengeAsync(new StopScavengeReq {
Options = new StopScavengeReq.Types.Options {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private async Task CreateInternalAsync(string streamName, string groupName, IEve
"The specified consumer strategy is not supported, specify one of the SystemConsumerStrategies");
}

var channelInfo = await GetChannelInfo(userCredentials, cancellationToken).ConfigureAwait(false);
var channelInfo = await GetChannelInfo(userCredentials?.UserCertificate, cancellationToken).ConfigureAwait(false);

if (streamName == SystemStreams.AllStream &&
!channelInfo.ServerCapabilities.SupportsPersistentSubscriptionsToAll) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public Task DeleteAsync(string streamName, string groupName, TimeSpan? deadline
/// </summary>
public async Task DeleteToStreamAsync(string streamName, string groupName, TimeSpan? deadline = null,
UserCredentials? userCredentials = null, CancellationToken cancellationToken = default) {
var channelInfo = await GetChannelInfo(userCredentials, cancellationToken).ConfigureAwait(false);
var channelInfo = await GetChannelInfo(userCredentials?.UserCertificate, cancellationToken).ConfigureAwait(false);

if (streamName == SystemStreams.AllStream &&
!channelInfo.ServerCapabilities.SupportsPersistentSubscriptionsToAll) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ partial class EventStorePersistentSubscriptionsClient {
/// </summary>
public async Task<PersistentSubscriptionInfo> GetInfoToAllAsync(string groupName, TimeSpan? deadline = null,
UserCredentials? userCredentials = null, CancellationToken cancellationToken = default) {
var channelInfo = await GetChannelInfo(userCredentials, cancellationToken).ConfigureAwait(false);
var channelInfo = await GetChannelInfo(userCredentials?.UserCertificate, cancellationToken).ConfigureAwait(false);
if (channelInfo.ServerCapabilities.SupportsPersistentSubscriptionsGetInfo) {
var req = new GetInfoReq() {
Options = new GetInfoReq.Types.Options{
Expand All @@ -33,7 +33,7 @@ public async Task<PersistentSubscriptionInfo> GetInfoToAllAsync(string groupName
/// </summary>
public async Task<PersistentSubscriptionInfo> GetInfoToStreamAsync(string streamName, string groupName,
TimeSpan? deadline = null, UserCredentials? userCredentials = null, CancellationToken cancellationToken = default) {
var channelInfo = await GetChannelInfo(userCredentials, cancellationToken).ConfigureAwait(false);
var channelInfo = await GetChannelInfo(userCredentials?.UserCertificate, cancellationToken).ConfigureAwait(false);
if (channelInfo.ServerCapabilities.SupportsPersistentSubscriptionsGetInfo) {
var req = new GetInfoReq() {
Options = new GetInfoReq.Types.Options {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ partial class EventStorePersistentSubscriptionsClient {
public async Task<IEnumerable<PersistentSubscriptionInfo>> ListToAllAsync(TimeSpan? deadline = null,
UserCredentials? userCredentials = null, CancellationToken cancellationToken = default) {

var channelInfo = await GetChannelInfo(userCredentials, cancellationToken).ConfigureAwait(false);
var channelInfo = await GetChannelInfo(userCredentials?.UserCertificate, cancellationToken).ConfigureAwait(false);
if (channelInfo.ServerCapabilities.SupportsPersistentSubscriptionsList) {
var req = new ListReq() {
Options = new ListReq.Types.Options{
Expand All @@ -38,7 +38,7 @@ public async Task<IEnumerable<PersistentSubscriptionInfo>> ListToAllAsync(TimeSp
public async Task<IEnumerable<PersistentSubscriptionInfo>> ListToStreamAsync(string streamName, TimeSpan? deadline = null,
UserCredentials? userCredentials = null, CancellationToken cancellationToken = default) {

var channelInfo = await GetChannelInfo(userCredentials, cancellationToken).ConfigureAwait(false);
var channelInfo = await GetChannelInfo(userCredentials?.UserCertificate, cancellationToken).ConfigureAwait(false);
if (channelInfo.ServerCapabilities.SupportsPersistentSubscriptionsList) {
var req = new ListReq() {
Options = new ListReq.Types.Options {
Expand All @@ -62,7 +62,7 @@ public async Task<IEnumerable<PersistentSubscriptionInfo>> ListToStreamAsync(str
public async Task<IEnumerable<PersistentSubscriptionInfo>> ListAllAsync(TimeSpan? deadline = null,
UserCredentials? userCredentials = null, CancellationToken cancellationToken = default) {

var channelInfo = await GetChannelInfo(userCredentials, cancellationToken).ConfigureAwait(false);
var channelInfo = await GetChannelInfo(userCredentials?.UserCertificate, cancellationToken).ConfigureAwait(false);
if (channelInfo.ServerCapabilities.SupportsPersistentSubscriptionsList) {
var req = new ListReq() {
Options = new ListReq.Types.Options {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public PersistentSubscriptionResult SubscribeToStream(string streamName, string
}

return new PersistentSubscriptionResult(streamName, groupName, async ct => {
var channelInfo = await GetChannelInfo(userCredentials, ct).ConfigureAwait(false);
var channelInfo = await GetChannelInfo(userCredentials?.UserCertificate, ct).ConfigureAwait(false);

if (streamName == SystemStreams.AllStream &&
!channelInfo.ServerCapabilities.SupportsPersistentSubscriptionsToAll) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ partial class EventStorePersistentSubscriptionsClient {
public async Task ReplayParkedMessagesToAllAsync(string groupName, long? stopAt = null, TimeSpan? deadline = null,
UserCredentials? userCredentials = null, CancellationToken cancellationToken = default) {

var channelInfo = await GetChannelInfo(userCredentials, cancellationToken).ConfigureAwait(false);
var channelInfo = await GetChannelInfo(userCredentials?.UserCertificate, cancellationToken).ConfigureAwait(false);
if (channelInfo.ServerCapabilities.SupportsPersistentSubscriptionsReplayParked) {
var req = new ReplayParkedReq() {
Options = new ReplayParkedReq.Types.Options{
Expand Down Expand Up @@ -46,7 +46,7 @@ await ReplayParkedHttpAsync(SystemStreams.AllStream, groupName, stopAt, channelI
public async Task ReplayParkedMessagesToStreamAsync(string streamName, string groupName, long? stopAt=null,
TimeSpan? deadline=null, UserCredentials? userCredentials=null, CancellationToken cancellationToken=default) {

var channelInfo = await GetChannelInfo(userCredentials, cancellationToken).ConfigureAwait(false);
var channelInfo = await GetChannelInfo(userCredentials?.UserCertificate, cancellationToken).ConfigureAwait(false);
if (channelInfo.ServerCapabilities.SupportsPersistentSubscriptionsReplayParked) {
var req = new ReplayParkedReq() {
Options = new ReplayParkedReq.Types.Options {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ partial class EventStorePersistentSubscriptionsClient {
/// </summary>
public async Task RestartSubsystemAsync(TimeSpan? deadline = null, UserCredentials? userCredentials = null,
CancellationToken cancellationToken = default) {
var channelInfo = await GetChannelInfo(userCredentials, cancellationToken).ConfigureAwait(false);
var channelInfo = await GetChannelInfo(userCredentials?.UserCertificate, cancellationToken).ConfigureAwait(false);
if (channelInfo.ServerCapabilities.SupportsPersistentSubscriptionsRestartSubsystem) {
await new PersistentSubscriptions.PersistentSubscriptions.PersistentSubscriptionsClient(channelInfo.CallInvoker)
.RestartSubsystemAsync(new Empty(), EventStoreCallOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public async Task UpdateToStreamAsync(string streamName, string groupName, Persi
$"{nameof(settings.StartFrom)} must be of type '{nameof(Position)}' when subscribing to {SystemStreams.AllStream}");
}

var channelInfo = await GetChannelInfo(userCredentials, cancellationToken).ConfigureAwait(false);
var channelInfo = await GetChannelInfo(userCredentials?.UserCertificate, cancellationToken).ConfigureAwait(false);

if (streamName == SystemStreams.AllStream &&
!channelInfo.ServerCapabilities.SupportsPersistentSubscriptionsToAll) {
Expand Down
Loading

0 comments on commit 2571caf

Please sign in to comment.