Skip to content

Commit 587dfc4

Browse files
committed
Set up matrix for testing
1 parent ee72f5c commit 587dfc4

File tree

3 files changed

+81
-67
lines changed

3 files changed

+81
-67
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -133,30 +133,9 @@ jobs:
133133
name: Docker Compose logs
134134
path: /tmp/*docker-compose.log
135135

136-
get-versions:
137-
runs-on: ubuntu-20.04
138-
outputs:
139-
versions: ${{ steps.versions.outputs.versions }}
140-
steps:
141-
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2
142-
- name: get versions to test harness against
143-
id: versions
144-
shell: bash
145-
run: |
146-
git fetch origin
147-
VERSIONS=$(git tag --sort=-version:refname | head -n 3 | jq --raw-input . | jq --slurp)
148-
echo "Testing versions: $VERSIONS"
149-
echo "::set-output name=versions::$(echo $VERSIONS)"
150-
151136
harness:
152137
runs-on: ubuntu-20.04
153-
needs: [get-versions, build]
154-
continue-on-error: true
155-
strategy:
156-
matrix:
157-
server-version: ${{fromJson(needs.get-versions.outputs.versions)}}
158-
env:
159-
SERVER_VERSION: ${{ matrix.server-version }}
138+
needs: build
160139
steps:
161140
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2
162141
- name: Extract version of Go to use

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ rekorServerImagerefs
1717
rekorCliImagerefs
1818
trillianServerImagerefs
1919
trillianSignerImagerefs
20+
logs

tests/rekor-harness.sh

Lines changed: 79 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
#
3-
# Copyright 2021 The Sigstore Authors.
3+
# Copyright 2022 The Sigstore Authors.
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
@@ -15,58 +15,92 @@
1515
# limitations under the License.
1616
set -e
1717

18-
if [ -z "$SERVER_VERSION" ]; then
19-
echo "Please indicate which version of rekor to test against by setting SERVER_VERSION"
20-
exit 1
21-
fi
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
2231

23-
HARNESS_TESTS="TestUploadVerify TestLogInfo TestGetCLI TestSSH TestJAR TestAPK TestIntoto TestX509 TestEntryUpload"
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+
}
2447

25-
testdir=$(dirname "$0")
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+
go build -o rekor-cli ./cmd/rekor-cli
54+
git checkout $current_branch
55+
}
2656

27-
echo "building CLI and server"
28-
go build -o rekor-cli ./cmd/rekor-cli
57+
function run_tests () {
58+
server_version=$1
59+
cli_version=$2
2960

30-
echo "starting services with version $SERVER_VERSION"
31-
git fetch origin
32-
current_branch=$(git rev-parse --abbrev-ref HEAD)
33-
git checkout $SERVER_VERSION
34-
docker-compose up -d --build
35-
git checkout $current_branch
61+
REKORTMPDIR="$(mktemp -d -t rekor_test.XXXXXX)"
62+
touch $REKORTMPDIR.rekor.yaml
63+
trap "rm -rf $REKORTMPDIR" EXIT
3664

37-
count=0
3865

39-
echo -n "waiting up to 60 sec for system to start"
40-
until [ $(docker-compose ps | grep -c "(healthy)") == 3 ];
41-
do
42-
if [ $count -eq 6 ]; then
43-
echo "! timeout reached"
44-
exit 1
45-
else
46-
echo -n "."
47-
sleep 10
48-
let 'count+=1'
49-
fi
50-
done
66+
go clean -testcache
67+
for test in $HARNESS_TESTS
68+
do
69+
if ! REKORTMPDIR=$REKORTMPDIR go test -run $test -v -tags=e2e ./tests/ > logs ; then
70+
cat logs
71+
docker-compose logs --no-color > /tmp/docker-compose.log
72+
exit 1
73+
fi
74+
if docker-compose logs --no-color | grep -q "panic: runtime error:" ; then
75+
# if we're here, we found a panic
76+
echo "Failing due to panics detected in logs"
77+
docker-compose logs --no-color > /tmp/docker-compose.log
78+
exit 1
79+
fi
80+
done
81+
}
5182

52-
echo
53-
echo "running tests $HARNESS_TESTS"
54-
REKORTMPDIR="$(mktemp -d -t rekor_test.XXXXXX)"
55-
touch $REKORTMPDIR.rekor.yaml
56-
trap "rm -rf $REKORTMPDIR" EXIT
83+
# Get last 3 server versions
84+
git fetch origin
85+
VERSIONS=$(git tag --sort=-version:refname | head -n 3 | tac)
86+
echo $VERSIONS
5787

88+
HARNESS_TESTS="TestUploadVerify TestLogInfo TestGetCLI TestSSH TestJAR TestAPK TestIntoto TestX509 TestEntryUpload"
5889

59-
for test in $HARNESS_TESTS
90+
for server_version in $VERSIONS
6091
do
61-
echo $test
62-
if ! REKORTMPDIR=$REKORTMPDIR go test -run $test -v -tags=e2e ./tests/; then
63-
docker-compose logs --no-color > /tmp/docker-compose.log
64-
exit 1
65-
fi
66-
if docker-compose logs --no-color | grep -q "panic: runtime error:" ; then
67-
# if we're here, we found a panic
68-
echo "Failing due to panics detected in logs"
69-
docker-compose logs --no-color > /tmp/docker-compose.log
70-
exit 1
71-
fi
92+
start_server $server_version
93+
for cli_version in $VERSIONS
94+
do
95+
echo "======================================================="
96+
echo "Running tests with server version $server_version and CLI version $cli_version"
97+
98+
build_cli $cli_version
99+
run_tests $server_version $cli_version
100+
101+
echo "Tests passed successfully."
102+
echo "======================================================="
103+
done
72104
done
105+
106+
echo "Harness testing successful :)"

0 commit comments

Comments
 (0)