Skip to content

Commit 745856e

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

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
@@ -55,6 +55,11 @@ public void Report(JSONMessage value)
5555
{
5656
_logger.LogDebug("Auxiliary data: {ExtensionData}", JsonSerializer.Serialize(value.Aux.ExtensionData));
5757
}
58+
59+
if (value.Error != null)
60+
{
61+
throw new Exception(value.Error.Message);
62+
}
5863
}
5964
}
6065
}

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;
@@ -545,6 +546,21 @@ public async Task PullPolicyNever()
545546
await Assert.ThrowsAnyAsync<Exception>(() => container.StartAsync(TestContext.Current.CancellationToken))
546547
.ConfigureAwait(true);
547548
}
549+
550+
[Fact]
551+
public async Task NoMatchingManifest()
552+
{
553+
Assert.SkipWhen(RuntimeInformation.ProcessArchitecture == Architecture.X64, "Only relevant on non x64 architectures");
554+
555+
await using var container = new ContainerBuilder("alpine:3.1")
556+
.WithEntrypoint(CommonCommands.SleepInfinity)
557+
.WithImagePullPolicy(PullPolicy.Always)
558+
.Build();
559+
560+
var exception = await Assert.ThrowsAnyAsync<Exception>(() => container.StartAsync(TestContext.Current.CancellationToken))
561+
.ConfigureAwait(true);
562+
Assert.Contains("no matching manifest", exception.Message);
563+
}
548564
}
549565
}
550566
}

0 commit comments

Comments
 (0)