Skip to content

Commit 30d1bf8

Browse files
committed
added entry for running unit tests with junit report
Signed-off-by: Andrew Hsu <[email protected]>
1 parent 7cfd814 commit 30d1bf8

5 files changed

Lines changed: 114 additions & 5 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ dockerversion/version_autogen.go
2020
dockerversion/version_autogen_unix.go
2121
vendor/pkg/
2222
coverage.txt
23+
go-test.out
2324
profile.out
25+
junit-report.xml

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ COPY hack/dockerfile/install/install.sh ./install.sh
163163
COPY hack/dockerfile/install/$INSTALL_BINARY_NAME.installer ./
164164
RUN PREFIX=/build ./install.sh $INSTALL_BINARY_NAME
165165

166+
FROM base AS gojunitreport
167+
ENV INSTALL_BINARY_NAME=gojunitreport
168+
COPY hack/dockerfile/install/install.sh ./install.sh
169+
COPY hack/dockerfile/install/$INSTALL_BINARY_NAME.installer ./
170+
RUN PREFIX=/build ./install.sh $INSTALL_BINARY_NAME
171+
166172
FROM base AS gometalinter
167173
ENV INSTALL_BINARY_NAME=gometalinter
168174
COPY hack/dockerfile/install/install.sh ./install.sh
@@ -235,6 +241,7 @@ RUN apt-get update && apt-get install -y \
235241
--no-install-recommends
236242
COPY --from=swagger /build/swagger* /usr/local/bin/
237243
COPY --from=frozen-images /build/ /docker-frozen-images
244+
COPY --from=gojunitreport /build/ /usr/local/bin/
238245
COPY --from=gometalinter /build/ /usr/local/bin/
239246
COPY --from=tomlv /build/ /usr/local/bin/
240247
COPY --from=vndr /build/ /usr/local/bin/

Jenkinsfile

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,64 @@ pipeline {
77
timeout(time: 3, unit: 'HOURS')
88
}
99
parameters {
10-
booleanParam(name: 'janky', defaultValue: true, description: 'x86 Build/Test')
11-
booleanParam(name: 'experimental', defaultValue: true, description: 'x86 Experimental Build/Test ')
12-
booleanParam(name: 'z', defaultValue: true, description: 'IBM Z (s390x) Build/Test')
13-
booleanParam(name: 'powerpc', defaultValue: true, description: 'PowerPC (ppc64le) Build/Test')
14-
booleanParam(name: 'vendor', defaultValue: true, description: 'Vendor')
10+
booleanParam(name: 'unit', defaultValue: true, description: 'x86 unit tests')
11+
booleanParam(name: 'janky', defaultValue: false, description: 'x86 Build/Test')
12+
booleanParam(name: 'experimental', defaultValue: false, description: 'x86 Experimental Build/Test ')
13+
booleanParam(name: 'z', defaultValue: false, description: 'IBM Z (s390x) Build/Test')
14+
booleanParam(name: 'powerpc', defaultValue: false, description: 'PowerPC (ppc64le) Build/Test')
15+
booleanParam(name: 'vendor', defaultValue: false, description: 'Vendor')
1516
booleanParam(name: 'windowsRS1', defaultValue: false, description: 'Windows 2016 (RS1) Build/Test')
1617
booleanParam(name: 'windowsRS5', defaultValue: false, description: 'Windows 2019 (RS5) Build/Test')
1718
}
1819
stages {
1920
stage('Build') {
2021
parallel {
22+
stage('unit') {
23+
when {
24+
beforeAgent true
25+
expression { params.unit }
26+
}
27+
agent { label 'amd64 && ubuntu-1804 && overlay2' }
28+
environment { DOCKER_BUILDKIT='1' }
29+
30+
steps {
31+
sh '''
32+
# todo: include ip_vs in base image
33+
sudo modprobe ip_vs
34+
35+
GITCOMMIT=$(git rev-parse --short HEAD)
36+
docker build --rm --force-rm --build-arg APT_MIRROR=cdn-fastly.deb.debian.org -t docker:$GITCOMMIT .
37+
38+
docker run --rm -t --privileged \
39+
-v "$WORKSPACE/bundles:/go/src/github.com/docker/docker/bundles" \
40+
-v "$WORKSPACE/.git:/go/src/github.com/docker/docker/.git" \
41+
--name docker-pr$BUILD_NUMBER \
42+
-e DOCKER_GITCOMMIT=${GITCOMMIT} \
43+
-e DOCKER_GRAPHDRIVER=overlay2 \
44+
-e GIT_SHA1=${GIT_COMMIT} \
45+
docker:$GITCOMMIT \
46+
hack/test/unit-junit
47+
'''
48+
}
49+
post {
50+
always {
51+
sh '''
52+
echo "Ensuring container killed."
53+
docker rm -vf docker-pr$BUILD_NUMBER || true
54+
55+
echo "Chowning /workspace to jenkins user"
56+
docker run --rm -v "$WORKSPACE:/workspace" busybox chown -R "$(id -u):$(id -g)" /workspace
57+
'''
58+
sh '''
59+
echo "Creating unit-bundles.tar.gz"
60+
(find bundles -name '*.log' -o -name '*.prof' -o -name integration.test | xargs tar -czf unit-bundles.tar.gz) || true
61+
'''
62+
archiveArtifacts artifacts: 'unit-bundles.tar.gz'
63+
junit 'junit-report.xml'
64+
deleteDir()
65+
}
66+
}
67+
}
2168
stage('janky') {
2269
when {
2370
beforeAgent true
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
GOJUNITREPORT_COMMIT=af01ea7f8024089b458d804d5cdf190f962a9a0c
4+
5+
install_gojunitreport() {
6+
echo "Installing go-junit-report version $GOJUNITREPORT_COMMIT"
7+
go get -d github.com/jstemmer/go-junit-report
8+
cd "$GOPATH/src/github.com/jstemmer/go-junit-report"
9+
git checkout -q "$GOJUNITREPORT_COMMIT"
10+
go build -buildmode=pie -o "${PREFIX}/go-junit-report" "github.com/jstemmer/go-junit-report"
11+
}

hack/test/unit-junit

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Run unit tests
4+
#
5+
# TESTFLAGS - add additional test flags. Ex:
6+
#
7+
# TESTFLAGS="-v -run TestBuild" hack/test/unit
8+
#
9+
# TESTDIRS - run tests for specified packages. Ex:
10+
#
11+
# TESTDIRS="./pkg/term" hack/test/unit
12+
#
13+
set -eu -o pipefail
14+
15+
TESTFLAGS+=" -test.timeout=${TIMEOUT:-5m}"
16+
BUILDFLAGS=( -tags "netgo seccomp libdm_no_deferred_remove" )
17+
TESTDIRS="${TESTDIRS:-"./..."}"
18+
19+
exclude_paths="/vendor/|/integration"
20+
pkg_list=$(go list $TESTDIRS | grep -vE "($exclude_paths)")
21+
22+
for pkg in $pkg_list; do
23+
go test "${BUILDFLAGS[@]}" \
24+
-v \
25+
-cover \
26+
-coverprofile=profile.out \
27+
-covermode=atomic \
28+
${TESTFLAGS} \
29+
"${pkg}" | tee tmp-go-test.out
30+
31+
if test -f tmp-go-test.out; then
32+
cat tmp-go-test.out >> go-test.out
33+
rm tmp-go-test.out
34+
fi
35+
36+
if test -f profile.out; then
37+
cat profile.out >> coverage.txt
38+
rm profile.out
39+
fi
40+
done
41+
42+
cat go-test.out | go-junit-report > junit-report.xml

0 commit comments

Comments
 (0)