github.com/opencontainers/umoci@v0.4.8-0.20240508124516-656e4836fb0d/hack/test-integration.sh (about) 1 #!/bin/bash 2 # umoci: Umoci Modifies Open Containers' Images 3 # Copyright (C) 2016-2020 SUSE LLC 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 set -Eeuxo pipefail 18 source "$(dirname "$BASH_SOURCE")/readlinkf.sh" 19 20 export ROOT="$(readlinkf_posix "$(dirname "$BASH_SOURCE")/..")" 21 22 # Set up the coverage directory. 23 COVERAGE="${COVERAGE:-}" 24 25 # -coverprofile= truncates the target file, so we need to create a 26 # temporary file for each execution of the coverage-generating umoci 27 # binary, which will then be collated after all the tests are run. 28 export COVERAGE_DIR="$(mktemp -dt umoci-coverage.XXXXXX)" 29 30 # Create a temporary symlink for umoci, since the --help tests require the 31 # binary have the name "umoci". This is all just to make the Makefile and 32 # test/helpers.bash nicer. 33 UMOCI_DIR="$(mktemp -dt umoci.XXXXXX)" 34 export UMOCI="$UMOCI_DIR/umoci" 35 ln -s "$ROOT/umoci.cover" "$UMOCI" 36 37 # TODO: This really isn't that nice of an interface... 38 tests=() 39 if [[ -z "$TESTS" ]] 40 then 41 tests=("$ROOT/test/"*.bats) 42 else 43 for f in $TESTS; do 44 tests+=("$ROOT/test/$f.bats") 45 done 46 fi 47 48 # Run the tests. 49 bats --jobs "+8" --tap "${tests[@]}" 50 51 if [ -n "${TRAVIS:-}" ] 52 then 53 coverage_tags=integration 54 [[ "$(id -u)" == 0 ]] || coverage_tags+=",rootless" 55 56 # There are far too many coverage files if we just try to upload them all 57 # (Codecov seems to struggle significiantly to process them). So we 58 # pre-merge them -- but because of cmdline limits we conservatively place 59 # them in a directory and use xargs. 60 tmp_coverage="$(mktemp -t umoci-coverage-merged.XXXXXX)" 61 find "$COVERAGE_DIR" -type f -print0 | xargs -0 "$ROOT/hack/collate.awk" >"$tmp_coverage" 62 63 # Upload the merged coverage file. 64 "$ROOT/hack/ci-codecov.sh" codecov -cZ -f "$tmp_coverage" -F "$coverage_tags" 65 elif [ -n "$COVERAGE" ] 66 then 67 # If running locally, collate the coverage information. 68 touch "$COVERAGE" 69 "$ROOT/hack/collate.awk" "$COVERAGE_DIR/"* "$COVERAGE" | sponge "$COVERAGE" 70 fi 71 rm -rf "$COVERAGE_DIR"