Skip to content

Commit 6498031

Browse files
test(audience-sdk): centralise DiskStoreTests file body fixtures
DiskStoreTests had three inline file body fixtures used as File.WriteAllText payloads: - "{\"stale\":true}" — older-than-purge-window file in the ApplyAnonymousDowngrade fixture - "{\"survived\":true}" — non-stale file the same fixture must keep - "{not valid json" — malformed file that exercises the malformed-input branch Adds StaleFileBody / SurvivingFileBody / MalformedFileBody file-local consts at the top of the fixture (matching the existing test-fixture const block convention) and migrates the three call sites. Per the user's "everything random goes in a constant" stance. Follow-up to SDK-272 (centralisation of duplicated literals).
1 parent f7aa206 commit 6498031

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/Packages/Audience/Tests/Runtime/Transport/DiskStoreTests.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ namespace Immutable.Audience.Tests
99
[TestFixture]
1010
internal class DiskStoreTests
1111
{
12+
// File body fixtures for queue scenarios: stale, surviving, malformed.
13+
private const string StaleFileBody = "{\"stale\":true}";
14+
private const string SurvivingFileBody = "{\"survived\":true}";
15+
private const string MalformedFileBody = "{not valid json";
16+
1217
private string _testDir;
1318
private DiskStore _store;
1419

@@ -98,7 +103,7 @@ public void ReadBatch_ExcludesAndDeletesStaleFiles()
98103
var staleTime = DateTime.UtcNow.AddDays(-(Constants.StaleEventDays + 1));
99104
var staleName = $"{staleTime.Ticks}_{Guid.NewGuid():N}{AudiencePaths.QueueFileExtension}";
100105
var queueDir = AudiencePaths.QueueDir(_testDir);
101-
File.WriteAllText(Path.Combine(queueDir, staleName), "{\"stale\":true}");
106+
File.WriteAllText(Path.Combine(queueDir, staleName), StaleFileBody);
102107

103108
var batch = _store.ReadBatch(10);
104109

@@ -152,7 +157,7 @@ public void CrashRecovery_PicksUpFilesFromPreviousRun()
152157
// Simulate a previous run by writing a file directly
153158
var queueDir = AudiencePaths.QueueDir(_testDir);
154159
var survivingName = $"{DateTime.UtcNow.Ticks}_{Guid.NewGuid():N}{AudiencePaths.QueueFileExtension}";
155-
File.WriteAllText(Path.Combine(queueDir, survivingName), "{\"survived\":true}");
160+
File.WriteAllText(Path.Combine(queueDir, survivingName), SurvivingFileBody);
156161

157162
// Create a new DiskStore instance pointing at the same path (simulates restart)
158163
var store2 = new DiskStore(_testDir);
@@ -233,7 +238,7 @@ public void ApplyAnonymousDowngrade_DeletesMalformedFiles()
233238
// downgrade cannot leave it to potentially leak identified data.
234239
var queueDir = AudiencePaths.QueueDir(_testDir);
235240
var badName = $"{DateTime.UtcNow.Ticks}_{Guid.NewGuid():N}{AudiencePaths.QueueFileExtension}";
236-
File.WriteAllText(Path.Combine(queueDir, badName), "{not valid json");
241+
File.WriteAllText(Path.Combine(queueDir, badName), MalformedFileBody);
237242

238243
_store.ApplyAnonymousDowngrade();
239244

0 commit comments

Comments
 (0)