Skip to content

Commit

Permalink
UntilFilesExists should look for file in container
Browse files Browse the repository at this point in the history
The existing implementation of UntilFileExists seems to look for a file in the host's file system instead of the container's. This seems incorrect to me.
  • Loading branch information
maaex authored and sevonnexer committed Oct 3, 2023
1 parent 560b64f commit 37063ec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,17 @@ public UntilFilesExists(string file)
_file = file;
}

public Task<bool> UntilAsync(IContainer container)
public async Task<bool> UntilAsync(IContainer container)
{
return Task.FromResult(File.Exists(_file));
try
{
await container.ReadFileAsync(_file);
return true;
}
catch (FileNotFoundException)
{
return false;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
namespace DotNet.Testcontainers.Tests.Unit
{
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Commons;
using DotNet.Testcontainers.Configurations;
using DotNet.Testcontainers.Images;
using DotNet.Testcontainers.Tests.Fixtures;
using System;
using System.Globalization;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Commons;
using DotNet.Testcontainers.Configurations;
using DotNet.Testcontainers.Images;
using DotNet.Testcontainers.Tests.Fixtures;
using Xunit;

public static class TestcontainersContainerTest
Expand Down Expand Up @@ -222,7 +222,7 @@ public async Task BindMountAndCommand()
.WithEntrypoint("/bin/sh", "-c")
.WithCommand($"hostname > /{target}/{file}")
.WithBindMount(TestSession.TempDirectoryPath, $"/{target}")
.WithWaitStrategy(Wait.ForUnixContainer().UntilFileExists(Path.Combine(TestSession.TempDirectoryPath, file)))
.WithWaitStrategy(Wait.ForUnixContainer().UntilFileExists($"/{target}/{file}"))
.Build();

// When
Expand Down Expand Up @@ -251,7 +251,7 @@ public async Task BindMountAndEnvironment()
.WithEntrypoint("/bin/sh", "-c")
.WithCommand($"printf $DAY_OF_WEEK > /{target}/{file}")
.WithBindMount(TestSession.TempDirectoryPath, $"/{target}")
.WithWaitStrategy(Wait.ForUnixContainer().UntilFileExists(Path.Combine(TestSession.TempDirectoryPath, file)))
.WithWaitStrategy(Wait.ForUnixContainer().UntilFileExists($"/{target}/{file}"))
.Build();

// When
Expand Down

0 comments on commit 37063ec

Please sign in to comment.