Skip to content

Commit c5a366f

Browse files
committed
Add tests to ensure that reuse hashes are stable
1 parent c2b86ad commit c5a366f

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

tests/Testcontainers.Platform.Linux.Tests/ReusableResourceTest.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,44 @@ public async Task ShouldReuseExistingResource()
100100

101101
public static class ReuseHashTest
102102
{
103+
public sealed class EqualTest
104+
{
105+
[Fact]
106+
[Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))]
107+
public void ForSameConfigurationCreatedInDifferentOrder()
108+
{
109+
var env1 = new Dictionary<string, string>
110+
{
111+
["keyA"] = "valueA",
112+
["keyB"] = "valueB",
113+
};
114+
var env2 = new Dictionary<string, string>
115+
{
116+
["keyB"] = "valueB",
117+
["keyA"] = "valueA",
118+
};
119+
var hash1 = new ReuseHashContainerBuilder().WithEnvironment(env1).WithLabel("labelA", "A").WithLabel("labelB", "B").GetReuseHash();
120+
var hash2 = new ReuseHashContainerBuilder().WithEnvironment(env2).WithLabel("labelB", "B").WithLabel("labelA", "A").GetReuseHash();
121+
Assert.Equal(hash1, hash2);
122+
}
123+
124+
[Fact]
125+
[Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))]
126+
public void ForGivenConfiguration()
127+
{
128+
var env = new Dictionary<string, string>
129+
{
130+
["keyB"] = "valueB",
131+
["keyA"] = "valueA",
132+
};
133+
var hash = new ReuseHashContainerBuilder().WithEnvironment(env).WithLabel("labelB", "B").WithLabel("labelA", "A").GetReuseHash();
134+
135+
// 50MEP+vnxEkQFo5PrndJ7oKOfh8= is the base64 encoded SHA1 of this JSON:
136+
// {"Image":null,"Name":null,"Entrypoint":null,"Command":[],"Environments":{"keyA":"valueA","keyB":"valueB"},"ExposedPorts":{},"PortBindings":{},"NetworkAliases":[],"ExtraHosts":[],"Labels":{"labelA":"A","labelB":"B","org.testcontainers":"true","org.testcontainers.lang":"dotnet"}}
137+
Assert.Equal("50MEP+vnxEkQFo5PrndJ7oKOfh8=", hash);
138+
}
139+
}
140+
103141
public sealed class NotEqualTest
104142
{
105143
[Fact]

0 commit comments

Comments
 (0)