Skip to content

Commit c60ba3c

Browse files
committed
[WIP] Throw on JSONMessage error
TODO: Create new exception type that also has a "Code" property.
1 parent 2218693 commit c60ba3c

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/Testcontainers/Clients/TraceProgress.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ public void Report(JSONMessage value)
3737
_logger.LogError(value.ErrorMessage.TrimEnd());
3838
}
3939

40+
if (value.Error != null)
41+
{
42+
throw new Exception(value.Error.Message);
43+
}
44+
4045
#pragma warning restore CA1848, CA2254
4146
}
4247
}

tests/Testcontainers.Tests/Unit/Containers/Unix/TestcontainersContainerTest.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace DotNet.Testcontainers.Tests.Unit
55
using System.IO;
66
using System.Net;
77
using System.Net.Sockets;
8+
using System.Runtime.InteropServices;
89
using System.Text;
910
using System.Threading.Tasks;
1011
using DotNet.Testcontainers.Builders;
@@ -539,6 +540,21 @@ public async Task PullPolicyNever()
539540
await Assert.ThrowsAnyAsync<Exception>(() => container.StartAsync(TestContext.Current.CancellationToken))
540541
.ConfigureAwait(true);
541542
}
543+
544+
[Fact]
545+
public async Task NoMatchingManifest()
546+
{
547+
Assert.SkipWhen(RuntimeInformation.ProcessArchitecture == Architecture.X64, "Only relevant on non x64 architectures");
548+
549+
await using var container = new ContainerBuilder("alpine:3.1")
550+
.WithEntrypoint(CommonCommands.SleepInfinity)
551+
.WithImagePullPolicy(PullPolicy.Always)
552+
.Build();
553+
554+
var exception = await Assert.ThrowsAnyAsync<Exception>(() => container.StartAsync(TestContext.Current.CancellationToken))
555+
.ConfigureAwait(true);
556+
Assert.Contains("no matching manifest", exception.Message);
557+
}
542558
}
543559
}
544560
}

0 commit comments

Comments
 (0)