Skip to content

Commit ba205a9

Browse files
committed
fix(ci): added new config for ci
1 parent 2209432 commit ba205a9

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

.github/workflows/ci.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
- main
77
pull_request:
88

9+
env:
10+
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
11+
912
jobs:
1013
build-and-test:
1114
runs-on: ubuntu-latest
@@ -19,9 +22,6 @@ jobs:
1922
with:
2023
dotnet-version: 9.0.x
2124

22-
- name: Set up Docker
23-
uses: docker/setup-docker@v4
24-
2525
- name: Restore solution
2626
run: dotnet restore Platform.Api.sln
2727

@@ -30,3 +30,5 @@ jobs:
3030

3131
- name: Test solution
3232
run: dotnet test Platform.Api.sln -m:1 -nr:false --no-build
33+
env:
34+
TESTCONTAINERS_RYUK_DISABLED: true

tests/Platform.Api.Tests/CustomWebApplicationFactory.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,15 @@ public sealed class CustomWebApplicationFactory : WebApplicationFactory<Program>
1818
.WithPassword("postgres")
1919
.Build();
2020

21+
private string? _connectionString;
22+
2123
public async Task InitializeAsync()
2224
{
2325
await _postgresContainer.StartAsync();
26+
_connectionString = _postgresContainer.GetConnectionString();
2427

28+
// Now that container is started and connection string is available,
29+
// we can safely access Services which will trigger host build
2530
using var scope = Services.CreateScope();
2631
var dbContext = scope.ServiceProvider.GetRequiredService<PlatformDbContext>();
2732
await dbContext.Database.MigrateAsync();
@@ -56,10 +61,16 @@ protected override void ConfigureWebHost(IWebHostBuilder builder)
5661
{
5762
builder.ConfigureAppConfiguration((_, config) =>
5863
{
64+
// Use the stored connection string - this will be set after container starts
65+
// If accessed before InitializeAsync, throw a clear error
66+
var connectionString = _connectionString
67+
?? throw new InvalidOperationException(
68+
"Connection string not available. Ensure InitializeAsync() has completed before accessing the application.");
69+
5970
config.AddInMemoryCollection(new Dictionary<string, string?>
6071
{
61-
["ConnectionStrings:DefaultConnection"] = _postgresContainer.GetConnectionString(),
62-
["Database:ConnectionString"] = _postgresContainer.GetConnectionString(),
72+
["ConnectionStrings:DefaultConnection"] = connectionString,
73+
["Database:ConnectionString"] = connectionString,
6374
["Jwt:SecretKey"] = "test-secret-key-minimum-32-characters-long-for-testing",
6475
["Jwt:Issuer"] = "Platform.Api.Tests",
6576
["Jwt:Audience"] = "Platform.Api.Tests",

0 commit comments

Comments
 (0)