Skip to content
Open
Show file tree
Hide file tree
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
48 changes: 5 additions & 43 deletions .github/workflows/healthchecks_oracle_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,46 +29,8 @@ on:

jobs:
build:
runs-on: ubuntu-latest
services:
oracle:
image: gvenzl/oracle-xe:18-slim
ports:
- 1521:1521
env:
ORACLE_PASSWORD: oracle
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x
9.0.x
- name: Restore
run: |
dotnet restore ./src/HealthChecks.Oracle/HealthChecks.Oracle.csproj &&
dotnet restore ./test/HealthChecks.Oracle.Tests/HealthChecks.Oracle.Tests.csproj
- name: Check formatting
run: |
dotnet format --no-restore --verify-no-changes --severity warn ./src/HealthChecks.Oracle/HealthChecks.Oracle.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1) &&
dotnet format --no-restore --verify-no-changes --severity warn ./test/HealthChecks.Oracle.Tests/HealthChecks.Oracle.Tests.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1)
- name: Build
run: |
dotnet build --no-restore ./src/HealthChecks.Oracle/HealthChecks.Oracle.csproj &&
dotnet build --no-restore ./test/HealthChecks.Oracle.Tests/HealthChecks.Oracle.Tests.csproj
- name: Test
run: >
dotnet test
./test/HealthChecks.Oracle.Tests/HealthChecks.Oracle.Tests.csproj
--no-restore
--no-build
--collect "XPlat Code Coverage"
--results-directory .coverage
--
DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
- name: Upload Coverage
uses: codecov/codecov-action@v5
with:
flags: Oracle
directory: .coverage
uses: ./.github/workflows/reusable_ci_workflow.yml
with:
PROJECT_PATH: ./src/HealthChecks.Oracle/HealthChecks.Oracle.csproj
TEST_PROJECT_PATH: ./test/HealthChecks.Oracle.Tests/HealthChecks.Oracle.Tests.csproj
CODECOV_FLAGS: Oracle
3 changes: 2 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
<PackageVersion Include="Testcontainers.ClickHouse" Version="$(TestcontainersVersion)" />
<PackageVersion Include="Testcontainers.Kafka" Version="$(TestcontainersVersion)" />
<PackageVersion Include="Testcontainers.Milvus" Version="$(TestcontainersVersion)" />
<PackageVersion Include="Testcontainers.Oracle" Version="$(TestcontainersVersion)" />
<PackageVersion Include="Testcontainers.PostgreSql" Version="$(TestcontainersVersion)" />
<PackageVersion Include="TestContainers.MongoDb" Version="$(TestcontainersVersion)" />
<PackageVersion Include="Testcontainers.MsSql" Version="$(TestcontainersVersion)" />
Expand All @@ -119,4 +120,4 @@
<ItemGroup Condition="'$(IsPackable)' == 'true'">
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace HealthChecks.Oracle.Tests.Functional;

public class oracle_healthcheck_should
public class oracle_healthcheck_should(OracleContainerFixture oracleFixture) : IClassFixture<OracleContainerFixture>
{
[Fact]
public async Task be_healthy_when_oracle_is_available()
{
var connectionString = "Data Source=localhost:1521/XEPDB1;User Id=system;Password=oracle";
string connectionString = oracleFixture.GetConnectionString();

var webHostBuilder = new WebHostBuilder()
.ConfigureServices(services =>
Expand All @@ -34,13 +34,15 @@ public async Task be_healthy_when_oracle_is_available()
[Fact]
public async Task be_unhealthy_when_oracle_is_not_available()
{
var connectionString = "Data Source=255.255.255.255:1521/XEPDB1;User Id=system;Password=oracle";
var connectionStringBuilder = oracleFixture.GetConnectionStringBuilder();

connectionStringBuilder.DataSource = "invalid";

var webHostBuilder = new WebHostBuilder()
.ConfigureServices(services =>
{
services.AddHealthChecks()
.AddOracle(connectionString, tags: ["oracle"]);
.AddOracle(connectionStringBuilder.ConnectionString, tags: ["oracle"]);
})
.Configure(app =>
{
Expand All @@ -58,7 +60,8 @@ public async Task be_unhealthy_when_oracle_is_not_available()
[Fact]
public async Task be_unhealthy_when_sql_query_is_not_valid()
{
var connectionString = "Data Source=localhost:1521/XEPDB1;User Id=system;Password=oracle";
string connectionString = oracleFixture.GetConnectionString();

var webHostBuilder = new WebHostBuilder()
.ConfigureServices(services =>
{
Expand All @@ -82,7 +85,7 @@ public async Task be_unhealthy_when_sql_query_is_not_valid()
public async Task be_healthy_with_connection_string_factory_when_oracle_is_available()
{
bool factoryCalled = false;
string connectionString = "Data Source=localhost:1521/XEPDB1;User Id=system;Password=oracle";
string connectionString = oracleFixture.GetConnectionString();

var webHostBuilder = new WebHostBuilder()
.ConfigureServices(services =>
Expand Down Expand Up @@ -114,8 +117,8 @@ public async Task be_healthy_with_connection_string_factory_when_oracle_is_avail
public async Task be_healthy_with_connection_string_and_credential_when_oracle_is_available()
{
bool factoryCalled = false;
string connectionString = "Data Source=localhost:1521/XEPDB1";
var password = new NetworkCredential("system", "oracle").SecurePassword;
var connectionStringBuilder = oracleFixture.GetConnectionStringBuilder();
var password = new NetworkCredential(connectionStringBuilder.UserID, connectionStringBuilder.Password).SecurePassword;
password.MakeReadOnly();
var credential = new OracleCredential("system", password);

Expand All @@ -124,7 +127,7 @@ public async Task be_healthy_with_connection_string_and_credential_when_oracle_i
{
services
.AddHealthChecks()
.AddOracle(connectionString, tags: ["oracle"],
.AddOracle($"DATA SOURCE={connectionStringBuilder.DataSource}", tags: ["oracle"],
configure: options =>
{
factoryCalled = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
<ProjectReference Include="..\..\src\HealthChecks.Oracle\HealthChecks.Oracle.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Testcontainers.Oracle" />
</ItemGroup>

</Project>
42 changes: 42 additions & 0 deletions test/HealthChecks.Oracle.Tests/OracleContainerFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Oracle.ManagedDataAccess.Client;
using Testcontainers.Oracle;

namespace HealthChecks.Oracle.Tests;

public class OracleContainerFixture : IAsyncLifetime
{
private const string Registry = "docker.io";

private const string Image = "gvenzl/oracle-xe";

private const string Tag = "21.3.0-slim-faststart";

public OracleContainer? Container { get; private set; }

public string GetConnectionString()
{
if (Container is null)
{
throw new InvalidOperationException("The test container was not initialized.");
}

return Container.GetConnectionString();
}

public OracleConnectionStringBuilder GetConnectionStringBuilder() => new(GetConnectionString());

public async Task InitializeAsync() => Container = await CreateContainerAsync();

public Task DisposeAsync() => Container?.DisposeAsync().AsTask() ?? Task.CompletedTask;

private async Task<OracleContainer> CreateContainerAsync()
{
var container = new OracleBuilder()
.WithImage($"{Registry}/{Image}:{Tag}")
.Build();

await container.StartAsync();

return container;
}
}