Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added entry for running unit tests with junit report #39638

Merged
merged 1 commit into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# please consider a global .gitignore https://help.github.com/articles/ignoring-files
*.exe
*.exe~
*.gz
*.orig
test.main
.*.swp
Expand All @@ -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
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -241,6 +247,7 @@ RUN pip3 install yamllint==1.16.0
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/
Expand Down
48 changes: 47 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions hack/dockerfile/install/gotestsum.installer
Original file line number Diff line number Diff line change
@@ -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'
}
36 changes: 15 additions & 21 deletions hack/test/unit
Original file line number Diff line number Diff line change
@@ -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}