Skip to content

Commit 8907a94

Browse files
committed
chore: Apply repo standards
1 parent df8dd7a commit 8907a94

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

src/Testcontainers.Keycloak/KeycloakBuilder.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,19 @@ public KeycloakBuilder WithPassword(string password)
6161
}
6262

6363
/// <summary>
64-
/// Sets the Keycloak to Import Realm file.
64+
/// Configures Keycloak to import a realm configuration file during startup.
6565
/// </summary>
66-
/// <param name="path">The path to realm-export.json</param>
66+
/// <remarks>
67+
/// The file will be copied to the <c>/opt/keycloak/data/import/</c> directory
68+
/// inside the container:
69+
/// https://www.keycloak.org/server/importExport#_importing_a_realm_during_startup.
70+
/// </remarks>
71+
/// <param name="realmConfigurationFilePath">The local path to the realm configuration file (JSON).</param>
6772
/// <returns>A configured instance of <see cref="KeycloakBuilder" />.</returns>
68-
public KeycloakBuilder WithRealm(string path)
73+
public KeycloakBuilder WithRealm(string realmConfigurationFilePath)
6974
{
70-
return Clone(new ContainerConfiguration(command: new AppendEnumerable<string>(["--import-realm"])))
71-
.WithBindMount(path, "/opt/keycloak/data/import/realm-export.json");
75+
return WithCommand("--import-realm")
76+
.WithResourceMapping(realmConfigurationFilePath, "/opt/keycloak/data/import/");
7277
}
7378

7479
/// <inheritdoc />

tests/Testcontainers.Keycloak.Tests/KeycloakContainerTest.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
using System.IO;
2-
using System.Linq;
3-
41
namespace Testcontainers.Keycloak;
52

63
public abstract class KeycloakContainerTest : IAsyncLifetime
@@ -93,13 +90,13 @@ public KeycloakV26Configuration()
9390
public sealed class KeycloakRealmConfiguration : KeycloakContainerTest
9491
{
9592
public KeycloakRealmConfiguration()
96-
: base(new KeycloakBuilder().WithRealm(Path.GetFullPath("realm-export.json")).Build())
93+
: base(new KeycloakBuilder().WithRealm("realm-export.json").Build())
9794
{
9895
}
9996

10097
[Fact]
10198
[Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))]
102-
public async Task RealmIsImported()
99+
public async Task AllRealmsAreEnabled()
103100
{
104101
// Given
105102
var keycloakClient = new KeycloakClient(_keycloakContainer.GetBaseAddress(), KeycloakBuilder.DefaultUsername, KeycloakBuilder.DefaultPassword);
@@ -109,7 +106,7 @@ public async Task RealmIsImported()
109106
.ConfigureAwait(true);
110107

111108
// Then
112-
Assert.True(realms.Count() == 2);
109+
Assert.Collection(realms, realm => Assert.True(realm.Enabled), realm => Assert.True(realm.Enabled));
113110
}
114111
}
115112
}

tests/Testcontainers.Keycloak.Tests/Testcontainers.Keycloak.Tests.csproj

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66
<OutputType>Exe</OutputType>
77
</PropertyGroup>
88
<ItemGroup>
9-
<PackageReference Include="Microsoft.NET.Test.Sdk" />
10-
<PackageReference Include="coverlet.collector" />
11-
<PackageReference Include="xunit.runner.visualstudio" />
12-
<PackageReference Include="xunit.v3" />
13-
<PackageReference Include="Keycloak.Net.Core" />
9+
<PackageReference Include="Microsoft.NET.Test.Sdk"/>
10+
<PackageReference Include="coverlet.collector"/>
11+
<PackageReference Include="xunit.runner.visualstudio"/>
12+
<PackageReference Include="xunit.v3"/>
13+
<PackageReference Include="Keycloak.Net.Core"/>
1414
</ItemGroup>
1515
<ItemGroup>
16-
<ProjectReference Include="../../src/Testcontainers.Keycloak/Testcontainers.Keycloak.csproj" />
17-
<ProjectReference Include="../Testcontainers.Commons/Testcontainers.Commons.csproj" />
16+
<ProjectReference Include="../../src/Testcontainers.Keycloak/Testcontainers.Keycloak.csproj"/>
17+
<ProjectReference Include="../Testcontainers.Commons/Testcontainers.Commons.csproj"/>
1818
</ItemGroup>
1919
<ItemGroup>
20-
<None Update="realm-export.json">
21-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
22-
</None>
20+
<None Update="realm-export.json">
21+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
22+
</None>
2323
</ItemGroup>
2424
</Project>

0 commit comments

Comments
 (0)