fix bats-test for freebsd (#1333)

This commit is contained in:
mmetc 2022-03-10 12:19:02 +01:00 committed by GitHub
parent c077668511
commit 0c35263c29
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 21 additions and 20 deletions

View file

@ -97,15 +97,15 @@ declare stderr
}
@test "$FILE cscli config backup" {
tempdir=$(mktemp -u -p "${BATS_TEST_TMPDIR}")
run -0 cscli config backup "${tempdir}"
backupdir=$(TMPDIR="${BATS_TEST_TMPDIR}" mktemp -u)
run -0 cscli config backup "${backupdir}"
assert_output --partial "Starting configuration backup"
run -1 --separate-stderr cscli config backup "${tempdir}"
run -1 --separate-stderr cscli config backup "${backupdir}"
run -0 echo "$stderr"
assert_output --partial "Failed to backup configurations"
assert_output --partial "file exists"
rm -rf -- "${tempdir:?}"
rm -rf -- "${backupdir:?}"
}
@test "$FILE cscli lapi status" {

View file

@ -61,11 +61,11 @@ declare stderr
@test "$FILE cscli config backup" {
yq 'del(.api.server)' -i "${CONFIG_DIR}/config.yaml"
tempdir=$(mktemp -u -p "${BATS_TEST_TMPDIR}")
run -0 cscli config backup "${tempdir}"
backupdir=$(TMPDIR="${BATS_TEST_TMPDIR}" mktemp -u)
run -0 cscli config backup "${backupdir}"
assert_output --partial "Starting configuration backup"
run -1 --separate-stderr cscli config backup "${tempdir}"
rm -rf -- "${tempdir:?}"
run -1 --separate-stderr cscli config backup "${backupdir}"
rm -rf -- "${backupdir:?}"
run -0 echo "$stderr"
assert_output --partial "Failed to backup configurations"

View file

@ -66,15 +66,15 @@ config_disable_agent() {
@test "$FILE no agent: cscli config backup" {
config_disable_agent
tempdir=$(mktemp -u -p "${BATS_TEST_TMPDIR}")
run -0 cscli config backup "${tempdir}"
backupdir=$(TMPDIR="${BATS_TEST_TMPDIR}" mktemp -u)
run -0 cscli config backup "${backupdir}"
assert_output --partial "Starting configuration backup"
run -1 --separate-stderr cscli config backup "${tempdir}"
run -1 --separate-stderr cscli config backup "${backupdir}"
run -0 echo "$stderr"
assert_output --partial "Failed to backup configurations"
assert_output --partial "file exists"
rm -rf -- "${tempdir:?}"
rm -rf -- "${backupdir:?}"
}
@test "$FILE no agent: lapi status should be ok" {

View file

@ -57,15 +57,15 @@ config_disable_capi() {
@test "$FILE no agent: cscli config backup" {
config_disable_capi
tempdir=$(mktemp -u -p "${BATS_TEST_TMPDIR}")
run -0 cscli config backup "${tempdir}"
backupdir=$(TMPDIR="${BATS_TEST_TMPDIR}" mktemp -u)
run -0 cscli config backup "${backupdir}"
assert_output --partial "Starting configuration backup"
run -1 --separate-stderr cscli config backup "${tempdir}"
run -1 --separate-stderr cscli config backup "${backupdir}"
run -0 echo "$stderr"
assert_output --partial "Failed to backup configurations"
assert_output --partial "file exists"
rm -rf -- "${tempdir:?}"
rm -rf -- "${backupdir:?}"
}
@test "$FILE without capi: cscli lapi status -> success" {

View file

@ -30,7 +30,7 @@ teardown() {
#----------
@test "$FILE 1.1.1.172 has been banned" {
tmpfile=$(mktemp -p "${BATS_TEST_TMPDIR}")
tmpfile=$(TMPDIR="${BATS_TEST_TMPDIR}" mktemp)
touch "${tmpfile}"
echo -e "---\nfilename: $tmpfile\nlabels:\n type: syslog\n" >>"${CONFIG_DIR}/acquis.yaml"

View file

@ -28,7 +28,7 @@ fi
wait_for_port() {
for _ in $(seq 40); do
nc -z localhost "$1" && return
nc -z localhost "$1" >/dev/null 2>&1 && return
sleep .05
done
@ -59,7 +59,8 @@ stop_instance() {
if [ -f "${DAEMON_PID}" ]; then
# terminate quickly with extreme prejudice, all the application data will be
# thrown away anyway. also terminate the child processes (notification plugin).
PGID="$(ps --no-headers -p "$(cat "${DAEMON_PID}")" -o pgid | tr -d ' ')"
PGID="$(ps -o pgid= -p "$(cat "${DAEMON_PID}")" | tr -d ' ')"
# ps above should work on linux, freebsd, busybox..
if [ -n "${PGID}" ]; then
kill -- "-${PGID}"
fi

View file

@ -20,7 +20,7 @@ check_requirements() {
fi
if ! command -v yq >/dev/null; then
die "missing required program 'yq'. You can install it with 'GO111MODULE=on go get github.com/mikefarah/yq/v4'"
die "missing required program 'yq'. You can install it with 'GO111MODULE=on go get github.com/mikefarah/yq/v4' and add ~/go/bin to $PATH"
fi
SYSTEM=$(uname -s)