run unit tests and generate junit report

Signed-off-by: Andrew Hsu <andrewhsu@docker.com>
This commit is contained in:
Andrew Hsu 2019-07-31 00:07:30 +00:00
parent 589f1dad8d
commit 42f0a0db75
5 changed files with 83 additions and 23 deletions

4
.gitignore vendored
View file

@ -3,6 +3,7 @@
# please consider a global .gitignore https://help.github.com/articles/ignoring-files # please consider a global .gitignore https://help.github.com/articles/ignoring-files
*.exe *.exe
*.exe~ *.exe~
*.gz
*.orig *.orig
test.main test.main
.*.swp .*.swp
@ -19,5 +20,6 @@ contrib/builder/rpm/*/changelog
dockerversion/version_autogen.go dockerversion/version_autogen.go
dockerversion/version_autogen_unix.go dockerversion/version_autogen_unix.go
vendor/pkg/ vendor/pkg/
coverage.txt go-test-report.json
profile.out profile.out
junit-report.xml

View file

@ -169,6 +169,12 @@ COPY hack/dockerfile/install/install.sh ./install.sh
COPY hack/dockerfile/install/$INSTALL_BINARY_NAME.installer ./ COPY hack/dockerfile/install/$INSTALL_BINARY_NAME.installer ./
RUN PREFIX=/build ./install.sh $INSTALL_BINARY_NAME RUN PREFIX=/build ./install.sh $INSTALL_BINARY_NAME
FROM base AS gotestsum
ENV INSTALL_BINARY_NAME=gotestsum
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 dev-base AS dockercli FROM dev-base AS dockercli
ENV INSTALL_BINARY_NAME=dockercli ENV INSTALL_BINARY_NAME=dockercli
COPY hack/dockerfile/install/install.sh ./install.sh COPY hack/dockerfile/install/install.sh ./install.sh
@ -241,6 +247,7 @@ RUN pip3 install yamllint==1.16.0
COPY --from=swagger /build/swagger* /usr/local/bin/ COPY --from=swagger /build/swagger* /usr/local/bin/
COPY --from=frozen-images /build/ /docker-frozen-images COPY --from=frozen-images /build/ /docker-frozen-images
COPY --from=gometalinter /build/ /usr/local/bin/ COPY --from=gometalinter /build/ /usr/local/bin/
COPY --from=gotestsum /build/ /usr/local/bin/
COPY --from=tomlv /build/ /usr/local/bin/ COPY --from=tomlv /build/ /usr/local/bin/
COPY --from=vndr /build/ /usr/local/bin/ COPY --from=vndr /build/ /usr/local/bin/
COPY --from=tini /build/ /usr/local/bin/ COPY --from=tini /build/ /usr/local/bin/

48
Jenkinsfile vendored
View file

@ -1,12 +1,14 @@
#!groovy
pipeline { pipeline {
agent none agent none
options { options {
buildDiscarder(logRotator(daysToKeepStr: '30')) buildDiscarder(logRotator(daysToKeepStr: '30'))
timeout(time: 3, unit: 'HOURS') timeout(time: 3, unit: 'HOURS')
timestamps()
} }
parameters { parameters {
booleanParam(name: 'unit', defaultValue: true, description: 'x86 unit tests')
booleanParam(name: 'janky', defaultValue: true, description: 'x86 Build/Test') booleanParam(name: 'janky', defaultValue: true, description: 'x86 Build/Test')
booleanParam(name: 'experimental', defaultValue: true, description: 'x86 Experimental 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: 'z', defaultValue: true, description: 'IBM Z (s390x) Build/Test')
@ -18,6 +20,50 @@ pipeline {
stages { stages {
stage('Build') { stage('Build') {
parallel { 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 \
docker:$GITCOMMIT \
hack/test/unit
'''
}
post {
always {
junit 'bundles/junit-report.xml'
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
echo 'Creating unit-bundles.tar.gz'
tar -czvf unit-bundles.tar.gz bundles/junit-report.xml bundles/go-test-report.json bundles/profile.out
'''
archiveArtifacts artifacts:'unit-bundles.tar.gz'
deleteDir()
}
}
}
stage('janky') { stage('janky') {
when { when {
beforeAgent true beforeAgent true

View file

@ -0,0 +1,11 @@
#!/bin/sh
GOTESTSUM_COMMIT='v0.3.5'
install_gotestsum() {
echo "Installing gotestsum version $GOTESTSUM_COMMIT"
go get -d gotest.tools/gotestsum
cd "$GOPATH/src/gotest.tools/gotestsum"
git checkout -q "$GOTESTSUM_COMMIT"
go build -buildmode=pie -o "${PREFIX}/gotestsum" 'gotest.tools/gotestsum'
}

View file

@ -1,34 +1,28 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# #
# Run unit tests # Run unit tests and create report
# #
# TESTFLAGS - add additional test flags. Ex: # TESTFLAGS - add additional test flags. Ex:
# #
# TESTFLAGS="-v -run TestBuild" hack/test/unit # TESTFLAGS='-v -run TestBuild' hack/test/unit
# #
# TESTDIRS - run tests for specified packages. Ex: # TESTDIRS - run tests for specified packages. Ex:
# #
# TESTDIRS="./pkg/term" hack/test/unit # TESTDIRS='./pkg/term' hack/test/unit
# #
set -eu -o pipefail set -eu -o pipefail
TESTFLAGS+=" -test.timeout=${TIMEOUT:-5m}" BUILDFLAGS=( -tags 'netgo seccomp libdm_no_deferred_remove' )
BUILDFLAGS=( -tags "netgo seccomp libdm_no_deferred_remove" ) TESTFLAGS+="-test.timeout=${TIMEOUT:-5m}"
TESTDIRS="${TESTDIRS:-"./..."}" TESTDIRS="${TESTDIRS:-./...}"
exclude_paths='/vendor/|/integration'
exclude_paths="/vendor/|/integration"
pkg_list=$(go list $TESTDIRS | grep -vE "($exclude_paths)") pkg_list=$(go list $TESTDIRS | grep -vE "($exclude_paths)")
for pkg in $pkg_list; do mkdir -p bundles
go test "${BUILDFLAGS[@]}" \ gotestsum --format=standard-quiet --jsonfile=bundles/go-test-report.json --junitfile=bundles/junit-report.xml -- \
-cover \ "${BUILDFLAGS[@]}" \
-coverprofile=profile.out \ -cover \
-covermode=atomic \ -coverprofile=bundles/profile.out \
${TESTFLAGS} \ -covermode=atomic \
"${pkg}" ${TESTFLAGS} \
${pkg_list}
if test -f profile.out; then
cat profile.out >> coverage.txt
rm profile.out
fi
done