Skip to content

Commit

Permalink
fix: Remove traling slash (fixes NotFound)
Browse files Browse the repository at this point in the history
  • Loading branch information
HofmeisterAn committed Oct 17, 2023
1 parent 0d62034 commit e339e4a
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 58 deletions.
28 changes: 14 additions & 14 deletions Testcontainers.sln
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Elasticsearc
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.EventStoreDb", "src\Testcontainers.EventStoreDb\Testcontainers.EventStoreDb.csproj", "{84D707E0-C9FA-4327-85DC-0AFEBEA73572}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.FakeGcsServer", "src\Testcontainers.FakeGcsServer\Testcontainers.FakeGcsServer.csproj", "{FF86B509-2F9E-4269-ABC2-912B3339DE29}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Firestore", "src\Testcontainers.Firestore\Testcontainers.Firestore.csproj", "{B3CC460D-0DFD-48A8-9502-54E9828B7B05}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.InfluxDb", "src\Testcontainers.InfluxDb\Testcontainers.InfluxDb.csproj", "{8F483B83-7BD4-4BD5-9F03-DFC26E1CE678}"
Expand Down Expand Up @@ -97,6 +99,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Elasticsearc
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.EventStoreDb.Tests", "tests\Testcontainers.EventStoreDb.Tests\Testcontainers.EventStoreDb.Tests.csproj", "{64F8E9B9-78FD-4E13-BDDF-0340E2D4E1D0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.FakeGcsServer.Tests", "tests\Testcontainers.FakeGcsServer.Tests\Testcontainers.FakeGcsServer.Tests.csproj", "{9F27AA1B-C25D-400C-BCB0-6B0BF1A1DCEA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Firestore.Tests", "tests\Testcontainers.Firestore.Tests\Testcontainers.Firestore.Tests.csproj", "{2F0D7CD6-7EA9-46FC-B8F2-25D55699525F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.InfluxDb.Tests", "tests\Testcontainers.InfluxDb.Tests\Testcontainers.InfluxDb.Tests.csproj", "{B45B0EF2-5852-4ED3-904A-8FC62A3253D7}"
Expand Down Expand Up @@ -151,10 +155,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Tests", "tes
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.WebDriver.Tests", "tests\Testcontainers.WebDriver.Tests\Testcontainers.WebDriver.Tests.csproj", "{EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.FakeGcsServer", "src\Testcontainers.FakeGcsServer\Testcontainers.FakeGcsServer.csproj", "{FF86B509-2F9E-4269-ABC2-912B3339DE29}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.FakeGcsServer.Tests", "tests\Testcontainers.FakeGcsServer.Tests\Testcontainers.FakeGcsServer.Tests.csproj", "{9F27AA1B-C25D-400C-BCB0-6B0BF1A1DCEA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -196,6 +196,10 @@ Global
{84D707E0-C9FA-4327-85DC-0AFEBEA73572}.Debug|Any CPU.Build.0 = Debug|Any CPU
{84D707E0-C9FA-4327-85DC-0AFEBEA73572}.Release|Any CPU.ActiveCfg = Release|Any CPU
{84D707E0-C9FA-4327-85DC-0AFEBEA73572}.Release|Any CPU.Build.0 = Release|Any CPU
{FF86B509-2F9E-4269-ABC2-912B3339DE29}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FF86B509-2F9E-4269-ABC2-912B3339DE29}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FF86B509-2F9E-4269-ABC2-912B3339DE29}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FF86B509-2F9E-4269-ABC2-912B3339DE29}.Release|Any CPU.Build.0 = Release|Any CPU
{B3CC460D-0DFD-48A8-9502-54E9828B7B05}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B3CC460D-0DFD-48A8-9502-54E9828B7B05}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B3CC460D-0DFD-48A8-9502-54E9828B7B05}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -332,6 +336,10 @@ Global
{64F8E9B9-78FD-4E13-BDDF-0340E2D4E1D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{64F8E9B9-78FD-4E13-BDDF-0340E2D4E1D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{64F8E9B9-78FD-4E13-BDDF-0340E2D4E1D0}.Release|Any CPU.Build.0 = Release|Any CPU
{9F27AA1B-C25D-400C-BCB0-6B0BF1A1DCEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9F27AA1B-C25D-400C-BCB0-6B0BF1A1DCEA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9F27AA1B-C25D-400C-BCB0-6B0BF1A1DCEA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9F27AA1B-C25D-400C-BCB0-6B0BF1A1DCEA}.Release|Any CPU.Build.0 = Release|Any CPU
{2F0D7CD6-7EA9-46FC-B8F2-25D55699525F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2F0D7CD6-7EA9-46FC-B8F2-25D55699525F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2F0D7CD6-7EA9-46FC-B8F2-25D55699525F}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -440,14 +448,6 @@ Global
{EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}.Release|Any CPU.Build.0 = Release|Any CPU
{FF86B509-2F9E-4269-ABC2-912B3339DE29}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FF86B509-2F9E-4269-ABC2-912B3339DE29}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FF86B509-2F9E-4269-ABC2-912B3339DE29}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FF86B509-2F9E-4269-ABC2-912B3339DE29}.Release|Any CPU.Build.0 = Release|Any CPU
{9F27AA1B-C25D-400C-BCB0-6B0BF1A1DCEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9F27AA1B-C25D-400C-BCB0-6B0BF1A1DCEA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9F27AA1B-C25D-400C-BCB0-6B0BF1A1DCEA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9F27AA1B-C25D-400C-BCB0-6B0BF1A1DCEA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{3F2E254F-C203-43FD-A078-DC3E2CBC0F9F} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
Expand All @@ -458,6 +458,7 @@ Global
{2EAFA567-9F68-4C52-9DBC-8F3EC11BB2CE} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{641DDEA5-B6E0-41E6-BA11-7A28C0913127} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{84D707E0-C9FA-4327-85DC-0AFEBEA73572} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{FF86B509-2F9E-4269-ABC2-912B3339DE29} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{B3CC460D-0DFD-48A8-9502-54E9828B7B05} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{8F483B83-7BD4-4BD5-9F03-DFC26E1CE678} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{111B840F-9DB0-4166-83E6-0580FD418F07} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
Expand Down Expand Up @@ -492,6 +493,7 @@ Global
{101515E6-74C1-40F9-85C8-871F742A378D} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{DD5B3678-468F-4D73-AECE-705E3D66CD43} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{64F8E9B9-78FD-4E13-BDDF-0340E2D4E1D0} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{9F27AA1B-C25D-400C-BCB0-6B0BF1A1DCEA} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{2F0D7CD6-7EA9-46FC-B8F2-25D55699525F} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{B45B0EF2-5852-4ED3-904A-8FC62A3253D7} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{F0F40AE2-70FF-4191-ADDA-26A19E0D1A0F} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
Expand Down Expand Up @@ -519,7 +521,5 @@ Global
{1A1983E6-5297-435F-B467-E8E1F11277D6} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{27CDB869-A150-4593-958F-6F26E5391E7C} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{FF86B509-2F9E-4269-ABC2-912B3339DE29} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{9F27AA1B-C25D-400C-BCB0-6B0BF1A1DCEA} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
EndGlobalSection
EndGlobal
21 changes: 14 additions & 7 deletions src/Testcontainers.FakeGcsServer/FakeGcsServerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ namespace Testcontainers.FakeGcsServer;
public sealed class FakeGcsServerBuilder : ContainerBuilder<FakeGcsServerBuilder, FakeGcsServerContainer, FakeGcsServerConfiguration>
{
public const string FakeGcsServerImage = "fsouza/fake-gcs-server:1.47.5";
public const ushort FakeGcsServerPort = 8080;

public const ushort FakeGcsServerPort = 4443;

public const string StartupScriptFilePath = "/testcontainers.sh";

/// <summary>
Expand Down Expand Up @@ -44,28 +46,33 @@ protected override FakeGcsServerBuilder Init()
.WithImage(FakeGcsServerImage)
.WithPortBinding(FakeGcsServerPort, true)
.WithEntrypoint("/bin/sh", "-c")
.WithCommand($"while [ ! -f {StartupScriptFilePath} ]; do sleep 0.1; done; sh {StartupScriptFilePath}")
.WithWaitStrategy(Wait.ForUnixContainer().UntilMessageIsLogged(new Regex("server started at.*", RegexOptions.IgnoreCase)))
.WithCommand("while [ ! -f " + StartupScriptFilePath + " ]; do sleep 0.1; done; /bin/sh " + StartupScriptFilePath)
.WithWaitStrategy(Wait.ForUnixContainer().UntilMessageIsLogged("server started"))
.WithStartupCallback((container, ct) =>
{
const char lf = '\n';
var startupScript = new StringBuilder();
startupScript.Append("#!/bin/bash");
startupScript.Append(lf);
startupScript.Append($"fake-gcs-server -backend memory -scheme http -port {FakeGcsServerPort} -external-url {new UriBuilder(Uri.UriSchemeHttp, container.Hostname, container.GetMappedPublicPort(FakeGcsServerPort))}");
startupScript.Append(lf);
startupScript.Append("fake-gcs-server ");
startupScript.Append("-backend memory ");
startupScript.Append("-scheme http ");
// If we do not remove the trailing slash, uploading an object will result in an
// error: HttpStatusCode.NotFound. The HTTP request appears incorrect. The
// container logs indicate the presence of an extra slash: `PUT //upload/storage/v1`.
startupScript.Append("-external-url " + new UriBuilder(Uri.UriSchemeHttp, container.Hostname, container.GetMappedPublicPort(FakeGcsServerPort)).ToString().Trim('/'));
return container.CopyAsync(Encoding.Default.GetBytes(startupScript.ToString()), StartupScriptFilePath, Unix.FileMode755, ct);
});
}

/// <inheritdoc />
protected override FakeGcsServerBuilder Clone(IContainerConfiguration resourceConfiguration)
protected override FakeGcsServerBuilder Clone(IResourceConfiguration<CreateContainerParameters> resourceConfiguration)
{
return Merge(DockerResourceConfiguration, new FakeGcsServerConfiguration(resourceConfiguration));
}

/// <inheritdoc />
protected override FakeGcsServerBuilder Clone(IResourceConfiguration<CreateContainerParameters> resourceConfiguration)
protected override FakeGcsServerBuilder Clone(IContainerConfiguration resourceConfiguration)
{
return Merge(DockerResourceConfiguration, new FakeGcsServerConfiguration(resourceConfiguration));
}
Expand Down
3 changes: 1 addition & 2 deletions src/Testcontainers.FakeGcsServer/FakeGcsServerContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public FakeGcsServerContainer(FakeGcsServerConfiguration configuration, ILogger
/// <returns>The FakeGcsServer connection string.</returns>
public string GetConnectionString()
{
var builder = new UriBuilder(Uri.UriSchemeHttp, Hostname, GetMappedPublicPort(FakeGcsServerBuilder.FakeGcsServerPort), "storage/v1/");
return builder.ToString();
return new UriBuilder(Uri.UriSchemeHttp, Hostname, GetMappedPublicPort(FakeGcsServerBuilder.FakeGcsServerPort), "/storage/v1/").ToString();
}
}
6 changes: 2 additions & 4 deletions src/Testcontainers.FakeGcsServer/Usings.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
global using System;
global using System.Net;
global using System.Text;
global using Docker.DotNet.Models;
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.Text;
global using System.Text.RegularExpressions;
global using Microsoft.Extensions.Logging;
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
using System.Text;
using System.IO;

namespace Testcontainers.FakeGcsServer;

public abstract class FakeGcsServerContainerTest : IAsyncLifetime
{
private readonly FakeGcsServerContainer _FakeGcsServerContainer = new FakeGcsServerBuilder().Build();
private readonly FakeGcsServerContainer _fakeGcsServerContainer = new FakeGcsServerBuilder().Build();

public Task InitializeAsync()
{
return _FakeGcsServerContainer.StartAsync();
return _fakeGcsServerContainer.StartAsync();
}

public Task DisposeAsync()
{
return _FakeGcsServerContainer.DisposeAsync().AsTask();
return _fakeGcsServerContainer.DisposeAsync().AsTask();
}

public sealed class BlobService : FakeGcsServerContainerTest
Expand All @@ -23,27 +20,38 @@ public sealed class BlobService : FakeGcsServerContainerTest
[Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))]
public async Task EstablishesConnection()
{
string testProject = "test-project";
string testBucket = "test-bucket";
string content = "Hello Google Storage";
string fileName = "hello.txt";

// Give
var client = await new StorageClientBuilder
{
UnauthenticatedAccess = true,
BaseUri = _FakeGcsServerContainer.GetConnectionString()
}.BuildAsync();

// Given
const string helloWorld = "Hello, World!";

using var writeStream = new MemoryStream(Encoding.Default.GetBytes(helloWorld));

using var readStream = new MemoryStream();

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

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

var fileName = Path.GetRandomFileName();

var storageClientBuilder = new StorageClientBuilder();
storageClientBuilder.UnauthenticatedAccess = true;
storageClientBuilder.BaseUri = _fakeGcsServerContainer.GetConnectionString();

// When
await client.CreateBucketAsync(testProject, testBucket);
await client.UploadObjectAsync(testBucket, fileName, "text/plain", new MemoryStream(Encoding.UTF8.GetBytes(content)));
using var ms = new MemoryStream();
await client.DownloadObjectAsync(testBucket, fileName, ms);
var blobContent = Encoding.UTF8.GetString(ms.ToArray());
var client = await storageClientBuilder.BuildAsync()
.ConfigureAwait(false);

_ = await client.CreateBucketAsync(project, bucket)
.ConfigureAwait(false);

_ = await client.UploadObjectAsync(bucket, fileName, "text/plain", writeStream)
.ConfigureAwait(false);

_ = await client.DownloadObjectAsync(bucket, fileName, readStream)
.ConfigureAwait(false);

// Then
Assert.Equal(content, blobContent);
Assert.Equal(helloWorld, Encoding.Default.GetString(readStream.ToArray()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0"/>
<PackageReference Include="xunit" Version="2.5.0"/>
<PackageReference Include="Google.Api.Gax" Version="4.4.0" />
<PackageReference Include="Google.Api.Gax.Rest" Version="4.4.0" />
<PackageReference Include="Google.Apis.Storage.v1" Version="1.62.1.3190" />
<PackageReference Include="Google.Cloud.Storage.V1" Version="4.6.0" />
<PackageReference Include="Google.Cloud.Storage.V1" Version="4.6.0"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Testcontainers.FakeGcsServer\Testcontainers.FakeGcsServer.csproj" />
<ProjectReference Include="$(SolutionDir)src/Testcontainers.FakeGcsServer/Testcontainers.FakeGcsServer.csproj"/>
<ProjectReference Include="$(SolutionDir)tests/Testcontainers.Commons/Testcontainers.Commons.csproj"/>
</ItemGroup>
</Project>
5 changes: 3 additions & 2 deletions tests/Testcontainers.FakeGcsServer.Tests/Usings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
global using System;
global using System.IO;
global using System.Text;
global using System.Threading.Tasks;
global using DotNet.Testcontainers.Commons;
global using System.Linq;
global using Google.Cloud.Storage.V1;
global using Testcontainers.FakeGcsServer;
global using Xunit;

0 comments on commit e339e4a

Please sign in to comment.