Skip to content

Commit

Permalink
added entry for running unit tests with junit report
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Hsu <andrewhsu@docker.com>
  • Loading branch information
andrewhsu committed Jul 31, 2019
1 parent 7cfd814 commit 30d1bf8
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ dockerversion/version_autogen.go
dockerversion/version_autogen_unix.go
vendor/pkg/
coverage.txt
go-test.out
profile.out
junit-report.xml
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ COPY hack/dockerfile/install/install.sh ./install.sh
COPY hack/dockerfile/install/$INSTALL_BINARY_NAME.installer ./
RUN PREFIX=/build ./install.sh $INSTALL_BINARY_NAME

FROM base AS gojunitreport
ENV INSTALL_BINARY_NAME=gojunitreport
COPY hack/dockerfile/install/install.sh ./install.sh
COPY hack/dockerfile/install/$INSTALL_BINARY_NAME.installer ./
RUN PREFIX=/build ./install.sh $INSTALL_BINARY_NAME

FROM base AS gometalinter
ENV INSTALL_BINARY_NAME=gometalinter
COPY hack/dockerfile/install/install.sh ./install.sh
Expand Down Expand Up @@ -235,6 +241,7 @@ RUN apt-get update && apt-get install -y \
--no-install-recommends
COPY --from=swagger /build/swagger* /usr/local/bin/
COPY --from=frozen-images /build/ /docker-frozen-images
COPY --from=gojunitreport /build/ /usr/local/bin/
COPY --from=gometalinter /build/ /usr/local/bin/
COPY --from=tomlv /build/ /usr/local/bin/
COPY --from=vndr /build/ /usr/local/bin/
Expand Down
57 changes: 52 additions & 5 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,64 @@ pipeline {
timeout(time: 3, unit: 'HOURS')
}
parameters {
booleanParam(name: 'janky', defaultValue: true, description: 'x86 Build/Test')
booleanParam(name: 'experimental', defaultValue: true, description: 'x86 Experimental Build/Test ')
booleanParam(name: 'z', defaultValue: true, description: 'IBM Z (s390x) Build/Test')
booleanParam(name: 'powerpc', defaultValue: true, description: 'PowerPC (ppc64le) Build/Test')
booleanParam(name: 'vendor', defaultValue: true, description: 'Vendor')
booleanParam(name: 'unit', defaultValue: true, description: 'x86 unit tests')
booleanParam(name: 'janky', defaultValue: false, description: 'x86 Build/Test')
booleanParam(name: 'experimental', defaultValue: false, description: 'x86 Experimental Build/Test ')
booleanParam(name: 'z', defaultValue: false, description: 'IBM Z (s390x) Build/Test')
booleanParam(name: 'powerpc', defaultValue: false, description: 'PowerPC (ppc64le) Build/Test')
booleanParam(name: 'vendor', defaultValue: false, description: 'Vendor')
booleanParam(name: 'windowsRS1', defaultValue: false, description: 'Windows 2016 (RS1) Build/Test')
booleanParam(name: 'windowsRS5', defaultValue: false, description: 'Windows 2019 (RS5) Build/Test')
}
stages {
stage('Build') {
parallel {
stage('unit') {
when {
beforeAgent true
expression { params.unit }
}
agent { label 'amd64 && ubuntu-1804 && overlay2' }
environment { DOCKER_BUILDKIT='1' }

steps {
sh '''
# todo: include ip_vs in base image
sudo modprobe ip_vs
GITCOMMIT=$(git rev-parse --short HEAD)
docker build --rm --force-rm --build-arg APT_MIRROR=cdn-fastly.deb.debian.org -t docker:$GITCOMMIT .
docker run --rm -t --privileged \
-v "$WORKSPACE/bundles:/go/src/github.com/docker/docker/bundles" \
-v "$WORKSPACE/.git:/go/src/github.com/docker/docker/.git" \
--name docker-pr$BUILD_NUMBER \
-e DOCKER_GITCOMMIT=${GITCOMMIT} \
-e DOCKER_GRAPHDRIVER=overlay2 \
-e GIT_SHA1=${GIT_COMMIT} \
docker:$GITCOMMIT \
hack/test/unit-junit
'''
}
post {
always {
sh '''
echo "Ensuring container killed."
docker rm -vf docker-pr$BUILD_NUMBER || true
echo "Chowning /workspace to jenkins user"
docker run --rm -v "$WORKSPACE:/workspace" busybox chown -R "$(id -u):$(id -g)" /workspace
'''
sh '''
echo "Creating unit-bundles.tar.gz"
(find bundles -name '*.log' -o -name '*.prof' -o -name integration.test | xargs tar -czf unit-bundles.tar.gz) || true
'''
archiveArtifacts artifacts: 'unit-bundles.tar.gz'
junit 'junit-report.xml'
deleteDir()
}
}
}
stage('janky') {
when {
beforeAgent true
Expand Down
11 changes: 11 additions & 0 deletions hack/dockerfile/install/gojunitreport.installer
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

GOJUNITREPORT_COMMIT=af01ea7f8024089b458d804d5cdf190f962a9a0c

install_gojunitreport() {
echo "Installing go-junit-report version $GOJUNITREPORT_COMMIT"
go get -d github.com/jstemmer/go-junit-report
cd "$GOPATH/src/github.com/jstemmer/go-junit-report"
git checkout -q "$GOJUNITREPORT_COMMIT"
go build -buildmode=pie -o "${PREFIX}/go-junit-report" "github.com/jstemmer/go-junit-report"
}
42 changes: 42 additions & 0 deletions hack/test/unit-junit
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
#
# Run unit tests
#
# TESTFLAGS - add additional test flags. Ex:
#
# TESTFLAGS="-v -run TestBuild" hack/test/unit
#
# TESTDIRS - run tests for specified packages. Ex:
#
# TESTDIRS="./pkg/term" hack/test/unit
#
set -eu -o pipefail

TESTFLAGS+=" -test.timeout=${TIMEOUT:-5m}"
BUILDFLAGS=( -tags "netgo seccomp libdm_no_deferred_remove" )
TESTDIRS="${TESTDIRS:-"./..."}"

exclude_paths="/vendor/|/integration"
pkg_list=$(go list $TESTDIRS | grep -vE "($exclude_paths)")

for pkg in $pkg_list; do
go test "${BUILDFLAGS[@]}" \
-v \
-cover \
-coverprofile=profile.out \
-covermode=atomic \
${TESTFLAGS} \
"${pkg}" | tee tmp-go-test.out

if test -f tmp-go-test.out; then
cat tmp-go-test.out >> go-test.out
rm tmp-go-test.out
fi

if test -f profile.out; then
cat profile.out >> coverage.txt
rm profile.out
fi
done

cat go-test.out | go-junit-report > junit-report.xml

0 comments on commit 30d1bf8

Please sign in to comment.