Skip to content

Commit

Permalink
fix(testcontainers#640) Fixed locked file in CopyResourceMappingConta…
Browse files Browse the repository at this point in the history
…inerTest
  • Loading branch information
vlaskal committed Nov 5, 2022
1 parent 99ac9a5 commit bdee2d5
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public sealed class CopyResourceMappingContainerTest : IAsyncLifetime, IDisposab
{
private const string ResourceMappingContent = "👋";

private readonly FileStream fileStream = new(Path.Combine(Path.GetTempPath(), Path.GetTempFileName()), FileMode.Create, FileAccess.Write, FileShare.Read, ResourceMappingContent.Length, FileOptions.DeleteOnClose);
private readonly string filePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());

private readonly string fileResourceMappingFilePath = Path.Combine("/tmp", Path.GetTempFileName());

Expand All @@ -27,22 +27,30 @@ public CopyResourceMappingContainerTest()
this.container = new TestcontainersBuilder<TestcontainersContainer>()
.WithImage("alpine")
.WithEntrypoint(KeepTestcontainersUpAndRunning.Command)
.WithResourceMapping(this.fileStream.Name, this.fileResourceMappingFilePath)
.WithResourceMapping(this.filePath, this.fileResourceMappingFilePath)
.WithResourceMapping(Encoding.Default.GetBytes(ResourceMappingContent), this.binaryResourceMappingFilePath)
.Build();
}

public Task InitializeAsync()
{
this.fileStream.Write(Encoding.Default.GetBytes(ResourceMappingContent));
this.fileStream.Flush();
using (var fileStream = File.Create(this.filePath))
{
fileStream.Write(Encoding.Default.GetBytes(ResourceMappingContent));
fileStream.Flush();
}

return this.container.StartAsync();
}

public Task DisposeAsync()
public async Task DisposeAsync()
{
this.fileStream.Dispose();
return this.container.DisposeAsync().AsTask();
await this.container.DisposeAsync();

if (File.Exists(this.filePath))
{
File.Delete(this.filePath);
}
}

public void Dispose()
Expand Down

0 comments on commit bdee2d5

Please sign in to comment.