Przeglądaj źródła

run unit tests and generate junit report

Signed-off-by: Andrew Hsu <andrewhsu@docker.com>
Andrew Hsu 6 lat temu
rodzic
commit
42f0a0db75
5 zmienionych plików z 83 dodań i 23 usunięć
  1. 3 1
      .gitignore
  2. 7 0
      Dockerfile
  3. 47 1
      Jenkinsfile
  4. 11 0
      hack/dockerfile/install/gotestsum.installer
  5. 15 21
      hack/test/unit

+ 3 - 1
.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

+ 7 - 0
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/

+ 47 - 1
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

+ 11 - 0
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'
+}

+ 15 - 21
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}