CliTest.kt (2781B)
1 /* 2 * This file is part of LibEuFin. 3 * Copyright (C) 2023-2025 Taler Systems S.A. 4 5 * LibEuFin is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU Affero General Public License as 7 * published by the Free Software Foundation; either version 3, or 8 * (at your option) any later version. 9 10 * LibEuFin is distributed in the hope that it will be useful, but 11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General 13 * Public License for more details. 14 15 * You should have received a copy of the GNU Affero General Public 16 * License along with LibEuFin; see the file COPYING. If not, see 17 * <http://www.gnu.org/licenses/> 18 */ 19 20 import com.github.ajalt.clikt.core.CliktCommand 21 import com.github.ajalt.clikt.testing.test 22 import tech.libeufin.common.crypto.CryptoUtil 23 import tech.libeufin.common.asUtf8 24 import tech.libeufin.nexus.* 25 import tech.libeufin.ebics.* 26 import tech.libeufin.nexus.cli.LibeufinNexus 27 import java.io.ByteArrayOutputStream 28 import java.io.PrintStream 29 import kotlin.io.path.* 30 import kotlin.test.Test 31 import kotlin.test.assertEquals 32 33 val nexusCmd = LibeufinNexus() 34 35 fun CliktCommand.testErr(cmd: String, msg: String) { 36 val prevOut = System.err 37 val tmpOut = ByteArrayOutputStream() 38 System.setErr(PrintStream(tmpOut)) 39 val result = test(cmd) 40 System.setErr(prevOut) 41 val tmpStr = tmpOut.asUtf8() 42 println(tmpStr) 43 assertEquals(1, result.statusCode, "'$cmd' should have failed") 44 val line = tmpStr.substringAfterLast(" - ").trimEnd('\n') 45 println(line) 46 assertEquals(msg, line) 47 } 48 49 class CliTest { 50 51 /** Test server check */ 52 @Test 53 fun serveCheck() { 54 val confs = listOf( 55 "mini" to 1, 56 "test" to 0 57 ) 58 for ((conf, statusCode) in confs) { 59 val result = nexusCmd.test("serve --check -c conf/$conf.conf") 60 assertEquals(statusCode, result.statusCode) 61 } 62 } 63 64 /** Test list cmds */ 65 @Test 66 fun listCheck() = setup { db, _ -> 67 fun check() { 68 for (list in listOf("incoming", "outgoing", "initiated", "initiated --awaiting-ack")) { 69 val result = nexusCmd.test("list $list -c conf/test.conf") 70 assertEquals(0, result.statusCode) 71 } 72 } 73 // Check empty 74 check() 75 // Check with transactions 76 registerIn(db) 77 registerOut(db) 78 check() 79 // Check with taler transactions 80 talerableOut(db) 81 talerableIn(db) 82 talerableKycIn(db) 83 check() 84 // Check with incomplete 85 registerIncompleteIn(db) 86 talerableIncompleteIn(db) 87 registerIncompleteOut(db) 88 check() 89 } 90 }