Skip to content

Commit 52bfb91

Browse files
committed
Make the test work w/ non-default hooks directory
By default the hook is expected to locate in /usr/share/containers/oci/hooks.d However, "make install" uses the prefix /usr/local as default. This change enables "make test-integration" to work in this situation.
1 parent 898f7b1 commit 52bfb91

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ test-integration:
6464
@echo
6565
@echo "==> Running integration tests (must be run as root)"
6666
./hack/check_root.sh
67-
bats $(BATS_OPTS) test/
67+
env HOOKS_DIR=$(HOOK_DIR) bats $(BATS_OPTS) test/
6868

6969
.PHONY: test-unit
7070
test-unit:

test/00-simple.bats

+7-7
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ load helpers
3131
tmpFile=$(mktemp)
3232
echo "Temporary file: ${tmpFile}"
3333

34-
run podman run --net=host --annotation io.containers.trace-syscall=of:${tmpFile} ${ALPINE} ls
34+
run podman run --net=host $HOOKS_DIR_OPT --annotation io.containers.trace-syscall=of:${tmpFile} ${ALPINE} ls
3535
echo "Podman output: ${lines[*]}"
3636
[ "$status" -eq 0 ]
3737
# sleep two seconds to let the hook finish writing the file
@@ -49,7 +49,7 @@ load helpers
4949
tmpFile=$(mktemp)
5050
echo "Temporary file: ${tmpFile}"
5151

52-
run podman run --net=host --annotation io.containers.trace-syscall=of:${tmpFile} ${ALPINE} ls
52+
run podman run --net=host $HOOKS_DIR_OPT --annotation io.containers.trace-syscall=of:${tmpFile} ${ALPINE} ls
5353
echo "Podman output: ${lines[*]}"
5454
[ "$status" -eq 0 ]
5555
# sleep two seconds to let the hook finish writing the file
@@ -71,7 +71,7 @@ load helpers
7171
tmpFile=$(mktemp)
7272
echo "Temporary file: ${tmpFile}"
7373

74-
run podman run --net=host --annotation io.containers.trace-syscall=of:${tmpFile} ${ALPINE} ls
74+
run podman run --net=host $HOOKS_DIR_OPT --annotation io.containers.trace-syscall=of:${tmpFile} ${ALPINE} ls
7575
echo "Podman output: ${lines[*]}"
7676
[ "$status" -eq 0 ]
7777
# sleep two seconds to let the hook finish writing the file
@@ -100,7 +100,7 @@ load helpers
100100
echo "Temporary file 1: ${tmpFile1}"
101101
echo "Temporary file 2: ${tmpFile2}"
102102

103-
run podman run --net=host --annotation io.containers.trace-syscall=of:${tmpFile1} ${ALPINE} ls /
103+
run podman run --net=host $HOOKS_DIR_OPT --annotation io.containers.trace-syscall=of:${tmpFile1} ${ALPINE} ls /
104104
[ "$status" -eq 0 ]
105105
# sleep two seconds to let the hook finish writing the file
106106
sleep 2
@@ -113,7 +113,7 @@ load helpers
113113
echo "Podman output: ${lines[*]}"
114114
[ "$status" -ne 0 ]
115115

116-
run podman run --net=host --annotation io.containers.trace-syscall="if:${tmpFile1};of:${tmpFile2}" ${ALPINE} ping -c3 $PINGABLE_HOST
116+
run podman run --net=host $HOOKS_DIR_OPT --annotation io.containers.trace-syscall="if:${tmpFile1};of:${tmpFile2}" ${ALPINE} ping -c3 $PINGABLE_HOST
117117
echo "Podman output: ${lines[*]}"
118118
[ "$status" -eq 0 ]
119119
sleep 2 # sleep two seconds to let the hook finish writing the file
@@ -138,7 +138,7 @@ load helpers
138138
tmpFile=$(mktemp)
139139
echo "Temporary file : ${tmpFile}"
140140

141-
run podman run --net=host --annotation io.containers.trace-syscall=of:${tmpFile} ${ALPINE} mkdir /foo
141+
run podman run --net=host $HOOKS_DIR_OPT --annotation io.containers.trace-syscall=of:${tmpFile} ${ALPINE} mkdir /foo
142142
echo "Podman output: ${lines[*]}"
143143
[ "$status" -eq 0 ]
144144
# sleep two seconds to let the hook finish writing the file
@@ -152,7 +152,7 @@ load helpers
152152
echo "Podman output: ${lines[*]}"
153153
[ "$status" -eq 0 ]
154154

155-
run podman run --net=host --annotation io.containers.trace-syscall="if:${BLOCK_MKDIR};of:${tmpFile}" ${ALPINE} mkdir /foo
155+
run podman run --net=host $HOOKS_DIR_OPT --annotation io.containers.trace-syscall="if:${BLOCK_MKDIR};of:${tmpFile}" ${ALPINE} mkdir /foo
156156
echo "Podman output: ${lines[*]}"
157157
[ "$status" -eq 0 ]
158158
# sleep two seconds to let the hook finish writing the file

test/01-syslog.bats

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ load helpers
1111
tmpFile=$(mktemp)
1212
echo "Temporary file: ${tmpFile}"
1313

14-
run podman run --net=host --annotation io.containers.trace-syscall=of:${tmpFile} ${ALPINE} ls
14+
run podman run --net=host $HOOKS_DIR_OPT --annotation io.containers.trace-syscall=of:${tmpFile} ${ALPINE} ls
1515
echo "Podman output: ${lines[*]}"
1616
[ "$status" -eq 0 ]
1717
# sleep two seconds to let the hook finish writing the file

test/helpers.bash

+6
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ BLOCK_MKDIR=$(realpath $(dirname ${BASH_SOURCE[0]})/fixtures/block-mkdir.json)
33

44
# Hostname that should be ping'able from any environment in which we run tests
55
PINGABLE_HOST=github.com
6+
7+
# Without giving HOOKS_DIR, the option will not appear, which avoids writing
8+
# default hooks directory in the command.
9+
if [ ! -z $HOOKS_DIR ]; then
10+
HOOKS_DIR_OPT="--hooks-dir=$HOOKS_DIR"
11+
fi

0 commit comments

Comments
 (0)