Skip to content

Commit e428a41

Browse files
committed
tests: Add integration test script for containertool --resource
1 parent 6e45daf commit e428a41

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

.github/workflows/integration_tests.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,28 @@ jobs:
3535
run: |
3636
swift test
3737
38+
containertool-resources-test:
39+
name: Containertool resources 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-containertool-resources.sh
59+
3860
plugin-streaming-output-test:
3961
name: Plugin streaming output test
4062
runs-on: ubuntu-latest
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env bash
2+
##===----------------------------------------------------------------------===##
3+
##
4+
## This source file is part of the SwiftContainerPlugin open source project
5+
##
6+
## Copyright (c) 2025 Apple Inc. and the SwiftContainerPlugin project authors
7+
## Licensed under Apache License v2.0
8+
##
9+
## See LICENSE.txt for license information
10+
## See CONTRIBUTORS.txt for the list of SwiftContainerPlugin project authors
11+
##
12+
## SPDX-License-Identifier: Apache-2.0
13+
##
14+
##===----------------------------------------------------------------------===##
15+
16+
log() { printf -- "** %s\n" "$*" >&2; }
17+
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
18+
fatal() { error "$@"; exit 1; }
19+
20+
set -euo pipefail
21+
22+
RUNTIME=${RUNTIME-"docker"}
23+
PKGPATH=$(mktemp -d)
24+
25+
#
26+
# Package an example payload with resources. This test only checks
27+
# that the correct files are in the container image and does not run
28+
# it, so the payload does not need to be an executable.
29+
#
30+
touch "$PKGPATH/hello"
31+
mkdir -p "$PKGPATH/resourcedir"
32+
touch "$PKGPATH/resourcedir/resource1.txt" "$PKGPATH/resourcedir/resource2.txt" "$PKGPATH/resourcedir/resource3.txt"
33+
touch "$PKGPATH/resourcefile.dat"
34+
swift run containertool \
35+
"$PKGPATH/hello" \
36+
--repository localhost:5000/resource_test \
37+
--from scratch \
38+
--resources "$PKGPATH/resourcedir" \
39+
--resources "$PKGPATH/resourcefile.dat"
40+
41+
$RUNTIME rm -f resource-test
42+
$RUNTIME create --pull always --name resource-test localhost:5000/resource_test:latest
43+
44+
cleanup() {
45+
log "Deleting temporary package $PKGPATH"
46+
rm -rf "$PKGPATH"
47+
48+
log "Deleting resource-test container"
49+
$RUNTIME rm -f resource-test
50+
}
51+
trap cleanup EXIT
52+
53+
54+
for resource in \
55+
/hello \
56+
/resourcedir/resource1.txt \
57+
/resourcedir/resource2.txt \
58+
/resourcedir/resource3.txt \
59+
/resourcefile.dat
60+
do
61+
# This will return a non-zero exit code if the file does not exist
62+
if $RUNTIME cp resource-test:$resource - > /dev/null ; then
63+
log "$resource: OK"
64+
else
65+
fatal "$resource: FAILED"
66+
fi
67+
done
68+

0 commit comments

Comments
 (0)