Skip to content
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

chore: Clean up DynamoDB module #774

Merged
merged 2 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/Testcontainers.DynamoDb/DynamoDbBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ private DynamoDbBuilder(DynamoDbConfiguration dockerResourceConfiguration)
/// <inheritdoc />
protected override DynamoDbConfiguration DockerResourceConfiguration { get; }


/// <inheritdoc />
public override DynamoDbContainer Build()
{
Expand All @@ -44,11 +43,8 @@ protected override DynamoDbBuilder Init()
return base.Init()
.WithImage(DynamoDbImage)
.WithPortBinding(DynamoDbPort, true)
.WithWaitStrategy(Wait.ForUnixContainer()
.UntilHttpRequestIsSucceeded(request: req =>
req.ForPath("/")
.ForStatusCode(HttpStatusCode.BadRequest)
.ForPort(DynamoDbPort)));
.WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(request =>
request.ForPath("/").ForPort(DynamoDbPort).ForStatusCode(HttpStatusCode.BadRequest)));
}

/// <inheritdoc />
Expand Down
6 changes: 3 additions & 3 deletions src/Testcontainers.DynamoDb/DynamoDbContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public DynamoDbContainer(DynamoDbConfiguration configuration, ILogger logger)
: base(configuration, logger)
{
}

/// <summary>
/// Gets the DynamoDB endpoint.
/// Gets the DynamoDb endpoint.
/// </summary>
/// <returns>The DynamoDB endpoint.</returns>
/// <returns>The DynamoDb endpoint.</returns>
public string GetEndpoint()
{
return new UriBuilder(Uri.UriSchemeHttp, Hostname, GetMappedPublicPort(DynamoDbBuilder.DynamoDbPort)).ToString();
Expand Down
22 changes: 11 additions & 11 deletions src/Testcontainers.DynamoDb/Testcontainers.DynamoDb.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2022.3.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(SolutionDir)src/Testcontainers/Testcontainers.csproj" />
</ItemGroup>
</Project>
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2022.3.1"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(SolutionDir)src/Testcontainers/Testcontainers.csproj"/>
</ItemGroup>
</Project>
7 changes: 2 additions & 5 deletions src/Testcontainers.DynamoDb/Usings.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
global using System;
global using System.Net;
global using Docker.DotNet.Models;
global using DotNet.Testcontainers;
global using DotNet.Testcontainers.Builders;
global using DotNet.Testcontainers.Configurations;
global using DotNet.Testcontainers.Containers;
global using JetBrains.Annotations;
global using Microsoft.Extensions.Logging;
global using System.Threading.Tasks;
global using System.Collections.Generic;
global using System.Net;
global using Microsoft.Extensions.Logging;
3 changes: 2 additions & 1 deletion src/Testcontainers.Minio/MinioBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ protected override MinioBuilder Init()
.WithCommand("server", "/data")
.WithUsername("minio")
.WithPassword(Guid.NewGuid().ToString("D"))
.WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(request => request.ForPath("/minio/health/ready").ForPort(MinioPort)));
.WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(request =>
request.ForPath("/minio/health/ready").ForPort(MinioPort)));
}

/// <inheritdoc />
Expand Down
1 change: 1 addition & 0 deletions tests/Testcontainers.DynamoDb.Tests/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
root = true
82 changes: 82 additions & 0 deletions tests/Testcontainers.DynamoDb.Tests/DynamoDbContainerTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
namespace Testcontainers.DynamoDb;

public sealed class DynamoDbContainerTest : IAsyncLifetime
{
private readonly DynamoDbContainer _dynamoDbContainer = new DynamoDbBuilder().Build();

static DynamoDbContainerTest()
{
Environment.SetEnvironmentVariable("AWS_ACCESS_KEY_ID", "AKIAIOSFODNN7EXAMPLE");
Environment.SetEnvironmentVariable("AWS_SECRET_ACCESS_KEY", "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY");
}

public Task InitializeAsync()
{
return _dynamoDbContainer.StartAsync();
}

public Task DisposeAsync()
{
return _dynamoDbContainer.DisposeAsync().AsTask();
}

[Fact]
[Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))]
public async Task ListBucketsReturnsHttpStatusCodeOk()
{
// Given
var config = new AmazonDynamoDBConfig();
config.ServiceURL = _dynamoDbContainer.GetEndpoint();

var client = new AmazonDynamoDBClient(config);

// When
var tables = await client.ListTablesAsync()
.ConfigureAwait(false);

// Then
Assert.Equal(HttpStatusCode.OK, tables.HttpStatusCode);
}

[Fact]
[Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))]
public async Task GetItemReturnsPutItem()
{
// Given
var id = Guid.NewGuid().ToString("D");

var tableName = Guid.NewGuid().ToString("D");

var config = new AmazonDynamoDBConfig();
config.ServiceURL = _dynamoDbContainer.GetEndpoint();

var client = new AmazonDynamoDBClient(config);

var tableRequest = new CreateTableRequest();
tableRequest.TableName = tableName;
tableRequest.AttributeDefinitions = new List<AttributeDefinition> { new AttributeDefinition("Id", ScalarAttributeType.S) };
tableRequest.KeySchema = new List<KeySchemaElement> { new KeySchemaElement("Id", KeyType.HASH) };
tableRequest.ProvisionedThroughput = new ProvisionedThroughput(10, 5);

var putItemRequest = new PutItemRequest();
putItemRequest.TableName = tableName;
putItemRequest.Item = new Dictionary<string, AttributeValue> { { "Id", new AttributeValue { S = id } } };

var getItemRequest = new GetItemRequest();
getItemRequest.TableName = tableName;
getItemRequest.Key = new Dictionary<string, AttributeValue> { { "Id", new AttributeValue { S = id } } };

// When
_ = await client.CreateTableAsync(tableRequest)
.ConfigureAwait(false);

_ = await client.PutItemAsync(putItemRequest)
.ConfigureAwait(false);

var itemResponse = await client.GetItemAsync(getItemRequest)
.ConfigureAwait(false);

// Then
Assert.Equal(id, itemResponse.Item.Values.Single().S);
}
}
81 changes: 0 additions & 81 deletions tests/Testcontainers.DynamoDb.Tests/DynamoDbContainerTests.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<IsPublishable>false</IsPublishable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.101.42" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="coverlet.msbuild" Version="3.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
<PackageReference Include="xunit" Version="2.4.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(SolutionDir)src/Testcontainers.DynamoDb/Testcontainers.DynamoDb.csproj" />
<ProjectReference Include="$(SolutionDir)tests/Testcontainers.Commons/Testcontainers.Commons.csproj" />
</ItemGroup>
</Project>
<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<IsPublishable>false</IsPublishable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1"/>
<PackageReference Include="coverlet.msbuild" Version="3.2.0"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"/>
<PackageReference Include="xunit" Version="2.4.2"/>
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.101.42"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(SolutionDir)src/Testcontainers.DynamoDb/Testcontainers.DynamoDb.csproj"/>
<ProjectReference Include="$(SolutionDir)tests/Testcontainers.Commons/Testcontainers.Commons.csproj"/>
</ItemGroup>
</Project>
5 changes: 2 additions & 3 deletions tests/Testcontainers.DynamoDb.Tests/Usings.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
global using System;
global using System.Collections.Generic;
global using System.IO;
global using System.Linq;
global using System.Net;
global using System.Threading.Tasks;
global using Amazon.DynamoDBv2;
global using Amazon.DynamoDBv2.Model;
global using Amazon.Runtime;
global using DotNet.Testcontainers.Commons;
global using Xunit;
global using Xunit;