Skip to content

Commit

Permalink
original test
Browse files Browse the repository at this point in the history
  • Loading branch information
manas-yu committed Nov 11, 2024
1 parent b133fc9 commit 25859ca
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import javax.inject.Singleton
class ConsoleLoggerTest {
private companion object {
private const val testTag = "tag"
private val testLogLevel: LogLevel = LogLevel.ERROR
private const val testMessage = "test error message"
}

Expand Down Expand Up @@ -79,7 +80,8 @@ class ConsoleLoggerTest {
val logContent = logFile.readText()
assertThat(logContent).contains(testMessage)
assertThat(logContent).contains("$testMessage 2")
assertThat(logContent.indexOf(testMessage)).isLessThan(logContent.indexOf("$testMessage 2"))
assertThat(logContent.indexOf(testMessage))
.isLessThan(logContent.indexOf("$testMessage 2"))
}

@Test
Expand All @@ -88,6 +90,15 @@ class ConsoleLoggerTest {
val firstErrorContextsDeferred = CoroutineScope(backgroundTestDispatcher).async {
consoleLogger.logErrorMessagesFlow.take(1).toList()
}

testCoroutineDispatchers.advanceUntilIdle() // Ensure the flow is subscribed before emit().
consoleLogger.e(testTag, testMessage)
testCoroutineDispatchers.advanceUntilIdle()

val firstErrorContext = firstErrorContextsDeferred.getCompleted().single()
assertThat(firstErrorContext.logTag).isEqualTo(testTag)
assertThat(firstErrorContext.logLevel).isEqualTo(testLogLevel.toString())
assertThat(firstErrorContext.fullErrorLog).isEqualTo(testMessage)
}

@Test
Expand Down

0 comments on commit 25859ca

Please sign in to comment.