Skip to content

Commit 6d14e11

Browse files
committed
fix test container for google
1 parent 709a610 commit 6d14e11

8 files changed

Lines changed: 28 additions & 17 deletions

File tree

ManagedCode.Storage.Tests/Storages/GCS/GCSBlobTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace ManagedCode.Storage.Tests.Storages.GCS;
88

9-
[Collection("Google")]
9+
1010
public class GCSBlobTests : BlobTests<GCSContainer>
1111
{
1212
protected override GCSContainer Build()

ManagedCode.Storage.Tests/Storages/GCS/GCSConfigTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace ManagedCode.Storage.Tests.Storages.GCS;
1313

14-
[Collection("Google")]
14+
1515
public class GCSConfigTests
1616
{
1717
[Fact]

ManagedCode.Storage.Tests/Storages/GCS/GCSConfigurator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace ManagedCode.Storage.Tests.Storages.GCS;
88

9-
[Collection("Google")]
9+
1010
public class GCSConfigurator
1111
{
1212
public static ServiceProvider ConfigureServices(string connectionString)

ManagedCode.Storage.Tests/Storages/GCS/GCSContainerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace ManagedCode.Storage.Tests.Storages.GCS;
66

7-
[Collection("Google")]
7+
88
public class GCSContainerTests : ContainerTests<GCSContainer>
99
{
1010
protected override GCSContainer Build()

ManagedCode.Storage.Tests/Storages/GCS/GCSDownloadTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace ManagedCode.Storage.Tests.Storages.GCS;
66

7-
[Collection("Google")]
7+
88
public class GCSDownloadTests : DownloadTests<GCSContainer>
99
{
1010
protected override GCSContainer Build()

ManagedCode.Storage.Tests/Storages/GCS/GCSUploadTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace ManagedCode.Storage.Tests.Storages.GCS;
66

7-
[Collection("Google")]
7+
88
public class GCSUploadTests : UploadTests<GCSContainer>
99
{
1010
protected override GCSContainer Build()

TestcontainersGCS/GCSBuilder.cs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
using System.Text;
2+
using System.Text.RegularExpressions;
3+
14
namespace TestcontainersGCS;
25

36
/// <inheritdoc cref="ContainerBuilder{TBuilderEntity, TContainerEntity, TConfigurationEntity}" />
47
[PublicAPI]
58
public sealed class GCSBuilder : ContainerBuilder<GCSBuilder, GCSContainer, GCSConfiguration>
69
{
7-
public const string GCSImage = "fsouza/fake-gcs-server:1.47.5";
8-
public const ushort GCSPort = 30000;
10+
public const string FakeGCSServerImage = "fsouza/fake-gcs-server:1.47.5";
11+
public const ushort FakeGCSServerPort = 4443;
12+
public const string StartupScriptFilePath = "/testcontainers.sh";
913

1014
/// <summary>
1115
/// Initializes a new instance of the <see cref="GCSBuilder" /> class.
@@ -40,14 +44,21 @@ public override GCSContainer Build()
4044
protected override GCSBuilder Init()
4145
{
4246
return base.Init()
43-
.WithImage(GCSImage)
44-
.WithPortBinding(GCSPort, GCSPort)
45-
.WithCommand("-scheme", "http")
46-
.WithCommand("-backend", "memory")
47-
.WithCommand("-external-url", $"http://localhost:{GCSPort}")
48-
.WithCommand("-port", $"{GCSPort}")
49-
.WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(request =>
50-
request.ForPath("/").ForPort(GCSPort).ForStatusCode(HttpStatusCode.NotFound)));
47+
.WithImage(FakeGCSServerImage)
48+
.WithPortBinding(FakeGCSServerPort, true)
49+
.WithEntrypoint("/bin/sh", "-c")
50+
.WithCommand($"while [ ! -f {StartupScriptFilePath} ]; do sleep 0.1; done; sh {StartupScriptFilePath}")
51+
.WithWaitStrategy(Wait.ForUnixContainer().UntilMessageIsLogged(new Regex("server started at.*", RegexOptions.IgnoreCase)))
52+
.WithStartupCallback((container, ct) =>
53+
{
54+
const char lf = '\n';
55+
var startupScript = new StringBuilder();
56+
startupScript.Append("#!/bin/bash");
57+
startupScript.Append(lf);
58+
startupScript.Append($"fake-gcs-server -backend memory -scheme http -port {FakeGCSServerPort} -external-url \"http://localhost:{container.GetMappedPublicPort(FakeGCSServerPort)}\"");
59+
startupScript.Append(lf);
60+
return container.CopyAsync(Encoding.Default.GetBytes(startupScript.ToString()), StartupScriptFilePath, Unix.FileMode755, ct);
61+
});
5162
}
5263

5364
/// <inheritdoc />

TestcontainersGCS/GCSContainer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public GCSContainer(GCSConfiguration configuration, ILogger logger)
2020
/// <returns>The GCS connection string.</returns>
2121
public string GetConnectionString()
2222
{
23-
var builder = new UriBuilder(Uri.UriSchemeHttp, Hostname, GetMappedPublicPort(GCSBuilder.GCSPort), "storage/v1/");
23+
var builder = new UriBuilder(Uri.UriSchemeHttp, Hostname, GetMappedPublicPort(GCSBuilder.FakeGCSServerPort), "storage/v1/");
2424
return builder.ToString();
2525
}
2626
}

0 commit comments

Comments
 (0)