From 42f0a0db75a921145c7f519f7b550e1392890da2 Mon Sep 17 00:00:00 2001 From: Andrew Hsu Date: Wed, 31 Jul 2019 00:07:30 +0000 Subject: [PATCH] run unit tests and generate junit report Signed-off-by: Andrew Hsu --- .gitignore | 4 +- Dockerfile | 7 +++ Jenkinsfile | 48 ++++++++++++++++++++- hack/dockerfile/install/gotestsum.installer | 11 +++++ hack/test/unit | 36 +++++++--------- 5 files changed, 83 insertions(+), 23 deletions(-) create mode 100755 hack/dockerfile/install/gotestsum.installer diff --git a/.gitignore b/.gitignore index 684ac53d43..abad293ee0 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/Dockerfile b/Dockerfile index e86fc23336..b72930218e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 @@ -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/ diff --git a/Jenkinsfile b/Jenkinsfile index 6c1f009e69..de9ca0eddc 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -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 diff --git a/hack/dockerfile/install/gotestsum.installer b/hack/dockerfile/install/gotestsum.installer new file mode 100755 index 0000000000..032f46f2fe --- /dev/null +++ b/hack/dockerfile/install/gotestsum.installer @@ -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' +} diff --git a/hack/test/unit b/hack/test/unit index d79c8a4bfb..656d4982ea 100755 --- a/hack/test/unit +++ b/hack/test/unit @@ -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}