瀏覽代碼

Add tests and typo fixes (#2092)

mmetc 2 年之前
父節點
當前提交
f6d6c5bb2b

+ 2 - 2
cmd/crowdsec-cli/bouncers.go

@@ -128,9 +128,9 @@ func NewBouncersAddCmd() *cobra.Command {
 		Use:   "add MyBouncerName [--length 16]",
 		Use:   "add MyBouncerName [--length 16]",
 		Short: "add bouncer",
 		Short: "add bouncer",
 		Long:  `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 -l 24
-cscli bouncers add MyBouncerName -k %s`, generatePassword(32)),
+cscli bouncers add MyBouncerName -k <random-key>`,
 		Args:              cobra.ExactArgs(1),
 		Args:              cobra.ExactArgs(1),
 		DisableAutoGenTag: true,
 		DisableAutoGenTag: true,
 		RunE: runBouncersAdd,
 		RunE: runBouncersAdd,

+ 1 - 1
cmd/crowdsec-cli/machines.go

@@ -196,7 +196,7 @@ cscli machines add MyTestMachine --password MyPassword
 
 
 	flags := cmdMachinesAdd.Flags()
 	flags := cmdMachinesAdd.Flags()
 	flags.StringP("password", "p", "", "machine password to login to the API")
 	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.StringP("url", "u", "", "URL of the local API")
 	flags.BoolP("interactive", "i", false, "interfactive mode to enter the password")
 	flags.BoolP("interactive", "i", false, "interfactive mode to enter the password")
 	flags.BoolP("auto", "a", false, "automatically generate password (and username if not provided)")
 	flags.BoolP("auto", "a", false, "automatically generate password (and username if not provided)")

+ 1 - 1
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.WriteHeader(http.StatusOK)
 	gctx.Writer.Write([]byte(`{"new": [`)) //No need to check for errors, the doc says it always returns nil
 	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" {
 	if val, ok := gctx.Request.URL.Query()["startup"]; ok && val[0] == "true" {
 		//Active decisions
 		//Active decisions
 
 

+ 12 - 1
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
     # we reset config and data, and only run the daemon once for all the tests in this file
     ./instance-data load
     ./instance-data load
     ./instance-crowdsec start
     ./instance-crowdsec start
-    fake_log | "${CROWDSEC}" -dsn file:///dev/fd/0 -type syslog -no-api 2>/dev/null
 }
 }
 
 
 teardown_file() {
 teardown_file() {
@@ -35,6 +34,18 @@ setup() {
     assert_stderr --partial "-dsn requires a -type argument"
     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" {
 @test "we have one decision" {
     rune -0 cscli decisions list -o json
     rune -0 cscli decisions list -o json
     rune -0 jq '. | length' <(output)
     rune -0 jq '. | length' <(output)