Add tests and typo fixes (#2092)

This commit is contained in:
mmetc 2023-03-03 11:06:27 +01:00 committed by GitHub
parent ef4e61e05e
commit f6d6c5bb2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 5 deletions

View file

@ -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 <random-key>`,
Args: cobra.ExactArgs(1),
DisableAutoGenTag: true,
RunE: runBouncersAdd,

View file

@ -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)")

View file

@ -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

View file

@ -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)