run unit tests and generate junit report

Signed-off-by: Andrew Hsu <andrewhsu@docker.com>
(cherry picked from commit 42f0a0db75)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Andrew Hsu 2019-07-31 00:07:30 +00:00 committed by Sebastiaan van Stijn
parent da9289fb54
commit 24144dbdc9
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
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
*.exe
*.exe~
*.gz
*.orig
test.main
.*.swp
@ -19,5 +20,6 @@ contrib/builder/rpm/*/changelog
dockerversion/version_autogen.go
dockerversion/version_autogen_unix.go
vendor/pkg/
coverage.txt
go-test-report.json
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 ./
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
ENV INSTALL_BINARY_NAME=dockercli
COPY hack/dockerfile/install/install.sh ./install.sh
@ -236,6 +242,7 @@ RUN apt-get update && apt-get install -y \
COPY --from=swagger /build/swagger* /usr/local/bin/
COPY --from=frozen-images /build/ /docker-frozen-images
COPY --from=gometalinter /build/ /usr/local/bin/
COPY --from=gotestsum /build/ /usr/local/bin/
COPY --from=tomlv /build/ /usr/local/bin/
COPY --from=vndr /build/ /usr/local/bin/
COPY --from=tini /build/ /usr/local/bin/

48
Jenkinsfile vendored
View File

@ -1,12 +1,14 @@
#!groovy
pipeline {
agent none
options {
buildDiscarder(logRotator(daysToKeepStr: '30'))
timeout(time: 3, unit: 'HOURS')
timestamps()
}
parameters {
booleanParam(name: 'unit', defaultValue: true, description: 'x86 unit tests')
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')
@ -18,6 +20,50 @@ pipeline {
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 \
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') {
when {
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
#
# Run unit tests
# Run unit tests and create report
#
# 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="./pkg/term" hack/test/unit
# 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"
BUILDFLAGS=( -tags 'netgo seccomp libdm_no_deferred_remove' )
TESTFLAGS+="-test.timeout=${TIMEOUT:-5m}"
TESTDIRS="${TESTDIRS:-./...}"
exclude_paths='/vendor/|/integration'
pkg_list=$(go list $TESTDIRS | grep -vE "($exclude_paths)")
for pkg in $pkg_list; do
go test "${BUILDFLAGS[@]}" \
-cover \
-coverprofile=profile.out \
-covermode=atomic \
${TESTFLAGS} \
"${pkg}"
if test -f profile.out; then
cat profile.out >> coverage.txt
rm profile.out
fi
done
mkdir -p bundles
gotestsum --format=standard-quiet --jsonfile=bundles/go-test-report.json --junitfile=bundles/junit-report.xml -- \
"${BUILDFLAGS[@]}" \
-cover \
-coverprofile=bundles/profile.out \
-covermode=atomic \
${TESTFLAGS} \
${pkg_list}