Skip to content

Commit

Permalink
tests: Check if the artifactsdir is created correctly
Browse files Browse the repository at this point in the history
Check if the common files in the artifactsdir is created by each
scan. This includes a fix to the temporary directory. The code in
setup_suite appearently did't work… :)
  • Loading branch information
rumpelsepp committed Aug 19, 2024
1 parent f0311a2 commit f5780ad
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
8 changes: 8 additions & 0 deletions tests/bats/002-scans.bats
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ setup_file() {
setup_gallia_toml
}

setup() {
common_setup
}

teardown() {
check_artifactsdir "$BATS_TMPDIR"/gallia/*/run-*
}

@test "scan services" {
gallia scan uds services --sessions 1 2 --check-session
}
Expand Down
8 changes: 8 additions & 0 deletions tests/bats/003-primitives.bats
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ setup_file() {
setup_gallia_toml
}

setup() {
common_setup
}

teardown() {
check_artifactsdir "$BATS_TMPDIR"/gallia/*/run-*
}

@test "primitive ecu-reset" {
gallia primitive uds ecu-reset
}
Expand Down
26 changes: 26 additions & 0 deletions tests/bats/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
#
# SPDX-License-Identifier: Apache-2.0

common_setup() {
# https://bats-core.readthedocs.io/en/stable/tutorial.html#let-s-do-some-setup
DIR="$(cd "$(dirname "$BATS_TEST_FILENAME")" >/dev/null 2>&1 && pwd)"
PATH="$DIR/..:$PATH"

cd "$BATS_TEST_TMPDIR" || exit 1
}

setup_gallia_toml() {
{
echo "[gallia]"
Expand All @@ -24,3 +32,21 @@ rm_gallia_toml() {
rm -f "$GALLIA_CONFIG"
fi
}

check_artifactsdir() {
# There is only one (tm) artifactsdir per run.
local artifactsdir
artifactsdir="$1"

if [[ ! -r "$artifactsdir/log.json.zst" ]]; then
return 1
fi

if [[ ! -r "$artifactsdir/META.json" ]]; then
return 1
fi

if [[ ! -r "$artifactsdir/ENV" ]]; then
return 1
fi
}
6 changes: 0 additions & 6 deletions tests/bats/setup_suite.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,4 @@

setup_suite() {
bats_require_minimum_version 1.8.0

# https://bats-core.readthedocs.io/en/stable/tutorial.html#let-s-do-some-setup
DIR="$(cd "$(dirname "$BATS_TEST_FILENAME")" >/dev/null 2>&1 && pwd)"
PATH="$DIR/..:$PATH"

cd "$BATS_TEST_TMPDIR" || exit 1
}

0 comments on commit f5780ad

Please sign in to comment.