diff options
author | Antoine A <> | 2023-10-11 21:56:13 +0000 |
---|---|---|
committer | Antoine A <> | 2023-10-11 21:56:13 +0000 |
commit | 6c8bacf30bb7e0acbbe0a9eaffee83b31c93b088 (patch) | |
tree | c40d0fe3a28b35fcff233deb1f1c05a4afe039ec | |
parent | 61f560d3624f30f78b90b9a804db7d5126e1a7da (diff) | |
download | libeufin-6c8bacf30bb7e0acbbe0a9eaffee83b31c93b088.tar.gz libeufin-6c8bacf30bb7e0acbbe0a9eaffee83b31c93b088.tar.bz2 libeufin-6c8bacf30bb7e0acbbe0a9eaffee83b31c93b088.zip |
Cleanup test config
-rw-r--r-- | bank/conf/test.conf | 6 | ||||
-rw-r--r-- | bank/conf/test_restrict.conf | 6 | ||||
-rw-r--r-- | bank/src/test/kotlin/Common.kt | 44 | ||||
-rw-r--r-- | bank/src/test/kotlin/helpers.kt | 25 | ||||
-rw-r--r-- | contrib/docker-launcher/libeufin-bank.conf | 14 | ||||
-rw-r--r-- | contrib/libeufin-bank.conf | 11 |
6 files changed, 49 insertions, 57 deletions
diff --git a/bank/conf/test.conf b/bank/conf/test.conf index fe7450a6..703ab6c5 100644 --- 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 index 462d94e6..9a74f807 100644 --- 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 deleted file mode 100644 index 02e4327d..00000000 --- a/bank/src/test/kotlin/Common.kt +++ /dev/null @@ -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 index fa10e05d..e9a94582 100644 --- 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 index 3add3927..fad81ace 100644 --- 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 index f1aa2b09..660c2789 100644 --- 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 |