-
-
Notifications
You must be signed in to change notification settings - Fork 345
fix: Generate consistent reuse hashes by sorting dictionary keys #1554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
HofmeisterAn
merged 2 commits into
testcontainers:develop
from
0xced:bugfix/stable-reuse-hash
Oct 17, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
23 changes: 2 additions & 21 deletions
23
src/Testcontainers/Configurations/Commons/JsonIgnoreRuntimeResourceLabels.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,39 +1,20 @@ | ||
| namespace DotNet.Testcontainers.Configurations | ||
| { | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text.Json; | ||
| using System.Text.Json.Serialization; | ||
| using DotNet.Testcontainers.Clients; | ||
| using DotNet.Testcontainers.Containers; | ||
|
|
||
| internal sealed class JsonIgnoreRuntimeResourceLabels : JsonConverter<IReadOnlyDictionary<string, string>> | ||
| internal sealed class JsonIgnoreRuntimeResourceLabels : JsonOrderedKeysConverter | ||
| { | ||
| private static readonly ISet<string> IgnoreLabels = new HashSet<string> { ResourceReaper.ResourceReaperSessionLabel, TestcontainersClient.TestcontainersVersionLabel, TestcontainersClient.TestcontainersSessionIdLabel }; | ||
|
|
||
| public override bool CanConvert(Type typeToConvert) | ||
| { | ||
| return typeof(IEnumerable<KeyValuePair<string, string>>).IsAssignableFrom(typeToConvert); | ||
| } | ||
|
|
||
| public override IReadOnlyDictionary<string, string> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
| { | ||
| return JsonSerializer.Deserialize<IReadOnlyDictionary<string, string>>(ref reader); | ||
| } | ||
|
|
||
| public override void Write(Utf8JsonWriter writer, IReadOnlyDictionary<string, string> value, JsonSerializerOptions options) | ||
| { | ||
| var labels = value.Where(label => !IgnoreLabels.Contains(label.Key)).ToDictionary(label => label.Key, label => label.Value); | ||
|
|
||
| writer.WriteStartObject(); | ||
|
|
||
| foreach (var label in labels) | ||
| { | ||
| writer.WriteString(label.Key, label.Value); | ||
| } | ||
|
|
||
| writer.WriteEndObject(); | ||
| base.Write(writer, labels, options); | ||
| } | ||
| } | ||
| } |
33 changes: 33 additions & 0 deletions
33
src/Testcontainers/Configurations/Commons/JsonOrderedKeysConverter.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| namespace DotNet.Testcontainers.Configurations | ||
| { | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text.Json; | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| internal class JsonOrderedKeysConverter : JsonConverter<IReadOnlyDictionary<string, string>> | ||
| { | ||
| public override bool CanConvert(Type typeToConvert) | ||
| { | ||
| return typeof(IEnumerable<KeyValuePair<string, string>>).IsAssignableFrom(typeToConvert); | ||
| } | ||
|
|
||
| public override IReadOnlyDictionary<string, string> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
| { | ||
| return JsonSerializer.Deserialize<IReadOnlyDictionary<string, string>>(ref reader); | ||
| } | ||
|
|
||
| public override void Write(Utf8JsonWriter writer, IReadOnlyDictionary<string, string> value, JsonSerializerOptions options) | ||
| { | ||
| writer.WriteStartObject(); | ||
|
|
||
| foreach (var item in value.OrderBy(item => item.Key)) | ||
| { | ||
| writer.WriteString(item.Key, item.Value); | ||
| } | ||
|
|
||
| writer.WriteEndObject(); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.