public virtual async Task <bool> Until(ITestcontainersContainer testcontainers, ILogger logger) { var execResult = await testcontainers.ExecAsync(this.command) .ConfigureAwait(false); return(0L.Equals(execResult.ExitCode)); }
public async Task CopyFileToRunningContainer() { // Given const string dayOfWeekFilePath = "/tmp/dayOfWeek"; var dayOfWeek = DateTime.UtcNow.DayOfWeek.ToString(); var testcontainersBuilder = new TestcontainersBuilder <TestcontainersContainer>() .WithImage("alpine") .WithEntrypoint(KeepTestcontainersUpAndRunning.Command); // When // Then await using (ITestcontainersContainer testcontainer = testcontainersBuilder.Build()) { await testcontainer.StartAsync(); await testcontainer.CopyFileAsync(dayOfWeekFilePath, Encoding.Default.GetBytes(dayOfWeek)); Assert.Equal(0, (await testcontainer.ExecAsync(new[] { "/bin/sh", "-c", $"test \"$(cat {dayOfWeekFilePath})\" = \"{dayOfWeek}\"" })).ExitCode); Assert.Equal(0, (await testcontainer.ExecAsync(new[] { "/bin/sh", "-c", $"stat {dayOfWeekFilePath} | grep 0600" })).ExitCode); } }
public async Task ExecCommandInRunningContainerWithStderr() { // Given var testcontainersBuilder = new TestcontainersBuilder <TestcontainersContainer>() .WithImage("alpine") .WithEntrypoint(KeepTestcontainersUpAndRunning.Command); // When // Then await using (ITestcontainersContainer testcontainer = testcontainersBuilder.Build()) { await testcontainer.StartAsync(); var execResult = await testcontainer.ExecAsync(new[] { "/bin/sh", "-c", "cd missing_directory" }); Assert.Contains("can't cd to missing_directory", execResult.Stderr); } }
public async Task ExecCommandInRunningContainerWithStdout() { // Given var testcontainersBuilder = new TestcontainersBuilder <TestcontainersContainer>() .WithImage("alpine") .WithEntrypoint(KeepTestcontainersUpAndRunning.Command); // When // Then await using (ITestcontainersContainer testcontainer = testcontainersBuilder.Build()) { await testcontainer.StartAsync(); var execResult = await testcontainer.ExecAsync(new[] { "/bin/sh", "-c", "ping -c 4 google.com" }); Assert.Contains("PING google.com", execResult.Stdout); } }
public async Task ExecCommandInRunningContainer() { // Given var testcontainersBuilder = new TestcontainersBuilder <TestcontainersContainer>() .WithImage("alpine") .WithEntrypoint(KeepTestcontainersUpAndRunning.Command); // When // Then await using (ITestcontainersContainer testcontainer = testcontainersBuilder.Build()) { await testcontainer.StartAsync(); var execResult = await testcontainer.ExecAsync(new[] { "/bin/sh", "-c", "exit 255" }); Assert.Equal(255, execResult.ExitCode); } }