Skip to content

Commit 94f1627

Browse files
authored
Add rekor test harness to presubmit tests (#921)
* Add rekor test harness to presubmit tests This will test critical user journeys against the last three versions of rekor released. Signed-off-by: Priya Wadhwa <priya@chainguard.dev> * Set up matrix for testing Signed-off-by: Priya Wadhwa <priya@chainguard.dev> * Code review comments Signed-off-by: Priya Wadhwa <priya@chainguard.dev>
1 parent 4da9b37 commit 94f1627

File tree

3 files changed

+123
-1
lines changed

3 files changed

+123
-1
lines changed

.github/workflows/main.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,22 @@ jobs:
132132
with:
133133
name: Docker Compose logs
134134
path: /tmp/*docker-compose.log
135+
136+
harness:
137+
runs-on: ubuntu-20.04
138+
needs: build
139+
steps:
140+
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2
141+
- name: Extract version of Go to use
142+
run: echo "GOVERSION=$(cat Dockerfile|grep golang | awk ' { print $2 } ' | cut -d '@' -f 1 | cut -d ':' -f 2 | uniq)" >> $GITHUB_ENV
143+
- uses: actions/setup-go@b22fbbc2921299758641fab08929b4ac52b32923 # v3.1.0
144+
with:
145+
go-version: ${{ env.GOVERSION }}
146+
- name: Run test harness
147+
run: ./tests/rekor-harness.sh
148+
- name: Upload logs if they exist
149+
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3
150+
if: failure()
151+
with:
152+
name: E2E Docker Compose logs
153+
path: /tmp/docker-compose.log

tests/e2e_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ type getOut struct {
203203
IntegratedTime int64
204204
}
205205

206-
func TestGet(t *testing.T) {
206+
func TestGetCLI(t *testing.T) {
207207
// Create something and add it to the log
208208
artifactPath := filepath.Join(t.TempDir(), "artifact")
209209
sigPath := filepath.Join(t.TempDir(), "signature.asc")

tests/rekor-harness.sh

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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

Comments
 (0)