Skip to content

Commit a2fc28e

Browse files
committed
chore(common): add unit test script for ci
1 parent 597eb89 commit a2fc28e

3 files changed

Lines changed: 37 additions & 17 deletions

File tree

Makefile

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,12 @@ ROOT_DIR := $(CURDIR)
66
BUILDPACK_DIR := $(ROOT_DIR)
77
PYTHON_BIN ?= python3
88

9-
.PHONY: test-buildpack clean-test-buildpack test-detect test-compile test-release smoke-test start-local
9+
.PHONY: test-buildpack clean-test-buildpack test-unit test-detect test-compile test-release smoke-test start-local
1010

1111
# Reset the temporary staging directories used for local buildpack testing.
1212
clean-test-buildpack:
1313
rm -rf $(BUILD_DIR) $(CACHE_DIR) $(ENV_DIR)
1414

15-
# Run unit tests for the detect script without requiring external test tooling.
16-
test-detect:
17-
@bash ./test/unit/detect_test.sh
18-
19-
# Run unit tests for the compile script with stubbed python and uv commands.
20-
test-compile:
21-
@bash ./test/unit/compile_test.sh
22-
23-
# Run unit tests for the release script command-resolution logic.
24-
test-release:
25-
@bash ./test/unit/release_test.sh
26-
2715
# Run the sample app through detect, compile, and release using the same
2816
# temporary directories each time so local testing is repeatable.
2917
test-buildpack: clean-test-buildpack
@@ -36,10 +24,6 @@ test-buildpack: clean-test-buildpack
3624
cd $(BUILD_DIR) && /bin/bash -lc 'source .profile.d/python.sh && $(PYTHON_BIN) -c "import fastapi; print(fastapi.__version__)"'
3725
cd $(BUILD_DIR) && $(BUILDPACK_DIR)/bin/release
3826

39-
# Run the single-app smoke test target against every app fixture under test/smoke.
40-
smoke-test:
41-
@./scripts/smoke-test.sh
42-
4327
# Start the staged sample app locally using the dependencies prepared by `test-buildpack`.
4428
start-local:
4529
@cd $(BUILD_DIR) && /bin/bash -lc '\
@@ -57,3 +41,11 @@ start-local:
5741
# Local machines often expose `python3` instead of `python`, so normalize that here. \
5842
WEB_CMD=$$(printf "%s" "$$WEB_CMD" | sed "s/^python /$(PYTHON_BIN) /"); \
5943
eval "$$WEB_CMD"'
44+
45+
# Run the single-app smoke test target against every app fixture under test/smoke.
46+
smoke-test:
47+
@./scripts/smoke-test.sh
48+
49+
# Run all lightweight script-level unit tests together.
50+
unit-test:
51+
@./scripts/unit-test.sh

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
The current cloud foundry [python-buildpack](https://github.com/cloudfoundry/python-buildpack) doesn't support modern python tools, such as [uv](https://docs.astral.sh/uv/), so I created this custom buildpack to bridge the gap.
44

5+
## Installation
6+
57
## Testing Locally
68

79
Run the buildpack test flow from the repository root:

scripts/unit-test.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
6+
UNIT_TEST_DIR="${UNIT_TEST_DIR:-$ROOT_DIR/test/unit}"
7+
8+
if [ ! -d "$UNIT_TEST_DIR" ]; then
9+
echo "Unit test directory not found: $UNIT_TEST_DIR"
10+
exit 1
11+
fi
12+
13+
found_test=0
14+
15+
# Run every shell test in test/unit and stop immediately if one fails.
16+
for test_file in "$UNIT_TEST_DIR"/*.sh; do
17+
[ -f "$test_file" ] || continue
18+
found_test=1
19+
echo "==> Running $(basename "$test_file")"
20+
bash "$test_file"
21+
done
22+
23+
if [ "$found_test" -eq 0 ]; then
24+
echo "No unit test scripts found in $UNIT_TEST_DIR"
25+
exit 1
26+
fi

0 commit comments

Comments
 (0)