Skip to content

Commit 357f57a

Browse files
committed
build(redis-operator): run the tests of the packages the patches touch
The image build ran go build only, and go build never compiles a _test.go, so nothing ran the tests of the code the patches change. Run go test in the builder stage on the packages the patches touch. The list is read from the patches themselves, so a new patch is covered without an edit to the Dockerfile. Two of the files the patches edit are upstream integration tests behind the integration build tag, which go test compiles none of, so each directory is also vetted with that tag. Doing it per derived directory rather than for the one directory those tests live in today keeps a later patch to a tagged test elsewhere covered. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent 5812b14 commit 357f57a

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

  • packages/system/redis-operator/images/redis-operator

‎packages/system/redis-operator/images/redis-operator/Dockerfile‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ RUN rm -rf manifests charts example .github
1717
COPY patches /patches
1818
RUN git apply /patches/*.diff
1919

20+
# go build never compiles a _test.go, so nothing else runs the tests of the
21+
# packages the patches touch. Each package is tested from its own directory:
22+
# that finds the module it belongs to, and an empty list runs nothing.
23+
# The list is read into a variable first: a for loop drops the exit status
24+
# of a command substitution, so a patch git cannot read would leave the list
25+
# empty and the step green.
26+
# Upstream's integration tests sit behind the integration build tag and need a
27+
# cluster, so go test compiles none of them; go vet with the tag type-checks
28+
# them in whichever of these directories they live.
29+
RUN files=$(git apply --numstat /patches/*.diff) || exit 1; \
30+
for dir in $(printf '%s\n' "$files" | cut -f3 | grep '\.go$' | xargs -r -n1 dirname | sort -u); do \
31+
(cd "$dir" && go test . && go vet -tags integration .) || exit 1; \
32+
done
33+
2034
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH VERSION=$VERSION ./scripts/build.sh
2135

2236
FROM alpine:3.24@sha256:294b683cb724975bec92580e1e685676bd4b50bda910ddb8c51d4cabeaec77e6

0 commit comments

Comments
 (0)