Skip to content

Commit 83a9407

Browse files
gnpricechrisbobbe
authored andcommitted
test: Prevent mutating shared example ServerEmojiData values
In principle these are subject to the same sort of state leak we've run into with the shared example User objects, and fixed in recent commits: these are shared global objects, which don't get discarded or reset by `testBinding.reset`, and until this commit they were mutable. The probability that we'd actually end up with such a state leak was low: ServerEmojiData values never normally get mutated in the app's data structures (unlike User values), plus there'll probably only ever be a small number of tests that would have a reason to use these. But after the preceding couple of commits (notably the one introducing _ImmutableUser), these represent the last remaining mutable data in this file's top-level fields. So let's eliminate that too, and get to 100% in eliminating the possibility of the #1712 class of bug.
1 parent 805afac commit 83a9407

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

test/example_data.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,14 @@ GetServerSettingsResult serverSettings({
131131
);
132132
}
133133

134-
final ServerEmojiData serverEmojiDataPopular = ServerEmojiData(codeToNames: {
134+
ServerEmojiData _immutableServerEmojiData({
135+
required Map<String, List<String>> codeToNames}) {
136+
return ServerEmojiData(
137+
codeToNames: Map.unmodifiable(codeToNames.map(
138+
(k, v) => MapEntry(k, List<String>.unmodifiable(v)))));
139+
}
140+
141+
final ServerEmojiData serverEmojiDataPopular = _immutableServerEmojiData(codeToNames: {
135142
'1f44d': ['+1', 'thumbs_up', 'like'],
136143
'1f389': ['tada'],
137144
'1f642': ['slight_smile'],
@@ -158,7 +165,7 @@ ServerEmojiData serverEmojiDataPopularPlus(ServerEmojiData data) {
158165
///
159166
/// zulip/zulip@9feba0f16f is a Server 11 commit.
160167
// TODO(server-11) can drop this
161-
final ServerEmojiData serverEmojiDataPopularLegacy = ServerEmojiData(codeToNames: {
168+
final ServerEmojiData serverEmojiDataPopularLegacy = _immutableServerEmojiData(codeToNames: {
162169
'1f44d': ['+1', 'thumbs_up', 'like'],
163170
'1f389': ['tada'],
164171
'1f642': ['smile'],

0 commit comments

Comments
 (0)