-
Notifications
You must be signed in to change notification settings - Fork 701
Use test containers to facilitate running various integration tests #1931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
0898c9a
Unignore Rider files to share them (as they should be) and add docker…
PhenX 5847220
Some cleanup
PhenX c40b690
Merge branch 'master' into feature/docker
3ce6d8b
Merge branch 'main' into feature/docker
165a738
Use testcontainers to start docker containers when reunning intergrat…
ea529d6
Restore gitignore
d0cafc1
Fix failing integration tests
c68e298
Add possibility to override appsettings with env vars to enable local…
1035bd3
Fix the Firebird connection string, and add it to the containers list
4e0475e
Merge branch 'main' into feature/docker
16ee77f
Use the same version as the other packages
0802c3a
Update Testcontainers dependencies
a008a4a
Add missing dependabot dependencies
162c3c8
Merge branch 'main' into feature/docker
jzabroski d4d30ca
Merge branch 'main' into feature/docker
jzabroski d305c73
Merge branch 'main' into feature/docker
PhenX 7fd856c
Change Firebird tests to use the original connection string with Docker
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| #region License | ||
| // Copyright (c) 2024, Fluent Migrator Project | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| #endregion | ||
|
|
||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
|
|
||
| using DotNet.Testcontainers.Containers; | ||
|
|
||
| namespace FluentMigrator.Tests.Containers; | ||
|
|
||
| public abstract class ContainerBase | ||
| { | ||
| /// <summary> | ||
| /// Server options | ||
| /// </summary> | ||
| protected abstract IntegrationTestOptions.DatabaseServerOptions ServerOptions { get; } | ||
|
|
||
| /// <summary> | ||
| /// Default container database port | ||
| /// </summary> | ||
| protected abstract int Port { get; } | ||
|
|
||
| /// <summary> | ||
| /// Builds the test-container container | ||
| /// </summary> | ||
| protected abstract DockerContainer Build(); | ||
|
|
||
| public async Task Start(CancellationToken cancellationToken = default) | ||
| { | ||
| if (!ServerOptions.IsEnabled || !ServerOptions.ContainerEnabled) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| // Build containers | ||
| var container = Build(); | ||
|
|
||
| // Start it | ||
| await container.StartAsync(cancellationToken); | ||
|
|
||
| // Get the external port | ||
| var publicPort = container.GetMappedPublicPort(Port); | ||
| ServerOptions.ConnectionString = ServerOptions.ConnectionString.Replace(Port.ToString(), publicPort.ToString()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #region License | ||
| // Copyright (c) 2024, Fluent Migrator Project | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| #endregion | ||
|
|
||
| using DotNet.Testcontainers.Containers; | ||
|
|
||
| using Testcontainers.Db2; | ||
|
|
||
| namespace FluentMigrator.Tests.Containers; | ||
|
|
||
| public class Db2Container : ContainerBase | ||
| { | ||
| /// <inheritdoc /> | ||
| protected override IntegrationTestOptions.DatabaseServerOptions ServerOptions => IntegrationTestOptions.Db2; | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override int Port => 50000; | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override DockerContainer Build() => new Db2Builder().WithAcceptLicenseAgreement(true).WithReuse(true).Build(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #region License | ||
| // Copyright (c) 2024, Fluent Migrator Project | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| #endregion | ||
|
|
||
| using DotNet.Testcontainers.Containers; | ||
|
|
||
| using Testcontainers.FirebirdSql; | ||
|
|
||
| namespace FluentMigrator.Tests.Containers; | ||
|
|
||
| public class FirebirdContainer : ContainerBase | ||
| { | ||
| /// <inheritdoc /> | ||
| protected override IntegrationTestOptions.DatabaseServerOptions ServerOptions => IntegrationTestOptions.Firebird; | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override int Port => 3050; | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override DockerContainer Build() => new FirebirdSqlBuilder().WithReuse(true).Build(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #region License | ||
| // Copyright (c) 2024, Fluent Migrator Project | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| #endregion | ||
|
|
||
| using DotNet.Testcontainers.Containers; | ||
|
|
||
| using Testcontainers.MySql; | ||
|
|
||
| namespace FluentMigrator.Tests.Containers; | ||
|
|
||
| public class MySqlContainer : ContainerBase | ||
| { | ||
| /// <inheritdoc /> | ||
| protected override IntegrationTestOptions.DatabaseServerOptions ServerOptions => IntegrationTestOptions.MySql; | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override int Port => 3306; | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override DockerContainer Build() => new MySqlBuilder().WithReuse(true).Build(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #region License | ||
| // Copyright (c) 2024, Fluent Migrator Project | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| #endregion | ||
|
|
||
| using DotNet.Testcontainers.Containers; | ||
|
|
||
| using Testcontainers.Oracle; | ||
|
|
||
| namespace FluentMigrator.Tests.Containers; | ||
|
|
||
| public class OracleContainer : ContainerBase | ||
| { | ||
| /// <inheritdoc /> | ||
| protected override IntegrationTestOptions.DatabaseServerOptions ServerOptions => IntegrationTestOptions.Oracle; | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override int Port => 1521; | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override DockerContainer Build() => new OracleBuilder().WithReuse(true).Build(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #region License | ||
| // Copyright (c) 2024, Fluent Migrator Project | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| #endregion | ||
|
|
||
| using DotNet.Testcontainers.Containers; | ||
|
|
||
| using Testcontainers.PostgreSql; | ||
|
|
||
| namespace FluentMigrator.Tests.Containers; | ||
|
|
||
| public class PostgresContainer : ContainerBase | ||
| { | ||
| /// <inheritdoc /> | ||
| protected override IntegrationTestOptions.DatabaseServerOptions ServerOptions => IntegrationTestOptions.Postgres; | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override int Port => 5432; | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override DockerContainer Build() => new PostgreSqlBuilder().WithReuse(true).Build(); | ||
| } |
33 changes: 33 additions & 0 deletions
33
test/FluentMigrator.Tests/Containers/SqlServerContainer.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #region License | ||
| // Copyright (c) 2024, Fluent Migrator Project | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| #endregion | ||
|
|
||
| using DotNet.Testcontainers.Containers; | ||
|
|
||
| using Testcontainers.MsSql; | ||
|
|
||
| namespace FluentMigrator.Tests.Containers; | ||
|
|
||
| public class SqlServerContainer : ContainerBase | ||
| { | ||
| /// <inheritdoc /> | ||
| protected override IntegrationTestOptions.DatabaseServerOptions ServerOptions => IntegrationTestOptions.SqlServer2016; | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override int Port => 1433; | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override DockerContainer Build() => new MsSqlBuilder().WithReuse(true).Build(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
test/FluentMigrator.Tests/Integration/IntegrationTestsSetup.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| #region License | ||
| // | ||
| // Copyright (c) 2007-2024, Fluent Migrator Project | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
| #endregion | ||
|
|
||
| using System.Threading.Tasks; | ||
|
|
||
| using FluentMigrator.Tests.Containers; | ||
|
|
||
| using NUnit.Framework; | ||
|
|
||
| namespace FluentMigrator.Tests.Integration | ||
| { | ||
| [SetUpFixture] | ||
| public class IntegrationTestsSetup | ||
| { | ||
| [OneTimeSetUp] | ||
| public async Task Setup() | ||
| { | ||
| await Task.WhenAll([ | ||
|
jzabroski marked this conversation as resolved.
|
||
| new MySqlContainer().Start(), | ||
|
jzabroski marked this conversation as resolved.
|
||
| new OracleContainer().Start(), | ||
| new SqlServerContainer().Start(), | ||
| new PostgresContainer().Start(), | ||
| new FirebirdContainer().Start(), | ||
| new Db2Container().Start(), | ||
| ]); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.