From f6d6c5bb2b9ce8705cabcb4cfb67cded0e829014 Mon Sep 17 00:00:00 2001 From: mmetc <92726601+mmetc@users.noreply.github.com> Date: Fri, 3 Mar 2023 11:06:27 +0100 Subject: [PATCH] Add tests and typo fixes (#2092) --- cmd/crowdsec-cli/bouncers.go | 4 ++-- cmd/crowdsec-cli/machines.go | 2 +- pkg/apiserver/controllers/v1/decisions.go | 2 +- tests/bats/40_cold-logs.bats | 13 ++++++++++++- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/cmd/crowdsec-cli/bouncers.go b/cmd/crowdsec-cli/bouncers.go index f62b982f0..3d751ebf5 100644 --- a/cmd/crowdsec-cli/bouncers.go +++ b/cmd/crowdsec-cli/bouncers.go @@ -128,9 +128,9 @@ func NewBouncersAddCmd() *cobra.Command { Use: "add MyBouncerName [--length 16]", Short: "add bouncer", Long: `add bouncer`, - Example: fmt.Sprintf(`cscli bouncers add MyBouncerName + Example: `cscli bouncers add MyBouncerName cscli bouncers add MyBouncerName -l 24 -cscli bouncers add MyBouncerName -k %s`, generatePassword(32)), +cscli bouncers add MyBouncerName -k `, Args: cobra.ExactArgs(1), DisableAutoGenTag: true, RunE: runBouncersAdd, diff --git a/cmd/crowdsec-cli/machines.go b/cmd/crowdsec-cli/machines.go index 09c01b964..95189252b 100644 --- a/cmd/crowdsec-cli/machines.go +++ b/cmd/crowdsec-cli/machines.go @@ -196,7 +196,7 @@ cscli machines add MyTestMachine --password MyPassword flags := cmdMachinesAdd.Flags() flags.StringP("password", "p", "", "machine password to login to the API") - flags.StringP("file", "f", "", "output file destination (defaults to "+csconfig.DefaultConfigPath("local_api_credentials.yaml")) + flags.StringP("file", "f", "", "output file destination (defaults to "+csconfig.DefaultConfigPath("local_api_credentials.yaml")+")") flags.StringP("url", "u", "", "URL of the local API") flags.BoolP("interactive", "i", false, "interfactive mode to enter the password") flags.BoolP("auto", "a", false, "automatically generate password (and username if not provided)") diff --git a/pkg/apiserver/controllers/v1/decisions.go b/pkg/apiserver/controllers/v1/decisions.go index 24aac198b..902d5384e 100644 --- a/pkg/apiserver/controllers/v1/decisions.go +++ b/pkg/apiserver/controllers/v1/decisions.go @@ -233,7 +233,7 @@ func (c *Controller) StreamDecisionChunked(gctx *gin.Context, bouncerInfo *ent.B gctx.Writer.WriteHeader(http.StatusOK) gctx.Writer.Write([]byte(`{"new": [`)) //No need to check for errors, the doc says it always returns nil - // if the blocker just start, return all decisions + // if the blocker just started, return all decisions if val, ok := gctx.Request.URL.Query()["startup"]; ok && val[0] == "true" { //Active decisions diff --git a/tests/bats/40_cold-logs.bats b/tests/bats/40_cold-logs.bats index bc8d927ca..ad4d5233c 100644 --- a/tests/bats/40_cold-logs.bats +++ b/tests/bats/40_cold-logs.bats @@ -15,7 +15,6 @@ setup_file() { # we reset config and data, and only run the daemon once for all the tests in this file ./instance-data load ./instance-crowdsec start - fake_log | "${CROWDSEC}" -dsn file:///dev/fd/0 -type syslog -no-api 2>/dev/null } teardown_file() { @@ -35,6 +34,18 @@ setup() { assert_stderr --partial "-dsn requires a -type argument" } +@test "the one-shot mode works" { + rune -0 "${CROWDSEC}" -dsn file://<(fake_log) -type syslog -no-api + refute_output + assert_stderr --partial "single file mode : log_media=stdout daemonize=false" + assert_stderr --regexp "Adding file .* to filelist" + assert_stderr --regexp "reading .* at once" + assert_stderr --regexp "Acquisition is finished, shutting down" + assert_stderr --regexp "Killing parser routines" + assert_stderr --regexp "Bucket routine exiting" + assert_stderr --regexp "crowdsec shutdown" +} + @test "we have one decision" { rune -0 cscli decisions list -o json rune -0 jq '. | length' <(output)