From cfe1c3d4b51a57fe3298455eb4e731f0a66ee364 Mon Sep 17 00:00:00 2001 From: David Benedeki Date: Wed, 22 Jul 2026 11:24:37 +0200 Subject: [PATCH] #8: Improve how asserts with the test function are handled * by using method `afterEach` from `BeforeAndAfterEach` instead of overding the `test` method the class behavior streamlined considerably * added instruction file fore coderabbit review AI --- .coderabbit.yaml | 45 ++++++++++++++++++ .../za/co/absa/db/balta/DBTestSuite.scala | 46 +++++++------------ 2 files changed, 62 insertions(+), 29 deletions(-) create mode 100644 .coderabbit.yaml diff --git a/.coderabbit.yaml b/.coderabbit.yaml new file mode 100644 index 0000000..600d299 --- /dev/null +++ b/.coderabbit.yaml @@ -0,0 +1,45 @@ +# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json + +language: "en-US" + +tone_instructions: >- + Be direct and concise. Skip praise and filler. Focus comments on + correctness, security, and maintainability issues. + +early_access: false +enable_free_tier: true + +reviews: + profile: "chill" # "chill" or "assertive" — start lenient, tighten later + request_changes_workflow: false + high_level_summary: true + poem: false + review_status: true + collapse_walkthrough: true + + auto_review: + enabled: true + drafts: false + labels: + - "!work in progress" # skip PRs labeled "Work in progress" + + path_filters: + - "!**/target/**" # sbt build output (root + project/) + - "!**/*.class" + - "!**/*.jar" + - "!**/generated/**" + - "!**/*.lock" + + tools: + shellcheck: + enabled: false + markdownlint: + enabled: true + github-checks: + enabled: true + timeout_ms: 90000 + languagetool: + enabled: true + +chat: + auto_reply: true diff --git a/balta/src/main/scala/za/co/absa/db/balta/DBTestSuite.scala b/balta/src/main/scala/za/co/absa/db/balta/DBTestSuite.scala index 63317b5..6c09ba1 100644 --- a/balta/src/main/scala/za/co/absa/db/balta/DBTestSuite.scala +++ b/balta/src/main/scala/za/co/absa/db/balta/DBTestSuite.scala @@ -16,8 +16,7 @@ package za.co.absa.db.balta -import org.scalactic.source -import org.scalatest.Tag +import org.scalatest.BeforeAndAfterEach import org.scalatest.funsuite.AnyFunSuite import za.co.absa.db.balta.classes.{DBConnection, DBFunction, DBTable, QueryResult} import za.co.absa.db.balta.classes.DBFunction.DBFunctionWithPositionedParamsOnly @@ -36,7 +35,22 @@ import java.util.Properties * * easy access to DB tables and functions * * the now() function that returns the current transaction time in the DB */ -abstract class DBTestSuite(val persistDataOverride: Option[Boolean] = None) extends AnyFunSuite { +abstract class DBTestSuite(val persistDataOverride: Option[Boolean] = None) + extends AnyFunSuite + with BeforeAndAfterEach { + + /** + * This to ensure that the tests are idempotent by rolling back the transaction after each test, unless persistData is + * explicitly set to true in the connection info (for rare cases and debugging purposes). + */ + override def afterEach(): Unit = { + if (connectionInfo.persistData) { + dbConnection.connection.commit() + } else { + dbConnection.connection.rollback() + } + super.afterEach() + } def this(persistDataOverride: Boolean) { this(Some(persistDataOverride)); @@ -55,31 +69,6 @@ abstract class DBTestSuite(val persistDataOverride: Option[Boolean] = None) exte .getOrElse(connectionInfoFromConfig) } - /** - * This is an enhanced test function that automatically rolls back the transaction after the test is finished - * - * @param testName – the name of the test - * @param testTags – the optional list of tags for this test - * @param testFun – the test function - */ - override protected def test(testName: String, testTags: Tag*) - (testFun: => Any /* Assertion */) - (implicit pos: source.Position): Unit = { - val dbTestFun = { - try { - testFun - } - finally { - if (connectionInfo.persistData) { - dbConnection.connection.commit() - } else { - dbConnection.connection.rollback() - } - } - } - super.test(testName, testTags: _*)(dbTestFun) - } - /** * This is a helper function that allows to easily access a DB table * @param tableName - the name of the table @@ -175,4 +164,3 @@ object DBTestSuite { ) } } -