Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#43: DBTestSuite: parametrize persist_data into constructor #46

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions balta/src/main/scala/za/co/absa/db/balta/DBTestSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ 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 extends AnyFunSuite {
abstract class DBTestSuite(val persistDataOverride: Option[Boolean] = None) extends AnyFunSuite {

def this(persistDataOverride: Boolean) {
this(Some(persistDataOverride));
}

/* the DB connection is ``lazy`, so it actually can be created only when needed and therefore the credentials
overridden in the successor */
Expand All @@ -44,7 +48,11 @@ abstract class DBTestSuite extends AnyFunSuite {
/**
* This is the connection info for the DB. It can be overridden in the derived classes to provide specific credentials
*/
protected lazy val connectionInfo: ConnectionInfo = readConnectionInfoFromConfig
protected lazy val connectionInfo: ConnectionInfo = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By this change, you kept the private method readConnectionInfoFromConfig without usage. Is that intention?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for noticing!

val connectionInfoFromConfig = readConnectionInfoFromConfig
persistDataOverride.map(overrideValue => connectionInfoFromConfig.copy(persistData = overrideValue))
.getOrElse(connectionInfoFromConfig)
}

/**
* This is an enhanced test function that automatically rolls back the transaction after the test is finished
Expand Down Expand Up @@ -146,7 +154,7 @@ abstract class DBTestSuite extends AnyFunSuite {
}

// private functions
private def readConnectionInfoFromConfig: ConnectionInfo = {
protected def readConnectionInfoFromConfig: ConnectionInfo = {
val properties = new Properties()
properties.load(getClass.getResourceAsStream("/database.properties"))

Expand Down
Loading