From a8f24fef43581c42c2d4336c2a22f141ce5a86cd Mon Sep 17 00:00:00 2001 From: Lucas Hinderberger Date: Wed, 3 Jul 2024 10:04:37 +0200 Subject: [PATCH] Adding keep-running flag --- README.md | 5 +++++ api_testsuite.go | 17 +++++++++++++++++ main.go | 12 ++++++++---- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4535f3e7..151cd3cb 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,11 @@ This starts the command with the following default settings: - `stop-on-fail`: Stop execution of later test suites if a test suite fails +### Keep running + +- `keep-running`: Wait for a keyboard interrupt after each test suite invocation. + This can be useful for keeping the HTTP / SMTP server for manual inspection. + ### Configure logging Per default request and response of a request will be logged on test failure. If you want to see more information you diff --git a/api_testsuite.go b/api_testsuite.go index 864f42cb..003758a9 100644 --- a/api_testsuite.go +++ b/api_testsuite.go @@ -7,6 +7,7 @@ import ( "net/http" "net/url" "os" + "os/signal" "path/filepath" "strconv" "sync" @@ -230,6 +231,22 @@ func (ats *Suite) Run() bool { } } + if keepRunning { // flag defined in main.go + logrus.Info("Waiting until a keyboard interrupt (usually CTRL+C) is received...") + + if ats.HttpServer != nil { + logrus.Info("HTTP Server URL:", ats.HttpServer.Addr) + } + if ats.SmtpServer != nil { + logrus.Info("SMTP Server URL:", ats.SmtpServer.Addr) + } + + sigChan := make(chan os.Signal, 1) + signal.Notify(sigChan, os.Interrupt) + + <-sigChan + } + return success } diff --git a/main.go b/main.go index 1b761678..8a3a469b 100644 --- a/main.go +++ b/main.go @@ -17,10 +17,10 @@ import ( ) var ( - reportFormat, reportFile, serverURL, httpServerReplaceHost string - logNetwork, logDatastore, logVerbose, logTimeStamp, logShort, logCurl, stopOnFail bool - rootDirectorys, singleTests []string - limitRequest, limitResponse, reportStatsGroups uint + reportFormat, reportFile, serverURL, httpServerReplaceHost string + keepRunning, logNetwork, logDatastore, logVerbose, logTimeStamp, logShort, logCurl, stopOnFail bool + rootDirectorys, singleTests []string + limitRequest, limitResponse, reportStatsGroups uint // set via -ldflags during build buildCommit, buildTime, buildVersion string ) @@ -85,6 +85,10 @@ func init() { &logCurl, "curl-bash", false, "Log network output as bash curl command") + testCMD.PersistentFlags().BoolVar( + &keepRunning, "keep-running", false, + "Before returning from each test suite, prompt for a keyboard interrupt") + testCMD.PersistentFlags().BoolVar( &stopOnFail, "stop-on-fail", false, "Stop execution of later test suites if a test suite fails")