Browse code

run unit tests and generate junit report

Signed-off-by: Andrew Hsu <andrewhsu@docker.com>

Andrew Hsu authored on 2019/07/31 09:07:30
Showing 5 changed files
... ...
@@ -3,6 +3,7 @@
3 3
 #  please consider a global .gitignore https://help.github.com/articles/ignoring-files
4 4
 *.exe
5 5
 *.exe~
6
+*.gz
6 7
 *.orig
7 8
 test.main
8 9
 .*.swp
... ...
@@ -19,5 +20,6 @@ contrib/builder/rpm/*/changelog
19 19
 dockerversion/version_autogen.go
20 20
 dockerversion/version_autogen_unix.go
21 21
 vendor/pkg/
22
-coverage.txt
22
+go-test-report.json
23 23
 profile.out
24
+junit-report.xml
... ...
@@ -169,6 +169,12 @@ COPY hack/dockerfile/install/install.sh ./install.sh
169 169
 COPY hack/dockerfile/install/$INSTALL_BINARY_NAME.installer ./
170 170
 RUN PREFIX=/build ./install.sh $INSTALL_BINARY_NAME
171 171
 
172
+FROM base AS gotestsum
173
+ENV INSTALL_BINARY_NAME=gotestsum
174
+COPY hack/dockerfile/install/install.sh ./install.sh
175
+COPY hack/dockerfile/install/$INSTALL_BINARY_NAME.installer ./
176
+RUN PREFIX=/build ./install.sh $INSTALL_BINARY_NAME
177
+
172 178
 FROM dev-base AS dockercli
173 179
 ENV INSTALL_BINARY_NAME=dockercli
174 180
 COPY hack/dockerfile/install/install.sh ./install.sh
... ...
@@ -241,6 +247,7 @@ RUN pip3 install yamllint==1.16.0
241 241
 COPY --from=swagger /build/swagger* /usr/local/bin/
242 242
 COPY --from=frozen-images /build/ /docker-frozen-images
243 243
 COPY --from=gometalinter /build/ /usr/local/bin/
244
+COPY --from=gotestsum /build/ /usr/local/bin/
244 245
 COPY --from=tomlv /build/ /usr/local/bin/
245 246
 COPY --from=vndr /build/ /usr/local/bin/
246 247
 COPY --from=tini /build/ /usr/local/bin/
... ...
@@ -1,12 +1,14 @@
1
+#!groovy
1 2
 pipeline {
2 3
   agent none
3 4
 
4
-
5 5
   options {
6 6
     buildDiscarder(logRotator(daysToKeepStr: '30'))
7 7
     timeout(time: 3, unit: 'HOURS')
8
+    timestamps()
8 9
   }
9 10
   parameters {
11
+        booleanParam(name: 'unit', defaultValue: true, description: 'x86 unit tests')
10 12
         booleanParam(name: 'janky', defaultValue: true, description: 'x86 Build/Test')
11 13
         booleanParam(name: 'experimental', defaultValue: true, description: 'x86 Experimental Build/Test ')
12 14
         booleanParam(name: 'z', defaultValue: true, description: 'IBM Z (s390x) Build/Test')
... ...
@@ -18,6 +20,50 @@ pipeline {
18 18
   stages {
19 19
     stage('Build') {
20 20
       parallel {
21
+        stage('unit') {
22
+          when {
23
+            beforeAgent true
24
+            expression { params.unit }
25
+          }
26
+          agent { label 'amd64 && ubuntu-1804 && overlay2' }
27
+          environment { DOCKER_BUILDKIT='1' }
28
+
29
+          steps {
30
+              sh '''
31
+                # todo: include ip_vs in base image
32
+                sudo modprobe ip_vs
33
+
34
+                GITCOMMIT=$(git rev-parse --short HEAD)
35
+                docker build --rm --force-rm --build-arg APT_MIRROR=cdn-fastly.deb.debian.org -t docker:$GITCOMMIT .
36
+
37
+                docker run --rm -t --privileged \
38
+                  -v "$WORKSPACE/bundles:/go/src/github.com/docker/docker/bundles" \
39
+                  -v "$WORKSPACE/.git:/go/src/github.com/docker/docker/.git" \
40
+                  --name docker-pr$BUILD_NUMBER \
41
+                  -e DOCKER_GITCOMMIT=${GITCOMMIT} \
42
+                  -e DOCKER_GRAPHDRIVER=overlay2 \
43
+                  docker:$GITCOMMIT \
44
+                  hack/test/unit
45
+              '''
46
+          }
47
+          post {
48
+            always {
49
+              junit 'bundles/junit-report.xml'
50
+              sh '''
51
+                echo 'Ensuring container killed.'
52
+                docker rm -vf docker-pr$BUILD_NUMBER || true
53
+
54
+                echo 'Chowning /workspace to jenkins user'
55
+                docker run --rm -v "$WORKSPACE:/workspace" busybox chown -R "$(id -u):$(id -g)" /workspace
56
+
57
+                echo 'Creating unit-bundles.tar.gz'
58
+                tar -czvf unit-bundles.tar.gz bundles/junit-report.xml bundles/go-test-report.json bundles/profile.out
59
+              '''
60
+              archiveArtifacts artifacts:'unit-bundles.tar.gz'
61
+              deleteDir()
62
+            }
63
+          }
64
+        }
21 65
         stage('janky') {
22 66
           when {
23 67
             beforeAgent true
24 68
new file mode 100755
... ...
@@ -0,0 +1,11 @@
0
+#!/bin/sh
1
+
2
+GOTESTSUM_COMMIT='v0.3.5'
3
+
4
+install_gotestsum() {
5
+	echo "Installing gotestsum version $GOTESTSUM_COMMIT"
6
+	go get -d gotest.tools/gotestsum
7
+	cd "$GOPATH/src/gotest.tools/gotestsum"
8
+	git checkout -q "$GOTESTSUM_COMMIT"
9
+	go build -buildmode=pie -o "${PREFIX}/gotestsum" 'gotest.tools/gotestsum'
10
+}
... ...
@@ -1,34 +1,28 @@
1 1
 #!/usr/bin/env bash
2 2
 #
3
-# Run unit tests
3
+# Run unit tests and create report
4 4
 #
5 5
 # TESTFLAGS - add additional test flags. Ex:
6 6
 #
7
-#   TESTFLAGS="-v -run TestBuild" hack/test/unit
7
+#   TESTFLAGS='-v -run TestBuild' hack/test/unit
8 8
 #
9 9
 # TESTDIRS - run tests for specified packages. Ex:
10 10
 #
11
-#    TESTDIRS="./pkg/term" hack/test/unit
11
+#   TESTDIRS='./pkg/term' hack/test/unit
12 12
 #
13 13
 set -eu -o pipefail
14 14
 
15
-TESTFLAGS+=" -test.timeout=${TIMEOUT:-5m}"
16
-BUILDFLAGS=( -tags "netgo seccomp libdm_no_deferred_remove" )
17
-TESTDIRS="${TESTDIRS:-"./..."}"
18
-
19
-exclude_paths="/vendor/|/integration"
15
+BUILDFLAGS=( -tags 'netgo seccomp libdm_no_deferred_remove' )
16
+TESTFLAGS+="-test.timeout=${TIMEOUT:-5m}"
17
+TESTDIRS="${TESTDIRS:-./...}"
18
+exclude_paths='/vendor/|/integration'
20 19
 pkg_list=$(go list $TESTDIRS | grep -vE "($exclude_paths)")
21 20
 
22
-for pkg in $pkg_list; do
23
-    go test "${BUILDFLAGS[@]}" \
24
-        -cover \
25
-        -coverprofile=profile.out \
26
-        -covermode=atomic \
27
-        ${TESTFLAGS} \
28
-        "${pkg}"
29
-
30
-    if test -f profile.out; then
31
-        cat profile.out >> coverage.txt
32
-        rm profile.out
33
-    fi
34
-done
21
+mkdir -p bundles
22
+gotestsum --format=standard-quiet --jsonfile=bundles/go-test-report.json --junitfile=bundles/junit-report.xml -- \
23
+  "${BUILDFLAGS[@]}" \
24
+  -cover \
25
+  -coverprofile=bundles/profile.out \
26
+  -covermode=atomic \
27
+  ${TESTFLAGS} \
28
+  ${pkg_list}