commit 6c8bacf30bb7e0acbbe0a9eaffee83b31c93b088
parent 61f560d3624f30f78b90b9a804db7d5126e1a7da
Author: Antoine A <>
Date: Wed, 11 Oct 2023 21:56:13 +0000
Cleanup test config
Diffstat:
6 files changed, 53 insertions(+), 60 deletions(-)
diff --git a/bank/conf/test.conf b/bank/conf/test.conf
@@ -14,4 +14,8 @@ fractional_input_digits = 2
fractional_normal_digits = 2
fractional_trailing_zero_digits = 2
is_currency_name_leading = NO
-alt_unit_names = {"0":"ク"}
-\ No newline at end of file
+alt_unit_names = {"0":"ク"}
+
+[libeufin-bankdb-postgres]
+SQL_DIR = $DATADIR/sql/
+CONFIG = postgresql:///libeufincheck
+\ No newline at end of file
diff --git a/bank/conf/test_restrict.conf b/bank/conf/test_restrict.conf
@@ -14,4 +14,8 @@ fractional_input_digits = 2
fractional_normal_digits = 2
fractional_trailing_zero_digits = 2
is_currency_name_leading = NO
-alt_unit_names = {"0":"ク"}
-\ No newline at end of file
+alt_unit_names = {"0":"ク"}
+
+[libeufin-bankdb-postgres]
+SQL_DIR = $DATADIR/sql/
+CONFIG = postgresql:///libeufincheck
+\ No newline at end of file
diff --git a/bank/src/test/kotlin/Common.kt b/bank/src/test/kotlin/Common.kt
@@ -1,44 +0,0 @@
-/*
- * This file is part of LibEuFin.
- * Copyright (C) 2019 Stanisci and Dold.
-
- * LibEuFin is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation; either version 3, or
- * (at your option) any later version.
-
- * LibEuFin is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General
- * Public License for more details.
-
- * You should have received a copy of the GNU Affero General Public
- * License along with LibEuFin; see the file COPYING. If not, see
- * <http://www.gnu.org/licenses/>
- */
-
-import tech.libeufin.bank.*
-import java.io.ByteArrayOutputStream
-import java.util.zip.DeflaterOutputStream
-
-/**
- * Init the database and sets the currency to KUDOS.
- */
-fun initDb(): Database {
- // We assume that libeufin-bank is installed. We could also try to locate the source tree here.
- val config = TalerConfig(ConfigSource("libeufin-bank", "libeufin-bank"))
- config.load()
- val sqlPath = config.requirePath("libeufin-bankdb-postgres", "SQL_DIR")
- val dbConnStr = "postgresql:///libeufincheck"
- resetDatabaseTables(dbConnStr, sqlPath)
- initializeDatabaseTables(dbConnStr, sqlPath)
- return Database(dbConnStr, "KUDOS")
-}
-
-fun deflater(reqBody: String): ByteArray {
- val bos = ByteArrayOutputStream()
- val ios = DeflaterOutputStream(bos)
- ios.write(reqBody.toByteArray())
- ios.finish()
- return bos.toByteArray()
-}
-\ No newline at end of file
diff --git a/bank/src/test/kotlin/helpers.kt b/bank/src/test/kotlin/helpers.kt
@@ -9,26 +9,31 @@ import kotlinx.serialization.json.JsonPrimitive
import net.taler.wallet.crypto.Base32Crockford
import kotlin.test.assertEquals
import tech.libeufin.bank.*
+import java.io.ByteArrayOutputStream
+import java.util.zip.DeflaterOutputStream
/* ----- Setup ----- */
-fun setupDb(lambda: (Database) -> Unit) {
- initDb().use(lambda)
-}
-
fun setup(
conf: String = "test.conf",
lambda: (Database, BankApplicationContext) -> Unit
){
- val db = initDb()
val config = TalerConfig(BANK_CONFIG_SOURCE)
config.load("conf/$conf")
+ val dbConnStr = config.requireString("libeufin-bankdb-postgres", "config")
+ val sqlPath = config.requirePath("libeufin-bankdb-postgres", "SQL_DIR")
+ resetDatabaseTables(dbConnStr, sqlPath)
+ initializeDatabaseTables(dbConnStr, sqlPath)
val ctx = BankApplicationContext.readFromConfig(config)
- db.use {
- lambda(db, ctx)
+ Database(dbConnStr, ctx.currency).use {
+ lambda(it, ctx)
}
}
+fun setupDb(lambda: (Database) -> Unit) {
+ setup() { db, _ -> lambda(db) }
+}
+
/* ----- Assert ----- */
fun HttpResponse.assertStatus(status: HttpStatusCode): HttpResponse {
@@ -59,7 +64,11 @@ inline fun <reified B> HttpRequestBuilder.jsonBody(b: B, deflate: Boolean = fals
contentType(ContentType.Application.Json)
if (deflate) {
headers.set("Content-Encoding", "deflate")
- setBody(deflater(json))
+ val bos = ByteArrayOutputStream()
+ val ios = DeflaterOutputStream(bos)
+ ios.write(json.toByteArray())
+ ios.finish()
+ setBody(bos.toByteArray())
} else {
setBody(json)
}
diff --git a/contrib/docker-launcher/libeufin-bank.conf b/contrib/docker-launcher/libeufin-bank.conf
@@ -10,8 +10,16 @@ SERVE = tcp
PORT = 8080
[libeufin-bankdb-postgres]
-# Where are the SQL files to setup our tables?
SQL_DIR = /usr/local/share/taler/sql/libeufin-bank/
-
-# DB connection string
CONFIG = postgresql:///libeufinbank
+
+[currency-kudos]
+ENABLED = YES
+name = "Kudos (Taler Demonstrator)"
+code = "KUDOS"
+decimal_separator = ","
+fractional_input_digits = 2
+fractional_normal_digits = 2
+fractional_trailing_zero_digits = 2
+is_currency_name_leading = NO
+alt_unit_names = {"0":"ク"}
+\ No newline at end of file
diff --git a/contrib/libeufin-bank.conf b/contrib/libeufin-bank.conf
@@ -40,3 +40,14 @@ SQL_DIR = $DATADIR/sql/
# DB connection string
CONFIG = postgresql:///libeufinbank
+
+[currency-kudos]
+ENABLED = YES
+name = "Kudos (Taler Demonstrator)"
+code = "KUDOS"
+decimal_separator = ","
+fractional_input_digits = 2
+fractional_normal_digits = 2
+fractional_trailing_zero_digits = 2
+is_currency_name_leading = NO
+alt_unit_names = {"0":"ク"}
+\ No newline at end of file