From 3321e40bffc5fe47133342d63f706a005a652273 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Fri, 7 Aug 2020 23:06:52 +0530 Subject: integration testing tweaks, rerun-payment-multiple scenario --- packages/taler-wallet-core/src/util/talerconfig.ts | 53 +++++++++++++++++++++- 1 file changed, 51 insertions(+), 2 deletions(-) (limited to 'packages/taler-wallet-core/src') diff --git a/packages/taler-wallet-core/src/util/talerconfig.ts b/packages/taler-wallet-core/src/util/talerconfig.ts index 8c740e1e2..e9a67287c 100644 --- a/packages/taler-wallet-core/src/util/talerconfig.ts +++ b/packages/taler-wallet-core/src/util/talerconfig.ts @@ -26,7 +26,6 @@ import { AmountJson } from "./amounts"; import * as Amounts from "./amounts"; import fs from "fs"; -import { acceptExchangeTermsOfService } from "../operations/exchanges"; export class ConfigError extends Error { constructor(message: string) { @@ -56,6 +55,26 @@ export class ConfigValue { } return this.converter(this.val); } + + orUndefined(): T | undefined { + if (this.val !== undefined) { + return this.converter(this.val); + } else { + return undefined; + } + } + + orDefault(v: T): T | undefined { + if (this.val !== undefined) { + return this.converter(this.val); + } else { + return v; + } + } + + isDefined(): boolean { + return this.val !== undefined; + } } /** @@ -197,7 +216,7 @@ export class Configuration { getString(section: string, option: string): ConfigValue { const secNorm = section.toUpperCase(); const optNorm = option.toUpperCase(); - const val = (this.sectionMap[section] ?? {})[optNorm]; + const val = (this.sectionMap[secNorm] ?? {})[optNorm]; return new ConfigValue(secNorm, optNorm, val, (x) => x); } @@ -210,6 +229,36 @@ export class Configuration { ); } + getYesNo(section: string, option: string): ConfigValue { + const secNorm = section.toUpperCase(); + const optNorm = option.toUpperCase(); + const val = (this.sectionMap[secNorm] ?? {})[optNorm]; + const convert = (x: string): boolean => { + x = x.toLowerCase(); + if (x === "yes") { + return true; + } else if (x === "no") { + return false; + } + throw Error(`invalid config value for [${secNorm}]/${optNorm}, expected yes/no`); + }; + return new ConfigValue(secNorm, optNorm, val, convert); + } + + getNumber(section: string, option: string): ConfigValue { + const secNorm = section.toUpperCase(); + const optNorm = option.toUpperCase(); + const val = (this.sectionMap[secNorm] ?? {})[optNorm]; + const convert = (x: string): number => { + try { + return Number.parseInt(x, 10); + } catch (e) { + throw Error(`invalid config value for [${secNorm}]/${optNorm}, expected number`); + } + }; + return new ConfigValue(secNorm, optNorm, val, convert); + } + lookupVariable(x: string, depth: number = 0): string | undefined { // We loop up options in PATHS in upper case, as option names // are case insensitive -- cgit v1.2.3