Skip to content

Commit d2f15ab

Browse files
committed
plugin: Add test for streaming output handler
1 parent fca18e0 commit d2f15ab

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

.github/workflows/integration_tests.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,25 @@ jobs:
3434
REGISTRY_PORT: 5000
3535
run: |
3636
swift test
37+
38+
plugin-streaming-output-test:
39+
name: Plugin streaming output test
40+
runs-on: ubuntu-latest
41+
services:
42+
registry:
43+
image: registry:2
44+
ports:
45+
- 5000:5000
46+
steps:
47+
- name: Checkout repository
48+
uses: actions/checkout@v4
49+
with:
50+
persist-credentials: false
51+
52+
- name: Mark the workspace as safe
53+
# https://github.com/actions/checkout/issues/766
54+
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
55+
56+
- name: Check plugin streaming output is reassembled and printed properly
57+
run: |
58+
scripts/test-plugin-output-streaming.sh
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
3+
# Test that error output streamed from containertool is printed correctly by the plugin.
4+
5+
set -exo pipefail
6+
7+
log() { printf -- "** %s\n" "$*" >&2; }
8+
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
9+
fatal() { error "$@"; exit 1; }
10+
11+
# Work in a temporary directory, deleted after the test finishes
12+
PKGPATH=$(mktemp -d)
13+
cleanup() {
14+
log "Deleting temporary package $PKGPATH"
15+
rm -rf "$PKGPATH"
16+
}
17+
trap cleanup EXIT
18+
19+
swift package --package-path "$PKGPATH" init --type executable --name hello
20+
cat >> "$PKGPATH/Package.swift" <<EOF
21+
package.dependencies += [
22+
.package(path: "$PWD"),
23+
]
24+
EOF
25+
26+
# Run the plugin, forgetting a mandatory argument. Verify that the output is not corrupted.
27+
# The `swift package` command will return a nonzero exit code. This is expected, so disable pipefail.
28+
set +o pipefail
29+
swift package --package-path "$PKGPATH" --allow-network-connections all build-container-image 2>&1 | tee "$PKGPATH/output"
30+
set -o pipefail
31+
32+
grep -F -x -e "error: Missing expected argument '--repository <repository>'" \
33+
-e "error: Help: --repository <repository> Repository path" \
34+
-e "error: Usage: containertool [<options>] --repository <repository> <executable>" \
35+
-e "error: See 'containertool --help' for more information." "$PKGPATH/output"
36+
37+
echo Plugin error output: PASSED
38+

0 commit comments

Comments
 (0)