Skip to content

Commit feb798c

Browse files
committed
added bats test for ldcache
1 parent 668356a commit feb798c

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tests/test_ldcache_hook.bats

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
setup() {
2+
RUNTIME="${RUNTIME:-crun}"
3+
TEST_IMAGE="${TEST_IMAGE:-ubuntu:20.04}"
4+
5+
TMP_HOOKS_DIR="$(mktemp -d)"
6+
TMP_HOOK_LOG_DIR="$(mktemp -d)"
7+
HOOK_OUT="${TMP_HOOK_LOG_DIR}/out.log"
8+
HOOK_ERR="${TMP_HOOK_LOG_DIR}/err.log"
9+
10+
cat > "${TMP_HOOKS_DIR}/02-ldcache.json" <<'EOF'
11+
{
12+
"version": "1.0.0",
13+
"hook": {
14+
"path": "/opt/sarus/bin/ldcache_hook",
15+
"env": ["LDCONFIG_PATH=/sbin/ldconfig"]
16+
},
17+
"stages": ["createContainer"]
18+
}
19+
EOF
20+
}
21+
22+
teardown() {
23+
rm -rf "${TMP_HOOKS_DIR}" "${TMP_HOOK_LOG_DIR}"
24+
}
25+
26+
helper_run_hooked_podman() {
27+
# cleanup hook output
28+
: > "${HOOK_OUT}"
29+
: > "${HOOK_ERR}"
30+
31+
# run hook with debug output
32+
podman --runtime="${RUNTIME}" \
33+
--hooks-dir "${TMP_HOOKS_DIR}" \
34+
run --rm \
35+
--annotation com.hooks.logging.level=0 \
36+
--annotation run.oci.hooks.stdout="${HOOK_OUT}" \
37+
--annotation run.oci.hooks.stderr="${HOOK_ERR}" \
38+
"${TEST_IMAGE}" bash -lc "$1"
39+
}
40+
41+
@test "hook runs and generates debug logs" {
42+
run helper_run_hooked_podman 'true'
43+
[ "$status" -eq 0 ]
44+
[ -s "$HOOK_OUT" ]
45+
}
46+
47+
#@test "/etc/ld.so.cache exists after hook" {
48+
# # TODO: can we validate that ld.so.cache was recently updated? idea: inject a lib and then see it in hook log
49+
# run helper_run_hooked_podman 'true'
50+
# [ "$status" -eq 0 ]
51+
#}

0 commit comments

Comments
 (0)