Skip to content

Commit d0aec23

Browse files
committed
tests: generalise rootless runner
This is necessary in order to add proper opportunistic tests, and is a placeholder until we add tests for new{uid,gid}map configurations. Signed-off-by: Aleksa Sarai <[email protected]>
1 parent 1a5fdc1 commit d0aec23

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,10 @@ localintegration: all
7777
bats -t tests/integration${TESTFLAGS}
7878

7979
rootlessintegration: runcimage
80-
docker run -e TESTFLAGS -t --privileged --rm -v $(CURDIR):/go/src/$(PROJECT) --cap-drop=ALL -u rootless $(RUNC_IMAGE) make localintegration
80+
docker run -e TESTFLAGS -t --privileged --rm -v $(CURDIR):/go/src/$(PROJECT) $(RUNC_IMAGE) make localrootlessintegration
8181

82-
# FIXME: This should not be separate from rootlessintegration's method of running.
8382
localrootlessintegration: all
84-
sudo -u rootless -H PATH="${PATH}" bats -t tests/integration${TESTFLAGS}
83+
tests/rootless.sh
8584

8685
shell: all
8786
docker run -e TESTFLAGS -ti --privileged --rm -v $(CURDIR):/go/src/$(PROJECT) $(RUNC_IMAGE) bash

tests/rootless.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
# Copyright (C) 2017 SUSE LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# rootless.sh -- Runner for rootless container tests. The purpose of this
17+
# script is to allow for the addition (and testing) of "opportunistic" features
18+
# to rootless containers while still testing the base features. In order to add
19+
# a new feature, please match the existing style. Add an entry to $ALL_FEATURES,
20+
# and add an enable_* and disable_* hook.
21+
22+
ALL_FEATURES=()
23+
ROOT="$(readlink -f "$(dirname "${BASH_SOURCE}")/..")"
24+
25+
# Create a powerset of $ALL_FEATURES (the set of all subsets of $ALL_FEATURES).
26+
# We test all of the possible combinations (as long as we don't add too many
27+
# feature knobs this shouldn't take too long -- but the number of tested
28+
# combinations is O(2^n)).
29+
function powerset() {
30+
eval printf '%s' $(printf '{,%s+}' "$@"):
31+
}
32+
features_powerset="$(powerset "${ALL_FEATURES[@]}")"
33+
34+
# Iterate over the powerset of all features.
35+
IFS=:
36+
for enabled_features in $features_powerset
37+
do
38+
idx="$(($idx+1))"
39+
echo "[$(printf '%.2d' "$idx")] run rootless tests ... (${enabled_features%%+})"
40+
41+
unset IFS
42+
for feature in "${ALL_FEATURES[@]}"
43+
do
44+
hook_func="disable_$feature"
45+
grep -E "(^|\+)$feature(\+|$)" <<<$enabled_features &>/dev/null && hook_func="enable_$feature"
46+
"$hook_func"
47+
done
48+
49+
# Run the test suite!
50+
set -e
51+
echo path: $PATH
52+
export ROOTLESS_FEATURES="$enabled_features"
53+
sudo -HE -u rootless PATH="$PATH" bats -t "$ROOT/tests/integration"
54+
set +e
55+
done

0 commit comments

Comments
 (0)