Skip to content

Commit

Permalink
merge cli flags after hot reload: add coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Lenka Segura <lsegura@redhat.com>
  • Loading branch information
LenkaSeg committed Dec 23, 2024
1 parent 9876ee4 commit 01deb37
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 13 deletions.
7 changes: 7 additions & 0 deletions internal/criocli/criocli.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package criocli
import (
"errors"
"fmt"
"strings"
"time"

"github.com/urfave/cli/v2"

Expand Down Expand Up @@ -827,3 +829,8 @@ func getCrioFlags(defConf *libconfig.Config) []cli.Flag {
},
}
}

// Timestamp returns a string timestamp representation.
func Timestamp() string {
return strings.ReplaceAll(time.Now().Format(time.RFC3339), ":", "")
}
23 changes: 23 additions & 0 deletions test/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,29 @@ function start_crio() {
check_images
}

function start_crio_no_cli() {
"$CRIO_BINARY_PATH" \
--default-mounts-file "$TESTDIR/containers/mounts.conf" \
-c "$CRIO_CONFIG" \
-d "$CRIO_CONFIG_DIR" \
&>"$CRIO_LOG" &
CRIO_PID=$!
wait_until_reachable
}

# Start crio.
# shellcheck disable=SC2120
function start_crio_no_log_level() {
echo "is there a crio process?"
if [[ $(pgrep crio) ]]; then
# kill previous process not to interfere with the start_crio_no_cli
sudo kill -9 $(pgrep crio)
fi
setup_crio "$@"
start_crio_no_cli
check_images
}

# Check if journald is supported by runtime.
function check_journald() {
"$CONMON_BINARY" \
Expand Down
17 changes: 4 additions & 13 deletions test/reload_config.bats
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,17 @@ function expect_log_failure() {
ps --pid "$CRIO_PID" &> /dev/null
}

@test "reload config should succeed with 'log_level'" {
@test "log_level set via command line remains after reload" {
# given
NEW_LEVEL="warn"
CONFIG_LEVEL="warn"
OPTION="log_level"

# when
replace_config $OPTION $NEW_LEVEL
replace_config $OPTION $CONFIG_LEVEL
reload_crio

# then
expect_log_success $OPTION $NEW_LEVEL
}

@test "reload config should fail with 'log_level' if invalid" {
# when
replace_config "log_level" "invalid"
reload_crio

# then
expect_log_failure "not a valid logrus Level"
wait_for_log 'FLAG: --log-level=\\"debug\\"'
}

@test "reload config should fail with if config is malformed" {
Expand Down
48 changes: 48 additions & 0 deletions test/reload_config_options.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bats
# vim: set syntax=sh:

load helpers

function setup() {
setup_test
start_crio_no_log_level

# the default log_level is `error` so we have to adapt it before running
# any tests to be able to see the `info` messages
replace_config "log_level" "debug"
}

function teardown() {
rm -f "$CRIO_CONFIG_DIR/00-new*Runtime.conf"
cleanup_test
}

function expect_log_success() {
wait_for_log '"set config '"$1"' to \\"'"$2"'\\""'
}

function expect_log_failure() {
wait_for_log "unable to reload configuration: $1"
}

@test "reload config should succeed with 'log_level'" {
# given
NEW_LEVEL="warn"
OPTION="log_level"

# when
replace_config $OPTION $NEW_LEVEL
reload_crio

# then
expect_log_success $OPTION $NEW_LEVEL
}

@test "reload config should fail with 'log_level' if invalid" {
# when
replace_config "log_level" "invalid"
reload_crio

# then
expect_log_failure "not a valid logrus Level"
}

0 comments on commit 01deb37

Please sign in to comment.