Skip to content

Commit 27ef5ee

Browse files
authored
Merge pull request #90 from Mab879/add_intgergation_tests
Add End-to-End Smoke tests
2 parents 8e713c0 + 10a53e8 commit 27ef5ee

4 files changed

Lines changed: 152 additions & 1 deletion

File tree

.github/workflows/main.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,24 @@ jobs:
3737
go-version: ${{ matrix.go }}
3838
- name: Test
3939
run: go test ./...
40+
e2e:
41+
name: End-to-End test (UBI 10)
42+
runs-on: ubuntu-latest
43+
strategy:
44+
fail-fast: false
45+
matrix:
46+
go:
47+
- 'stable'
48+
- 'oldstable'
49+
container: registry.access.redhat.com/ubi10:latest
50+
steps:
51+
- name: Checkout
52+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
53+
- name: Setup Go
54+
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
55+
with:
56+
go-version: ${{ matrix.go }}
57+
- name: Install Dependencies
58+
run: dnf install -y make jq util-linux
59+
- name: E2E Tests
60+
run: make e2e

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
/feeds
44
/reports
55
/vendor
6-
/cvetool
6+
/cvetool
7+
/*.db*

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ cvetool: vendor
1515
clean:
1616
rm -f cvetool
1717
rm -rf vendor
18+
19+
.PHONY: e2e
20+
e2e: cvetool
21+
bash tests/e2e.sh

tests/e2e.sh

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#!/usr/bin/env bash
2+
set -u -o pipefail
3+
4+
cvetool="./cvetool"
5+
failures=0
6+
7+
fail() {
8+
echo ""
9+
echo "=========================================="
10+
echo "FAIL: $1"
11+
echo "=========================================="
12+
if [ -n "${2:-}" ]; then
13+
echo "--- output ---"
14+
echo "$2"
15+
echo "--- end output ---"
16+
fi
17+
echo ""
18+
failures=$((failures + 1))
19+
}
20+
21+
# Test: `cvetool --version` exits successfully
22+
echo "Test: cvetool --version exits successfully..."
23+
version_output=$("$cvetool" --version 2>&1) || {
24+
fail "cvetool --version exited non-zero" "${version_output:-}"
25+
}
26+
if [ -z "${version_output:-}" ]; then
27+
fail "cvetool --version produced no output"
28+
else
29+
echo "PASS: cvetool --version output: $version_output"
30+
fi
31+
32+
# Test: `cvetool update` should not produce any warnings
33+
echo "Test: cvetool update produces no warnings..."
34+
tmpdb=$(mktemp)
35+
unwritable_dir=""
36+
cleanup() {
37+
[ -n "$unwritable_dir" ] && chmod 0755 "$unwritable_dir" 2>/dev/null && rm -rf "$unwritable_dir"
38+
rm -f "$tmpdb"
39+
}
40+
trap cleanup EXIT
41+
update_ok=true
42+
update_output=$("$cvetool" -l debug update --db-path "$tmpdb" 2>&1) || {
43+
fail "cvetool update exited non-zero" "${update_output:-}"
44+
update_ok=false
45+
}
46+
if echo "${update_output:-}" | grep -qi "WARN"; then
47+
fail "cvetool update produced warnings" "$update_output"
48+
else
49+
echo "PASS: no warnings in cvetool update output"
50+
fi
51+
52+
if [ "$update_ok" = true ]; then
53+
# Test: `cvetool scan` exits successfully (warnings are acceptable)
54+
echo "Test: cvetool scan exits successfully..."
55+
scan_output=$("$cvetool" -l debug scan --db-path "$tmpdb" 2>&1) || {
56+
fail "cvetool scan exited non-zero" "${scan_output:-}"
57+
}
58+
if echo "${scan_output:-}" | grep -qi "ERR"; then
59+
fail "cvetool scan produced errors" "$scan_output"
60+
else
61+
echo "PASS: cvetool scan exited successfully"
62+
fi
63+
64+
# Test: `cvetool scan --format sarif` produces valid JSON
65+
echo "Test: cvetool scan --format sarif produces valid JSON..."
66+
json_output=$("$cvetool" -l debug scan --db-path "$tmpdb" --format sarif 2>/dev/null) || {
67+
fail "cvetool scan --format sarif exited non-zero" "${json_output:-}"
68+
}
69+
if ! echo "${json_output:-}" | jq . >/dev/null 2>&1; then
70+
fail "cvetool scan --format sarif produced invalid JSON" "$json_output"
71+
else
72+
echo "PASS: cvetool scan --format sarif output is valid JSON"
73+
fi
74+
75+
# Test: `cvetool scan --format quay` produces valid JSON
76+
echo "Test: cvetool scan --format quay produces valid JSON..."
77+
json_output=$("$cvetool" -l debug scan --db-path "$tmpdb" --format quay 2>/dev/null) || {
78+
fail "cvetool scan --format quay exited non-zero" "${json_output:-}"
79+
}
80+
if ! echo "${json_output:-}" | jq . >/dev/null 2>&1; then
81+
fail "cvetool scan --format quay produced invalid JSON" "$json_output"
82+
else
83+
echo "PASS: cvetool scan --format quay output is valid JSON"
84+
fi
85+
else
86+
echo "SKIP: scan tests skipped because cvetool update failed"
87+
fi
88+
89+
# Test: `cvetool scan` with a bad db path should fail
90+
echo "Test: cvetool scan with bad db path fails..."
91+
if bad_db_output=$("$cvetool" scan --db-path /nonexistent/bad.db 2>&1); then
92+
fail "cvetool scan with bad db path exited 0 (expected failure)" "$bad_db_output"
93+
else
94+
echo "PASS: cvetool scan with bad db path exits non-zero"
95+
fi
96+
97+
# Test: `cvetool update` with an unwritable db path should fail
98+
echo "Test: cvetool update with unwritable db path fails..."
99+
unwritable_dir=$(mktemp -d)
100+
chmod 0000 "$unwritable_dir"
101+
if [ "$(id -u)" -eq 0 ]; then
102+
if unwritable_output=$(runuser -u nobody -- "$cvetool" update --db-path "$unwritable_dir/db" 2>&1); then
103+
fail "cvetool update with unwritable db path exited 0 (expected failure)" "${unwritable_output:-}"
104+
else
105+
echo "PASS: cvetool update with unwritable db path exits non-zero"
106+
fi
107+
else
108+
if unwritable_output=$("$cvetool" update --db-path "$unwritable_dir/db" 2>&1); then
109+
fail "cvetool update with unwritable db path exited 0 (expected failure)" "${unwritable_output:-}"
110+
else
111+
echo "PASS: cvetool update with unwritable db path exits non-zero"
112+
fi
113+
fi
114+
115+
# Summary
116+
echo ""
117+
echo "=========================================="
118+
if [ $failures -gt 0 ]; then
119+
echo "DONE: $failures test(s) FAILED"
120+
echo "=========================================="
121+
exit 1
122+
else
123+
echo "DONE: all tests passed"
124+
echo "=========================================="
125+
fi

0 commit comments

Comments
 (0)