Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions test/IntegrationTests/OracleCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ private async Task<IContainer> LaunchOracleContainerAsync(int port)
var containersBuilder = new ContainerBuilder()
.WithImage(OracleImage)
.WithEnvironment("ORACLE_RANDOM_PASSWORD", "yes")
.WithEnvironment("APP_USER", "appuser")
.WithEnvironment("APP_USER_PASSWORD", Password)
.WithName($"oracle-{port}")
.WithPortBinding(port, OraclePort)
.WithWaitStrategy(Wait.ForUnixContainer().UntilInternalTcpPortIsAvailable(OraclePort))
Expand All @@ -76,6 +74,29 @@ private async Task<IContainer> LaunchOracleContainerAsync(int port)
var container = containersBuilder.Build();
await container.StartAsync();

// Create the application user after container is ready
// First ensure the pluggable database is open, then create the user
var createUserScript = $"ALTER PLUGGABLE DATABASE ALL OPEN; " +
$"ALTER SESSION SET CONTAINER=FREEPDB1; " +
$"CREATE USER appuser IDENTIFIED BY \"{Password}\" QUOTA UNLIMITED ON USERS; " +
$"GRANT CONNECT, RESOURCE TO appuser;";

var createResult = await container.ExecAsync(new[] { "bash", "-c", $"echo \"{createUserScript}\" | sqlplus -s / as sysdba" });

if (createResult.ExitCode != 0)
{
throw new InvalidOperationException($"Failed to create Oracle user. Exit code: {createResult.ExitCode}, Output: {createResult.Stdout}, Error: {createResult.Stderr}");
}

// Verify the user was created successfully by attempting to query it
var verifyScript = "ALTER SESSION SET CONTAINER=FREEPDB1; SELECT username FROM dba_users WHERE username='APPUSER';";
var verifyResult = await container.ExecAsync(new[] { "bash", "-c", $"echo \"{verifyScript}\" | sqlplus -s / as sysdba" });

if (verifyResult.ExitCode != 0 || !verifyResult.Stdout.Contains("APPUSER"))
{
throw new InvalidOperationException($"User creation verification failed. Exit code: {verifyResult.ExitCode}, Output: {verifyResult.Stdout}");
}

return container;
}

Expand Down
Loading