libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

CliExitTest.kt (1793B)


      1 /*
      2  * This file is part of LibEuFin.
      3  * Copyright (C) 2026 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.ProgramResult
     21 import com.github.ajalt.clikt.testing.test
     22 import org.slf4j.LoggerFactory
     23 import tech.libeufin.common.TalerCmd
     24 import tech.libeufin.common.TalerConfigError
     25 import java.net.ConnectException
     26 import kotlin.test.Test
     27 import kotlin.test.assertEquals
     28 
     29 class CliExitTest {
     30     private fun status(failure: Throwable): Int {
     31         val cmd = object : TalerCmd("exit-test") {
     32             override fun run() = cliCmd(LoggerFactory.getLogger("exit-test")) {
     33                 throw failure
     34             }
     35         }
     36         return cmd.test("").statusCode
     37     }
     38 
     39     @Test
     40     fun configurationFailureStopsService() {
     41         assertEquals(6, status(TalerConfigError.generic("Missing service configuration")))
     42     }
     43 
     44     @Test
     45     fun dependencyOutageCanRestart() {
     46         assertEquals(1, status(ConnectException("Connection refused")))
     47     }
     48 
     49     @Test
     50     fun explicitResultsSurvive() {
     51         for (code in listOf(0, 1, 6, 9)) {
     52             assertEquals(code, status(ProgramResult(code)))
     53         }
     54     }
     55 }