-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A bunch of little fixes + reorg listeners code
- Loading branch information
1 parent
22baeda
commit 4340e8f
Showing
4 changed files
with
99 additions
and
63 deletions.
There are no files selected for viewing
This file contains 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
44 changes: 44 additions & 0 deletions
44
src/main/kotlin/dev/restate/sdktesting/junit/InjectLog4jContextListener.kt
This file contains 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,44 @@ | ||
// Copyright (c) 2023 - Restate Software, Inc., Restate GmbH | ||
// | ||
// This file is part of the Restate SDK Test suite tool, | ||
// which is released under the MIT license. | ||
// | ||
// You can find a copy of the license in file LICENSE in the root | ||
// directory of this repository or package, or at | ||
// https://github.com/restatedev/sdk-test-suite/blob/main/LICENSE | ||
package dev.restate.sdktesting.junit | ||
|
||
import kotlin.jvm.optionals.getOrNull | ||
import org.apache.logging.log4j.ThreadContext | ||
import org.junit.platform.engine.TestExecutionResult | ||
import org.junit.platform.engine.support.descriptor.ClassSource | ||
import org.junit.platform.launcher.TestExecutionListener | ||
import org.junit.platform.launcher.TestIdentifier | ||
import org.junit.platform.launcher.TestPlan | ||
|
||
class InjectLog4jContextListener(val suiteName: String) : TestExecutionListener { | ||
|
||
companion object { | ||
const val TEST_NAME = "test" | ||
} | ||
|
||
@Volatile var testPlan: TestPlan? = null | ||
|
||
override fun testPlanExecutionStarted(testPlan: TestPlan) { | ||
this.testPlan = testPlan | ||
} | ||
|
||
override fun executionStarted(testIdentifier: TestIdentifier) { | ||
if (testIdentifier.isTest || testIdentifier.source.getOrNull() is ClassSource) { | ||
val displayName = describeTestIdentifier(suiteName, testPlan!!, testIdentifier) | ||
ThreadContext.put(TEST_NAME, displayName) | ||
} | ||
} | ||
|
||
override fun executionFinished( | ||
testIdentifier: TestIdentifier, | ||
testExecutionResult: TestExecutionResult | ||
) { | ||
ThreadContext.remove(TEST_NAME) | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/kotlin/dev/restate/sdktesting/junit/LogTestEventsToTerminalListener.kt
This file contains 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,52 @@ | ||
// Copyright (c) 2023 - Restate Software, Inc., Restate GmbH | ||
// | ||
// This file is part of the Restate SDK Test suite tool, | ||
// which is released under the MIT license. | ||
// | ||
// You can find a copy of the license in file LICENSE in the root | ||
// directory of this repository or package, or at | ||
// https://github.com/restatedev/sdk-test-suite/blob/main/LICENSE | ||
package dev.restate.sdktesting.junit | ||
|
||
import com.github.ajalt.mordant.terminal.Terminal | ||
import kotlin.jvm.optionals.getOrNull | ||
import org.junit.platform.engine.TestExecutionResult | ||
import org.junit.platform.engine.support.descriptor.ClassSource | ||
import org.junit.platform.launcher.TestExecutionListener | ||
import org.junit.platform.launcher.TestIdentifier | ||
import org.junit.platform.launcher.TestPlan | ||
|
||
class LogTestEventsToTerminalListener(val suiteName: String, val terminal: Terminal) : | ||
TestExecutionListener { | ||
@Volatile var testPlan: TestPlan? = null | ||
|
||
override fun testPlanExecutionStarted(testPlan: TestPlan) { | ||
this.testPlan = testPlan | ||
} | ||
|
||
override fun executionFinished( | ||
testIdentifier: TestIdentifier, | ||
testExecutionResult: TestExecutionResult | ||
) { | ||
if (testIdentifier.isTest) { | ||
val name = describeTestIdentifier(suiteName, testPlan!!, testIdentifier) | ||
when (testExecutionResult.status!!) { | ||
TestExecutionResult.Status.SUCCESSFUL -> terminal.println("✅ $name") | ||
TestExecutionResult.Status.ABORTED -> terminal.println("❌ $name") | ||
TestExecutionResult.Status.FAILED -> { | ||
terminal.println("❌ $name") | ||
} | ||
} | ||
} | ||
if (testIdentifier.source.getOrNull() is ClassSource) { | ||
val name = describeTestIdentifier(suiteName, testPlan!!, testIdentifier) | ||
when (testExecutionResult.status!!) { | ||
TestExecutionResult.Status.ABORTED -> terminal.println("❌ $name init") | ||
TestExecutionResult.Status.FAILED -> { | ||
terminal.println("❌ $name init") | ||
} | ||
else -> {} | ||
} | ||
} | ||
} | ||
} |
This file contains 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