Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…iners-dotnet into feature/cosmosdb-testcontainer
  • Loading branch information
Yeseh committed Aug 28, 2022
2 parents 6d0ae41 + 596b14e commit c3809a4
Show file tree
Hide file tree
Showing 92 changed files with 2,020 additions and 175 deletions.
11 changes: 0 additions & 11 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -455,17 +455,6 @@ dotnet_naming_rule.parameters_rule.severity = warning

max_line_length = 240

dotnet_diagnostic.SA0001.severity = none
dotnet_diagnostic.SA1600.severity = none
dotnet_diagnostic.SA1633.severity = none

##########################################
# JetBrains Rider
##########################################

resharper_arrange_object_creation_when_type_evident_highlighting = do_not_show
resharper_convert_to_using_declaration_highlighting = do_not_show

##########################################
# Testcontainers.Tests
##########################################
Expand Down
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- [ ] `CHANGELOG.md` is up-to-date
7 changes: 4 additions & 3 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ env:
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_NOLOGO: true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_VERSION: 6.0.x
TZ: CET # https://stackoverflow.com/q/53510011

jobs:
Expand All @@ -37,8 +36,6 @@ jobs:

- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Restore .NET Tools
run: dotnet tool restore
Expand All @@ -55,6 +52,7 @@ jobs:
- name: Get Logs
run: Get-ChildItem -Path . -Include *.log -Recurse | % { Get-Content -Path $_.FullName }
shell: pwsh
if: always()

- name: Rename Test And Coverage Results
run: Get-ChildItem -Path 'test-coverage' -Filter *.xml | Rename-Item -NewName { $_.Name -Replace 'coverage', '${{ matrix.os }}'.ToLower() }
Expand Down Expand Up @@ -109,6 +107,9 @@ jobs:
Get-ChildItem -Path 'test-coverage' -Filter *.xml | % { (Get-Content $_) -Replace '[A-Za-z0-9:\-\/\\]+tests', '${{ github.workspace }}/tests' | Set-Content $_ }
shell: pwsh

- name: Setup .NET
uses: actions/setup-dotnet@v2

- name: Restore .NET Tools
run: dotnet tool restore

Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,18 @@

### Added

- 421 Add Azurite module (@vlaskal)
- 504 Add Elasticsearch module (@chertby)
- 516 Add `ITestcontainersBuilder<TDockerContainer>.WithTmpfsMount` (@chrisbbe)
- 520 Add MariaDB module (@renemadsen)
- 528 Do not require the Docker host configuration (`DockerEndpointAuthConfig`) on `TestcontainersSettings` initialization
- 538 Support optional username and password in MongoDB connection string (@the-avid-engineer)
- 540 Add Docker registry authentication provider for `DOCKER_AUTH_CONFIG` environment variable (@vova-lantsov-dev)
- 541 Allow MsSqlTestcontainerConfiguration custom database names (@enginexon)

### Fixed

- 525 Read ServerURL, Username and Secret field from CredsStore response to pull private Docker images

## [2.1.0]

Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<AssemblyVersion>$(Version)</AssemblyVersion>
<FileVersion>$(Version)</FileVersion>
<Product>Testcontainers</Product>
<Copyright>Copyright (c) 2019 - 2021 Andre Hofmeister and other authors</Copyright>
<Copyright>Copyright (c) 2019 - 2022 Andre Hofmeister and other authors</Copyright>
<Authors>Andre Hofmeister and contributors</Authors>
<Company>Andre Hofmeister</Company>
<Description>A lightweight library to run tests with throwaway instances of Docker containers.</Description>
Expand Down
20 changes: 12 additions & 8 deletions Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,28 @@
<PackageReference Update="Microsoft.Extensions.Hosting" Version="3.1.23" />
<PackageReference Update="coverlet.msbuild" Version="3.1.2" />
<PackageReference Update="FluentAssertions" Version="5.10.3" />
<PackageReference Update="Moq" Version="4.18.1" />
<PackageReference Update="Moq" Version="4.18.2" />
<PackageReference Update="Serilog.Extensions.Logging" Version="3.1.0" />
<PackageReference Update="Serilog.Settings.Configuration" Version="3.3.0" />
<PackageReference Update="Serilog.Sinks.Console" Version="4.0.1" />
<PackageReference Update="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Update="Serilog" Version="2.11.0" />
<PackageReference Update="xunit.runner.visualstudio" Version="2.4.5" />
<PackageReference Update="xunit" Version="2.4.1" />
<PackageReference Update="xunit" Version="2.4.2" />
<!-- 3rd party client dependencies -->
<PackageReference Update="Azure.Data.Tables" Version="12.6.1" />
<PackageReference Update="Azure.Storage.Blobs" Version="12.13.0" />
<PackageReference Update="Azure.Storage.Queues" Version="12.11.0" />
<PackageReference Update="Confluent.Kafka" Version="1.8.2" />
<PackageReference Update="CouchbaseNetClient" Version="3.2.8" />
<PackageReference Update="MongoDB.Driver" Version="2.15.0" />
<PackageReference Update="CouchbaseNetClient" Version="3.2.9" />
<PackageReference Update="Elastic.Clients.Elasticsearch" Version="8.0.0-beta.3" />
<PackageReference Update="MongoDB.Driver" Version="2.17.1" />
<PackageReference Update="MyCouch" Version="7.6.0" />
<PackageReference Update="MySql.Data" Version="8.0.28" />
<PackageReference Update="Npgsql" Version="6.0.3" />
<PackageReference Update="Oracle.ManagedDataAccess.Core" Version="3.21.50" />
<PackageReference Update="Npgsql" Version="6.0.6" />
<PackageReference Update="Oracle.ManagedDataAccess.Core" Version="3.21.61" />
<PackageReference Update="Pomelo.EntityFrameworkCore.MySql" Version="6.0.2" />
<PackageReference Update="RabbitMQ.Client" Version="6.2.4" />
<PackageReference Update="StackExchange.Redis" Version="2.5.43" />
<PackageReference Update="StackExchange.Redis" Version="2.6.48" />
<PackageReference Update="System.Data.SqlClient" Version="4.8.3" />
</ItemGroup>
</Project>
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Testcontainers is a library to support tests with throwaway instances of Docker

Choose from existing pre-configured configurations and start containers within a second, to support and run your tests. Or create your own containers with Dockerfiles and run your tests immediately afterward.

Get in touch with the Testcontainers team and others, and join our [Slack workspace][slack-workspace].

## Supported operating systems

Testcontainers supports Windows, Linux, and macOS as host systems. Linux Docker containers are supported on all three operating systems.
Expand All @@ -34,16 +36,18 @@ To configure a container, use the `TestcontainersBuilder<TestcontainersContainer
- `WithPortBinding` publishes the container port to the host e.g. `-p, --publish 80:80`.
- `WithBindMount` binds a path of a file or directory into the container e.g. `-v, --volume .:/tmp`.
- `WithVolumeMount` mounts a managed volume into the container e.g. `--mount type=volume,source=.,destination=/tmp`.
- `WithTmpfsMount` mounts a temporary volume into the container e.g. `--mount type=tmpfs,destination=/tmp`.
- `WithNetwork` assigns a network to the container e.g. `--network="bridge"`.
- `WithNetworkAliases` assigns a network-scoped aliases to the container e.g. `--network-alias alias`
- `WithAutoRemove` will remove the stopped container automatically like `--rm`.
- `WithCleanUp` will remove the container automatically after all tests have been run (see [Resource Reaper](#resource-reaper)).
- `WithPrivileged` sets the `--privileged` flag.
- `WithDockerEndpoint` sets the Docker API endpoint e.g. `-H tcp://0.0.0.0:2376`.
- `WithRegistryAuthentication` basic authentication against a private Docker registry.
- `WithOutputConsumer` redirects `stdout` and `stderr` to capture the container output.
- `WithWaitStrategy` sets the wait strategy to complete the container start and indicates when it is ready.
- `WithCreateContainerParametersModifier` allows low level modifications of the Docker container create parameter.
- `WithStartupCallback` sets the startup callback to invoke after the container start.
- `WithPrivileged` sets the `--privileged` flag.
- `WithAutoRemove` will remove the stopped container automatically like `--rm`.
- `WithCleanUp` will remove the container automatically after all tests have been run (see [Resource Reaper](#resource-reaper)).
- `WithResourceReaperSessionId` assigns a Resource Reaper session id to the container.

Use the additional builder for image (`ImageFromDockerfileBuilder`), network (`TestcontainersNetworkBuilder`) and volume (`TestcontainersVolumeBuilder`) to set up your individual test environment.
Expand All @@ -57,7 +61,10 @@ Testcontainers assigns each Docker resource a Resource Reaper session id. After
The pre-configured Testcontainers below are supported. Further examples can be found in [TestcontainersContainerTest][1] as well as in [database][2] or [message broker][3] tests.

- Apache CouchDB (couchdb:2.3.1)
- Azurite (mcr.microsoft.com/azure-storage/azurite:3.18.0)
- Couchbase (couchbase:6.5.1)
- Elasticsearch (elasticsearch:8.3.2)
- MariaDB (mariadb:10.8)
- Microsoft SQL Server (mcr.microsoft.com/mssql/server:2017-CU28-ubuntu-16.04)
- MongoDB (mongo:5.0.6)
- MySQL (mysql:8.0.28)
Expand Down Expand Up @@ -176,5 +183,6 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
[1]: https://github.com/testcontainers/testcontainers-dotnet/blob/develop/tests/Testcontainers.Tests/Unit/Containers/Unix/TestcontainersContainerTest.cs
[2]: https://github.com/testcontainers/testcontainers-dotnet/blob/develop/tests/Testcontainers.Tests/Unit/Containers/Unix/Modules/Databases
[3]: https://github.com/testcontainers/testcontainers-dotnet/blob/develop/tests/Testcontainers.Tests/Unit/Containers/Unix/Modules/MessageBrokers
[slack-workspace]: https://slack.testcontainers.org/
[moby-ryuk]: https://github.com/testcontainers/moby-ryuk
[xunit]: https://xunit.net
28 changes: 28 additions & 0 deletions Testcontainers.dic
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
azurecr
azurite
capi
creds
dvcm
enumerables
ghcr
httpd
identitytoken
initdb
isready
lipsum
ltsc
memopt
mycounter
mydatabase
myregistry
myregistryhost
nlcm
npipe
postgre
ramsize
rebalance
ryuk
servercore
sqlplus
testcontainer
testcontainers
42 changes: 42 additions & 0 deletions Testcontainers.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<wpf:ResourceDictionary xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xml:space="preserve">
<s:Boolean x:Key="/Default/CodeStyle/Naming/CSharpNaming/ApplyAutoDetectedRules/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=OS/@EntryIndexedValue">OS</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/TRAILING_COMMA_IN_MULTILINE_LISTS/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/NAMESPACE_BODY/@EntryValue">BlockScoped</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CSharpUsing/QualifiedUsingAtNestedScope/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/InstalledDictionaries/InstalledDictionaries/=Testcontainers_002Edic/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=azurecr/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=azurite/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=capi/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=creds/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=dockerignore/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=dvcm/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=enumerables/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ghcr/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=httpd/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=identitytoken/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=initdb/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=isready/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=lipsum/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ltsc/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=memopt/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=mycounter/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=mydatabase/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=myregistry/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=myregistryhost/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=nlcm/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=npipe/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=postgre/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ramsize/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=rebalance/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ryuk/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=servercore/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=sqlplus/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=testcontainer/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=testcontainers/@EntryIndexedValue">True</s:Boolean>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CheckNamespace/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertToUsingDeclaration/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseAwaitUsing/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeObjectCreationWhenTypeEvident/@EntryIndexedValue">DO_NOT_SHOW</s:String>
</wpf:ResourceDictionary>
2 changes: 1 addition & 1 deletion build.cake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#tool nuget:?package=dotnet-sonarscanner&version=5.7.1
#tool nuget:?package=dotnet-sonarscanner&version=5.7.2

#addin nuget:?package=Cake.Sonar&version=1.1.29

Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "6.0.300",
"version": "6.0.400",
"rollForward": "latestPatch"
}
}
14 changes: 1 addition & 13 deletions src/Testcontainers/Builders/CredsHelperProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,8 @@ public IDockerRegistryAuthenticationConfiguration GetAuthConfig(string hostname)
return null;
}

var username = credential.TryGetProperty("Username", out var usernameProperty) ? usernameProperty.GetString() : null;

var password = credential.TryGetProperty("Secret", out var passwordProperty) ? passwordProperty.GetString() : null;

this.logger.DockerRegistryCredentialFound(hostname);

if ("<token>".Equals(username, StringComparison.OrdinalIgnoreCase))
{
return new DockerRegistryAuthenticationConfiguration(hostname, null, null, password);
}
else
{
return new DockerRegistryAuthenticationConfiguration(hostname, username, password);
}
return new DockerRegistryAuthenticationConfiguration(hostname, credential);
}
}
}
14 changes: 3 additions & 11 deletions src/Testcontainers/Builders/CredsStoreProvider.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
namespace DotNet.Testcontainers.Builders
{
using System.Text.Json;
using Docker.DotNet.Models;
using DotNet.Testcontainers.Configurations;
using JetBrains.Annotations;
using Microsoft.Extensions.Logging;

/// <inheritdoc cref="IDockerEndpointAuthenticationProvider" />
internal sealed class CredsStoreProvider : IDockerRegistryAuthenticationProvider
{
private static readonly JsonSerializerOptions JsonSerializerOptions = new JsonSerializerOptions();

private readonly JsonElement rootElement;

private readonly ILogger logger;

static CredsStoreProvider()
{
JsonSerializerOptions.PropertyNameCaseInsensitive = true;
}

/// <summary>
/// Initializes a new instance of the <see cref="CredsStoreProvider" /> class.
/// </summary>
Expand Down Expand Up @@ -65,19 +57,19 @@ public IDockerRegistryAuthenticationConfiguration GetAuthConfig(string hostname)
return null;
}

AuthConfig authConfig;
JsonElement credential;

try
{
authConfig = JsonSerializer.Deserialize<AuthConfig>(JsonDocument.Parse(credentialProviderOutput).RootElement.GetRawText(), JsonSerializerOptions);
credential = JsonDocument.Parse(credentialProviderOutput).RootElement;
}
catch (JsonException)
{
return null;
}

this.logger.DockerRegistryCredentialFound(hostname);
return new DockerRegistryAuthenticationConfiguration(authConfig.ServerAddress, authConfig.Username, authConfig.Password);
return new DockerRegistryAuthenticationConfiguration(hostname, credential);
}
}
}
Loading

0 comments on commit c3809a4

Please sign in to comment.