Skip to content

Commit cfe690a

Browse files
committed
chore: add test
1 parent b70a74c commit cfe690a

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/Testcontainers.Tests/Unit/Images/ImageFromDockerfileTest.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,40 @@ public async Task DockerfileArchiveTar()
7878
Assert.Equal(expected, actual);
7979
}
8080

81+
[Fact]
82+
public async Task IgnoredDockerfileIsCopiedToTarball()
83+
{
84+
// Given
85+
86+
// This test ensures Dockerfiles in subdirectories are copied to the right paths
87+
// in the tarball, instead of ending up at the root directory:
88+
// https://github.com/testcontainers/testcontainers-dotnet/issues/1557.
89+
IImage image = new DockerImage("localhost/testcontainers", Guid.NewGuid().ToString("D"), string.Empty);
90+
91+
var actual = new SortedSet<string>();
92+
93+
var buildArguments = new ReadOnlyDictionary<string, string>(new Dictionary<string, string>());
94+
95+
var dockerfileArchive = new DockerfileArchive(null, "Assets/", "target/Dockerfile", image, buildArguments, NullLogger.Instance);
96+
97+
var dockerfileArchiveFilePath = await dockerfileArchive.Tar(TestContext.Current.CancellationToken)
98+
.ConfigureAwait(true);
99+
100+
// When
101+
using (var tarOut = new FileStream(dockerfileArchiveFilePath, FileMode.Open, FileAccess.Read))
102+
{
103+
using (var tarIn = TarArchive.CreateInputTarArchive(tarOut, Encoding.Default))
104+
{
105+
tarIn.ProgressMessageEvent += (_, entry, _) => actual.Add(entry.Name);
106+
tarIn.ListContents();
107+
}
108+
}
109+
110+
// Then
111+
Assert.Contains("target/Dockerfile", actual);
112+
Assert.DoesNotContain("Dockerfile", actual);
113+
}
114+
81115
[Fact]
82116
public async Task ThrowsDockerfileDoesNotExist()
83117
{

0 commit comments

Comments
 (0)