Skip to content

Commit

Permalink
upgrade testcontainers (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
K-Dud authored Nov 15, 2024
1 parent 13082bf commit d4309f4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
3 changes: 2 additions & 1 deletion backend/Contexture.Api.Tests/Contexture.Api.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
</PackageReference>
<PackageReference Update="FSharp.Core" Version="7.0.300" />
<PackageReference Include="NStore.Persistence.MsSql" Version="0.14.0" />
<PackageReference Include="Testcontainers" Version="2.4.0" />
<PackageReference Include="Testcontainers" Version="4.0.0" />
<PackageReference Include="Testcontainers.MsSql" Version="4.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion backend/Contexture.Api.Tests/EventStore.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ type MsSqlBackedEventStore(msSql: MsSqlFixture) =
let config =
MsSqlPersistenceOptions(
loggerFactory,
ConnectionString = msSql.Container.ConnectionString,
ConnectionString = msSql.Container.GetConnectionString(),
StreamsTableName = $"streams_{Interlocked.Increment(counter)}_{this.GetType().Name}",
Serializer = NStoreBased.JsonMsSqlSerializer.Default
)
Expand Down
10 changes: 5 additions & 5 deletions backend/Contexture.Api.Tests/PositionStorage.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ type SqlServerPositionStorage(msSql: MsSqlFixture) =
inherit PositionStorageBehavior()

override this.EmptyStorage() =
SqlServer.PositionStorage(msSql.Container.ConnectionString)
SqlServer.PositionStorage(msSql.Container.GetConnectionString())

override this.StorageWith items = task {
use client = new SqlConnection(msSql.Container.ConnectionString)
use client = new SqlConnection(msSql.Container.GetConnectionString())
do! client.OpenAsync()

// using string concatenation over parameters here is OK because it's just (unit) test code
Expand All @@ -98,15 +98,15 @@ type SqlServerPositionStorage(msSql: MsSqlFixture) =
let! result = command.ExecuteNonQueryAsync()
Assert.Equal(items |> List.length, result)

return SqlServer.PositionStorage(msSql.Container.ConnectionString) :> IStorePositions
return SqlServer.PositionStorage(msSql.Container.GetConnectionString()) :> IStorePositions
}

interface IAsyncLifetime with
member this.DisposeAsync() =
SqlServer.PositionStorage.RemoveSchema(msSql.Container.ConnectionString)
SqlServer.PositionStorage.RemoveSchema(msSql.Container.GetConnectionString())

member this.InitializeAsync() =
SqlServer.PositionStorage.CreateSchema(msSql.Container.ConnectionString)
SqlServer.PositionStorage.CreateSchema(msSql.Container.GetConnectionString())

interface IClassFixture<MsSqlFixture> with

15 changes: 4 additions & 11 deletions backend/Contexture.Api.Tests/SqlServerFixture.fs
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
namespace Contexture.Api.Tests

#nowarn "44" // ContainerBuilder<MsSqlTestcontainer>() is deprecated but does not provide a clear guidance yet

open System
open System.Threading
open DotNet.Testcontainers.Builders
open DotNet.Testcontainers.Configurations
open DotNet.Testcontainers.Containers
open Testcontainers.MsSql
open Xunit

type MsSqlFixture() =
static let mutable counter = ref 0
let container =
let container =
let containerConfiguration =
ContainerBuilder<MsSqlTestcontainer>()
.WithDatabase(new MsSqlTestcontainerConfiguration(Password = "localdevpassword#123"))
.WithImage("mcr.microsoft.com/mssql/server:2019-latest")
MsSqlBuilder()
.WithName($"MS-SQL-Integration-Tests-{Interlocked.Increment counter}")
.WithCleanUp(false)
.WithAutoRemove(true)

let instance = containerConfiguration.Build()
instance
containerConfiguration.Build()

member _.Container = container

Expand Down

0 comments on commit d4309f4

Please sign in to comment.