@@ -13,6 +13,7 @@ import io.element.android.features.rageshake.api.reporter.BugReporterListener
13
13
import io.element.android.features.rageshake.impl.crash.CrashDataStore
14
14
import io.element.android.features.rageshake.impl.crash.FakeCrashDataStore
15
15
import io.element.android.features.rageshake.impl.screenshot.FakeScreenshotHolder
16
+ import io.element.android.libraries.core.meta.BuildMeta
16
17
import io.element.android.libraries.matrix.api.MatrixClientProvider
17
18
import io.element.android.libraries.matrix.api.auth.MatrixAuthenticationService
18
19
import io.element.android.libraries.matrix.api.tracing.TracingService
@@ -305,23 +306,35 @@ class DefaultBugReporterTest {
305
306
@Test
306
307
fun `the log directory is initialized using the last session store data` () = runTest {
307
308
val sut = createDefaultBugReporter(
309
+ buildMeta = aBuildMeta(isEnterpriseBuild = true ),
308
310
sessionStore = InMemorySessionStore ().apply {
309
311
storeData(aSessionData(sessionId = " @alice:domain.com" ))
310
312
}
311
313
)
312
314
assertThat(sut.logDirectory().absolutePath).endsWith(" /cache/logs/domain.com" )
313
315
}
314
316
317
+ @Test
318
+ fun `foss build - the log directory is initialized to the root log directory` () = runTest {
319
+ val sut = createDefaultBugReporter(
320
+ sessionStore = InMemorySessionStore ().apply {
321
+ storeData(aSessionData(sessionId = " @alice:domain.com" ))
322
+ }
323
+ )
324
+ assertThat(sut.logDirectory().absolutePath).endsWith(" /cache/logs" )
325
+ }
326
+
315
327
@Test
316
328
fun `when the log directory is updated, the tracing service is invoked` () = runTest {
317
329
var param: WriteToFilesConfiguration ? = null
318
330
val updateWriteToFilesConfigurationResult = lambdaRecorder<WriteToFilesConfiguration , Unit > {
319
331
param = it
320
332
}
321
333
val sut = createDefaultBugReporter(
334
+ buildMeta = aBuildMeta(isEnterpriseBuild = true ),
322
335
tracingService = FakeTracingService (
323
336
updateWriteToFilesConfigurationResult = updateWriteToFilesConfigurationResult,
324
- )
337
+ ),
325
338
)
326
339
sut.setLogDirectorySubfolder(" my.sub.folder" )
327
340
updateWriteToFilesConfigurationResult.assertions().isCalledOnce()
@@ -333,16 +346,29 @@ class DefaultBugReporterTest {
333
346
assertThat((param as WriteToFilesConfiguration .Enabled ).filenameSuffix).isEqualTo(" log" )
334
347
}
335
348
349
+ @Test
350
+ fun `foss build - when the log directory is updated, the tracing service is not invoked` () = runTest {
351
+ val updateWriteToFilesConfigurationResult = lambdaRecorder<WriteToFilesConfiguration , Unit > {}
352
+ val sut = createDefaultBugReporter(
353
+ tracingService = FakeTracingService (
354
+ updateWriteToFilesConfigurationResult = updateWriteToFilesConfigurationResult,
355
+ )
356
+ )
357
+ sut.setLogDirectorySubfolder(" my.sub.folder" )
358
+ updateWriteToFilesConfigurationResult.assertions().isNeverCalled()
359
+ }
360
+
336
361
@Test
337
362
fun `when the log directory is reset, the tracing service is invoked` () = runTest {
338
363
var param: WriteToFilesConfiguration ? = null
339
364
val updateWriteToFilesConfigurationResult = lambdaRecorder<WriteToFilesConfiguration , Unit > {
340
365
param = it
341
366
}
342
367
val sut = createDefaultBugReporter(
368
+ buildMeta = aBuildMeta(isEnterpriseBuild = true ),
343
369
tracingService = FakeTracingService (
344
370
updateWriteToFilesConfigurationResult = updateWriteToFilesConfigurationResult,
345
- )
371
+ ),
346
372
)
347
373
sut.setLogDirectorySubfolder(null )
348
374
updateWriteToFilesConfigurationResult.assertions().isCalledOnce()
@@ -354,6 +380,18 @@ class DefaultBugReporterTest {
354
380
assertThat((param as WriteToFilesConfiguration .Enabled ).filenameSuffix).isEqualTo(" log" )
355
381
}
356
382
383
+ @Test
384
+ fun `foss build - when the log directory is reset, the tracing service is not invoked` () = runTest {
385
+ val updateWriteToFilesConfigurationResult = lambdaRecorder<WriteToFilesConfiguration , Unit > {}
386
+ val sut = createDefaultBugReporter(
387
+ tracingService = FakeTracingService (
388
+ updateWriteToFilesConfigurationResult = updateWriteToFilesConfigurationResult,
389
+ )
390
+ )
391
+ sut.setLogDirectorySubfolder(null )
392
+ updateWriteToFilesConfigurationResult.assertions().isNeverCalled()
393
+ }
394
+
357
395
@Test
358
396
fun `when a new MatrixClient is created the logs folder is updated` () = runTest {
359
397
var param: WriteToFilesConfiguration ? = null
@@ -368,6 +406,7 @@ class DefaultBugReporterTest {
368
406
)
369
407
}
370
408
val sut = createDefaultBugReporter(
409
+ buildMeta = aBuildMeta(isEnterpriseBuild = true ),
371
410
matrixAuthenticationService = matrixAuthenticationService,
372
411
tracingService = FakeTracingService (
373
412
updateWriteToFilesConfigurationResult = updateWriteToFilesConfigurationResult,
@@ -385,15 +424,37 @@ class DefaultBugReporterTest {
385
424
assertThat((param as WriteToFilesConfiguration .Enabled ).filenameSuffix).isEqualTo(" log" )
386
425
}
387
426
427
+ @Test
428
+ fun `foss build - when a new MatrixClient is created the logs folder is not updated` () = runTest {
429
+ val updateWriteToFilesConfigurationResult = lambdaRecorder<WriteToFilesConfiguration , Unit > {}
430
+ val matrixAuthenticationService = FakeMatrixAuthenticationService ().apply {
431
+ givenMatrixClient(
432
+ FakeMatrixClient (
433
+ userIdServerNameLambda = { " domain.foo.org" },
434
+ )
435
+ )
436
+ }
437
+ val sut = createDefaultBugReporter(
438
+ matrixAuthenticationService = matrixAuthenticationService,
439
+ tracingService = FakeTracingService (
440
+ updateWriteToFilesConfigurationResult = updateWriteToFilesConfigurationResult,
441
+ )
442
+ )
443
+ assertThat(sut.logDirectory().absolutePath).endsWith(" /cache/logs" )
444
+ matrixAuthenticationService.login(" alice" , " password" )
445
+ assertThat(sut.logDirectory().absolutePath).endsWith(" /cache/logs" )
446
+ updateWriteToFilesConfigurationResult.assertions().isNeverCalled()
447
+ }
448
+
388
449
private fun TestScope.createDefaultBugReporter (
450
+ buildMeta : BuildMeta = aBuildMeta(),
389
451
sessionStore : SessionStore = InMemorySessionStore (),
390
452
matrixClientProvider : MatrixClientProvider = FakeMatrixClientProvider (),
391
453
crashDataStore : CrashDataStore = FakeCrashDataStore (),
392
454
server : MockWebServer = MockWebServer (),
393
455
tracingService : TracingService = FakeTracingService (),
394
456
matrixAuthenticationService : MatrixAuthenticationService = FakeMatrixAuthenticationService (),
395
457
): DefaultBugReporter {
396
- val buildMeta = aBuildMeta()
397
458
return DefaultBugReporter (
398
459
context = RuntimeEnvironment .getApplication(),
399
460
screenshotHolder = FakeScreenshotHolder (),
0 commit comments