Skip to content

Commit 070d235

Browse files
committed
build(kube-ovn): run the tests of the packages the patches touch
The image build ran one test by name, the one shipped next to the migration patch, and go build never compiles a _test.go, so the rest of the tests in the packages the patches change never ran. 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. It replaces the hand-picked go test line: the shipped test lives in pkg/controller, which a patch touches, so the loop runs it with the rest of that package. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent 59c3174 commit 070d235

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

‎packages/system/kubeovn/images/kubeovn/Dockerfile‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,20 @@ WORKDIR /source
1212

1313
COPY patches /patches
1414
RUN git apply /patches/*.diff
15+
# The loop below runs this test: a patch touches pkg/controller.
1516
COPY tests/kubevirt_migration_test.go.txt /source/pkg/controller/kubevirt_migration_test.go
16-
RUN go test ./pkg/controller -run '^TestVMIMigrationSchedulingRetry$' -count=1
17+
18+
# go build never compiles a _test.go, so nothing else runs the tests of the
19+
# packages the patches touch. Each package is tested from its own directory:
20+
# that finds the module it belongs to, and an empty list runs nothing.
21+
# The list is read into a variable first: a for loop drops the exit status
22+
# of a command substitution, so a patch git cannot read would leave the list
23+
# empty and the step green.
24+
RUN files=$(git apply --numstat /patches/*.diff) || exit 1; \
25+
for dir in $(printf '%s\n' "$files" | cut -f3 | grep '\.go$' | xargs -r -n1 dirname | sort -u); do \
26+
(cd "$dir" && go test .) || exit 1; \
27+
done
28+
1729
# Upstream hardcodes GOARCH in each target: build-go is amd64 only, and
1830
# build-go-arm is its arm64 twin minus the `go mod tidy` and the test-server
1931
# binary, which this image never copies.

0 commit comments

Comments
 (0)