commit 27a8fa91a81b3f8930dfe3145f8d930bb03dc545
parent 7529280def4b7d80c3a214fae97042a4c9848bc3
Author: MS <ms@taler.net>
Date: Thu, 10 Dec 2020 17:16:24 +0100
Testing the PostgreSQL connection string.
Diffstat:
5 files changed, 29 insertions(+), 32 deletions(-)
diff --git a/integration-tests/tests.py b/integration-tests/tests.py
@@ -20,7 +20,7 @@ S = "http://localhost:5000"
N = "http://localhost:5001"
# Database
-DB = "libeufintestdb"
+DB = "jdbc:postgresql://127.0.0.1:5433/libeufintestdb?user=libeufin"
# Nexus user details
NEXUS_USERNAME = "person"
diff --git a/integration-tests/util.py b/integration-tests/util.py
@@ -46,40 +46,36 @@ def kill(name, s):
s.terminate()
s.wait()
-def removeStaleTables(dbName):
- flushTablesNexus(dbName)
- flushTablesSandbox(dbName)
-
-def makeNexusSuperuser(dbName):
+def makeNexusSuperuser(dbConnString):
check_call([
"../gradlew",
"-q", "--console=plain",
"-p", "..",
"nexus:run",
- f"--args=superuser admin --password x --db-name={dbName}",
+ f"--args=superuser admin --password x --db-conn-string={dbConnString}",
])
-def dropSandboxTables(dbName):
+def dropSandboxTables(dbConnString):
check_call([
"../gradlew",
"-q", "--console=plain",
"-p", "..",
"sandbox:run",
- f"--args=drop-tables",
+ f"--args=drop-tables --db-conn-string={dbConnString}"
])
-def dropNexusTables(dbName):
+def dropNexusTables(dbConnString):
check_call([
"../gradlew",
"-q", "--console=plain",
"-p", "..",
"nexus:run",
- f"--args=drop-tables",
+ f"--args=drop-tables --db-conn-string={dbConnString}"
])
-def startSandbox(dbName):
+def startSandbox(dbConnString):
check_call(["../gradlew", "-q", "--console=plain", "-p", "..", "sandbox:assemble"])
checkPort(5000)
sandbox = Popen([
@@ -89,10 +85,10 @@ def startSandbox(dbName):
"..",
"sandbox:run",
"--console=plain",
- "--args=serve --db-name={}".format(dbName)],
+ "--args=serve --db-conn-string={}".format(dbConnString)],
stdin=DEVNULL,
stdout=open("sandbox-stdout.log", "w"),
- stderr=open("sandbox-stderr.log", "w"),
+ stderr=open("sandbox-stderr.log", "w")
)
atexit.register(lambda: kill("sandbox", sandbox))
for i in range(10):
@@ -109,24 +105,22 @@ def startSandbox(dbName):
break
-def startNexus(dbName):
+def startNexus(dbConnString):
check_call(
["../gradlew", "-q", "--console=plain", "-p", "..", "nexus:assemble",]
)
checkPort(5001)
- nexus = Popen(
- [
- "../gradlew",
- "-q",
- "-p",
- "..",
- "nexus:run",
- "--console=plain",
- "--args=serve --db-name={}".format(dbName),
- ],
+ nexus = Popen([
+ "../gradlew",
+ "-q",
+ "-p",
+ "..",
+ "nexus:run",
+ "--console=plain",
+ "--args=serve --db-conn-string={}".format(dbConnString)],
stdin=DEVNULL,
stdout=open("nexus-stdout.log", "w"),
- stderr=open("nexus-stderr.log", "w"),
+ stderr=open("nexus-stderr.log", "w")
)
atexit.register(lambda: kill("nexus", nexus))
for i in range(80):
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -35,6 +35,7 @@ import tech.libeufin.nexus.server.serverMain
import tech.libeufin.util.CryptoUtil.hashpw
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import tech.libeufin.nexus.iso20022.parseCamtMessage
+import tech.libeufin.util.DEFAULT_DB_CONNECTION
import tech.libeufin.util.XMLUtil
import tech.libeufin.util.setLogLevel
import java.io.File
@@ -51,7 +52,7 @@ class Serve : CliktCommand("Run nexus HTTP server") {
helpFormatter = CliktHelpFormatter(showDefaultValues = true)
}
}
- private val dbConnString by option().default("jdbc:sqlite://libeufindb")
+ private val dbConnString by option().default(DEFAULT_DB_CONNECTION)
private val host by option().default("127.0.0.1")
private val logLevel by option()
override fun run() {
@@ -72,18 +73,18 @@ class ParseCamt : CliktCommand("Parse a camt file") {
}
class DropTables : CliktCommand("Drop all the tables from the database") {
- private val dbConnString by option().default("jdbc:sqlite://libeufindb")
+ private val dbConnString by option().default(DEFAULT_DB_CONNECTION)
override fun run() {
dbDropTables(dbConnString)
}
}
class Superuser : CliktCommand("Add superuser or change pw") {
- private val dbName by option().default("jdbc:sqlite://libeufindb")
+ private val dbConnString by option().default(DEFAULT_DB_CONNECTION)
private val username by argument()
private val password by option().prompt(requireConfirmation = true, hideInput = true)
override fun run() {
- dbCreateTables(dbName)
+ dbCreateTables(dbConnString)
transaction {
val hashedPw = hashpw(password)
val user = NexusUserEntity.findById(username)
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -91,14 +91,14 @@ class SandboxCommand : CliktCommand() {
}
class DropTables : CliktCommand("Drop all the tables from the database") {
- private val dbConnString by option().default("jdbc:sqlite://libeufindb")
+ private val dbConnString by option().default(DEFAULT_DB_CONNECTION)
override fun run() {
dbDropTables(dbConnString)
}
}
class Serve : CliktCommand("Run sandbox HTTP server") {
- private val dbConnString by option().default("jdbc:sqlite://libeufindb")
+ private val dbConnString by option().default(DEFAULT_DB_CONNECTION)
private val logLevel by option()
override fun run() {
LOGGER = LoggerFactory.getLogger("tech.libeufin.sandbox")
diff --git a/util/src/main/kotlin/Config.kt b/util/src/main/kotlin/Config.kt
@@ -6,6 +6,8 @@ import ch.qos.logback.classic.util.ContextInitializer
import ch.qos.logback.core.util.Loader
import org.slf4j.LoggerFactory
+val DEFAULT_DB_CONNECTION = "jdbc:sqlite:/tmp/libeufindb"
+
/**
* Set system properties to wanted values, and load logback configuration after.
* While it can set any system property, it is used only to set the log file name.