Skip to content

Commit 9848a7c

Browse files
committed
test/config: fix "config dir should fail with invalid option"
Sometimes this test fails like this: > not ok 11 config dir should fail with invalid option > (in test file ./config.bats, line 38) > `RES=$(cat "$CRIO_LOG")' failed > cat: /tmp/tmp.nho2aP6lqh/crio.log: No such file or directory > unable to decode configuration /tmp/tmp.nho2aP6lqh/crio.conf: Near line 2 (last key parsed 'crio.runtime.log_level'): expected value but found "info" instead The reason it fails is logs are written by using tee, which for some reason is run in a subshell, and it looks like a race between the main shell and the subshell. Anyway, using tee is not needed here. Simplify it by using run, and add a check for non-zero exit code. The second problem is, the test is not doing what it supposed to. Judging by the test name ("config dir should fail"), it seems the test should write a correct log_level value to the main config file, a wrong value to a file under crio.conf.d, and check that crio fails. The problem is, the value in main file is wrong as well it is not quoted. Fix the test so the main config file has the correct log_level value. Fix the output check to look for the specific bad key. Signed-off-by: Kir Kolyshkin <[email protected]> (cherry picked from commit 94ef42c) Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 48efb10 commit 9848a7c

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

test/config.bats

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ function teardown() {
3030

3131
@test "config dir should fail with invalid option" {
3232
# given
33-
printf "[crio.runtime]\nlog_level = info\n" > "$CRIO_CONFIG"
34-
printf "[crio.runtime]\nlog_level = wrong\n" > "$CRIO_CONFIG_DIR"/00-default
33+
printf '[crio.runtime]\nlog_level = "info"\n' > "$CRIO_CONFIG"
34+
printf '[crio.runtime]\nlog_level = "wrong-level"\n' > "$CRIO_CONFIG_DIR"/00-default
3535

3636
# when
37-
"$CRIO_BINARY_PATH" -c "$CRIO_CONFIG" -d "$CRIO_CONFIG_DIR" &> >(tee "$CRIO_LOG") || true
38-
RES=$(cat "$CRIO_LOG")
37+
run "$CRIO_BINARY_PATH" -c "$CRIO_CONFIG" -d "$CRIO_CONFIG_DIR"
3938

4039
# then
41-
[[ "$RES" =~ "unable to decode configuration" ]]
40+
[ "$status" -ne 0 ]
41+
[[ "$output" == *"not a valid logrus"*"wrong-level"* ]]
4242
}

0 commit comments

Comments
 (0)