|
| 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