|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Copyright 2022 The Sigstore Authors. |
| 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 | +set -e |
| 17 | + |
| 18 | +function start_server () { |
| 19 | + server_version=$1 |
| 20 | + current_branch=$(git rev-parse --abbrev-ref HEAD) |
| 21 | + git checkout $server_version |
| 22 | + if [ $(docker-compose ps | grep -c "(healthy)") == 0 ]; then |
| 23 | + echo "starting services with version $server_version" |
| 24 | + docker-compose up -d --build |
| 25 | + else |
| 26 | + echo "turning down rekor and restarting at version $server_version" |
| 27 | + docker stop $(docker ps --filter name=rekor-server --format {{.ID}}) |
| 28 | + docker-compose up -d --build rekor-server |
| 29 | + fi |
| 30 | + git checkout $current_branch |
| 31 | + |
| 32 | + count=0 |
| 33 | + echo -n "waiting up to 60 sec for system to start" |
| 34 | + until [ $(docker-compose ps | grep -c "(healthy)") == 3 ]; |
| 35 | + do |
| 36 | + if [ $count -eq 6 ]; then |
| 37 | + echo "! timeout reached" |
| 38 | + exit 1 |
| 39 | + else |
| 40 | + echo -n "." |
| 41 | + sleep 10 |
| 42 | + let 'count+=1' |
| 43 | + fi |
| 44 | + done |
| 45 | + echo |
| 46 | +} |
| 47 | + |
| 48 | +function build_cli () { |
| 49 | + echo "Building CLI at version $cli_version" |
| 50 | + cli_version=$1 |
| 51 | + current_branch=$(git rev-parse --abbrev-ref HEAD) |
| 52 | + git checkout $cli_version |
| 53 | + make rekor-cli |
| 54 | + git checkout $current_branch |
| 55 | +} |
| 56 | + |
| 57 | +function run_tests () { |
| 58 | + REKORTMPDIR="$(mktemp -d -t rekor_test.XXXXXX)" |
| 59 | + touch $REKORTMPDIR.rekor.yaml |
| 60 | + trap "rm -rf $REKORTMPDIR" EXIT |
| 61 | + |
| 62 | + |
| 63 | + go clean -testcache |
| 64 | + for test in $HARNESS_TESTS |
| 65 | + do |
| 66 | + if ! REKORTMPDIR=$REKORTMPDIR go test -run $test -v -tags=e2e ./tests/ > $REKORTMPDIR/logs ; then |
| 67 | + cat $REKORTMPDIR/logs |
| 68 | + docker-compose logs --no-color > /tmp/docker-compose.log |
| 69 | + exit 1 |
| 70 | + fi |
| 71 | + if docker-compose logs --no-color | grep -q "panic: runtime error:" ; then |
| 72 | + # if we're here, we found a panic |
| 73 | + echo "Failing due to panics detected in logs" |
| 74 | + docker-compose logs --no-color > /tmp/docker-compose.log |
| 75 | + exit 1 |
| 76 | + fi |
| 77 | + done |
| 78 | +} |
| 79 | + |
| 80 | +# Get last 3 server versions |
| 81 | +git fetch origin |
| 82 | +VERSIONS=$(git tag --sort=-version:refname | head -n 3 | tac) |
| 83 | +echo $VERSIONS |
| 84 | + |
| 85 | +HARNESS_TESTS="TestUploadVerify TestLogInfo TestGetCLI TestSSH TestJAR TestAPK TestIntoto TestX509 TestEntryUpload" |
| 86 | + |
| 87 | +for server_version in $VERSIONS |
| 88 | +do |
| 89 | + start_server $server_version |
| 90 | + for cli_version in $VERSIONS |
| 91 | + do |
| 92 | + echo "=======================================================" |
| 93 | + echo "Running tests with server version $server_version and CLI version $cli_version" |
| 94 | + |
| 95 | + build_cli $cli_version |
| 96 | + run_tests |
| 97 | + |
| 98 | + echo "Tests passed successfully." |
| 99 | + echo "=======================================================" |
| 100 | + done |
| 101 | +done |
| 102 | + |
| 103 | +echo "Harness testing successful :)" |
0 commit comments