-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ type VahterTestContainers() = | |
let mutable publicConnectionString: string = null | ||
|
||
// base image for the app, we'll build exactly how we build it in Azure | ||
let buildLogger = StringLogger() | ||
let image = | ||
ImageFromDockerfileBuilder() | ||
.WithDockerfileDirectory(solutionDir, String.Empty) | ||
|
@@ -39,6 +40,8 @@ type VahterTestContainers() = | |
.WithBuildArgument("RESOURCE_REAPER_SESSION_ID", ResourceReaper.DefaultSessionId.ToString("D")) | ||
// it might speed up the process to not clean up the base image | ||
.WithCleanUp(false) | ||
.WithDeleteIfExists(true) | ||
.WithLogger(buildLogger) | ||
.Build() | ||
|
||
// private network for the containers | ||
|
@@ -113,17 +116,27 @@ type VahterTestContainers() = | |
.DependsOn(flywayContainer) | ||
.WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(80)) | ||
.Build() | ||
|
||
let startContainers() = task { | ||
try | ||
// start building the image and spin up db at the same time | ||
let imageTask = image.CreateAsync() | ||
let dbTask = dbContainer.StartAsync() | ||
|
||
// wait for both to finish | ||
do! imageTask | ||
do! dbTask | ||
with | ||
| e -> | ||
let logs = buildLogger.ExtractMessages() | ||
let errorMessage = "Container startup failure, logs:\n" + if String.IsNullOrWhiteSpace logs then "<no logs provided>" else logs | ||
raise <| Exception(errorMessage, e) | ||
Check failure on line 133 in src/VahterBanBot.Tests/ContainerTestBase.fs GitHub Actions / Test resultsBaseTests+BaseTests ► Not possible to interact with the bot without authorization
Raw output
Check failure on line 133 in src/VahterBanBot.Tests/ContainerTestBase.fs GitHub Actions / Test resultsBaseTests+BaseTests ► Random path returns OK
Raw output
Check failure on line 133 in src/VahterBanBot.Tests/ContainerTestBase.fs GitHub Actions / Test resultsBaseTests+BaseTests ► Should be possible to interact with the bot
Raw output
Check failure on line 133 in src/VahterBanBot.Tests/ContainerTestBase.fs GitHub Actions / Test resultsPingTests+PingTests ► Message got recorded
Raw output
Check failure on line 133 in src/VahterBanBot.Tests/ContainerTestBase.fs GitHub Actions / Test resultsPingTests+PingTests ► Message not recorded if chat is not on the list
Raw output
Check failure on line 133 in src/VahterBanBot.Tests/ContainerTestBase.fs GitHub Actions / Test resultsVahterBanBot.Tests.BanTests+BanTests ► NON Vahter can't ban on reply
Raw output
Check failure on line 133 in src/VahterBanBot.Tests/ContainerTestBase.fs GitHub Actions / Test resultsVahterBanBot.Tests.BanTests+BanTests ► Only Vahter can unban user
Raw output
Check failure on line 133 in src/VahterBanBot.Tests/ContainerTestBase.fs GitHub Actions / Test resultsVahterBanBot.Tests.BanTests+BanTests ► Vahter can ban on reply
Raw output
Check failure on line 133 in src/VahterBanBot.Tests/ContainerTestBase.fs GitHub Actions / Test resultsVahterBanBot.Tests.BanTests+BanTests ► Vahter can unban user
Raw output
Check failure on line 133 in src/VahterBanBot.Tests/ContainerTestBase.fs GitHub Actions / Test resultsVahterBanBot.Tests.BanTests+BanTests ► Vahter can't ban another vahter
Raw output
Check failure on line 133 in src/VahterBanBot.Tests/ContainerTestBase.fs GitHub Actions / Test resultsVahterBanBot.Tests.BanTests+BanTests ► Vahter can't ban on reply in non-allowed chat
Raw output
|
||
} | ||
|
||
interface IAsyncLifetime with | ||
member this.InitializeAsync() = task { | ||
try | ||
// start building the image and spin up db at the same time | ||
let imageTask = image.CreateAsync() | ||
let dbTask = dbContainer.StartAsync() | ||
|
||
// wait for both to finish | ||
do! imageTask | ||
do! dbTask | ||
do! startContainers() | ||
publicConnectionString <- $"Server=127.0.0.1;Database=vahter_bot_ban;Port={dbContainer.GetMappedPublicPort(5432)};User Id=vahter_bot_ban_service;Password=vahter_bot_ban_service;Include Error Detail=true;Minimum Pool Size=1;Maximum Pool Size=20;Max Auto Prepare=100;Auto Prepare Min Usages=1;Trust Server Certificate=true;" | ||
|
||
// initialize DB with the schema, database and a DB user | ||
|
@@ -158,9 +171,10 @@ type VahterTestContainers() = | |
httpClient.BaseAddress <- uri | ||
httpClient.DefaultRequestHeaders.Add("X-Telegram-Bot-Api-Secret-Token", "OUR_SECRET") | ||
finally | ||
let struct (_, err) = appContainer.GetLogsAsync().Result | ||
if err <> "" then | ||
failwith err | ||
if appContainer.State <> TestcontainersStates.Undefined then | ||
let struct (_stdout, err) = appContainer.GetLogsAsync().Result | ||
if err <> "" then | ||
failwith err | ||
} | ||
member this.DisposeAsync() = task { | ||
// stop all the containers, flyway might be dead already | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace VahterBanBot.Tests | ||
|
||
open System | ||
open Microsoft.Extensions.Logging | ||
|
||
type StringLogger() = | ||
let lockObj = obj() | ||
let messages = ResizeArray<string>() | ||
interface ILogger with | ||
member this.BeginScope _ = null | ||
member this.IsEnabled _ = true | ||
member this.Log(logLevel, _eventId, state, ex, formatter) = | ||
lock lockObj (fun() -> | ||
messages.Add($"[{logLevel}] {formatter.Invoke(state, ex)}")) | ||
|
||
member _.ExtractMessages(): string = lock lockObj (fun() -> String.Join("\n", messages)) |