Browse code

Add code coverage report and codecov config

Signed-off-by: Daniel Nephin <dnephin@docker.com>

Daniel Nephin authored on 2017/09/20 07:00:54
Showing 5 changed files
... ...
@@ -20,3 +20,5 @@ dockerversion/version_autogen.go
20 20
 dockerversion/version_autogen_unix.go
21 21
 vendor/pkg/
22 22
 hack/integration-cli-on-swarm/integration-cli-on-swarm
23
+coverage.txt
24
+profile.out
... ...
@@ -12,35 +12,40 @@ import (
12 12
 	"github.com/docker/docker/api"
13 13
 	"github.com/docker/docker/api/types"
14 14
 	"github.com/docker/docker/internal/testutil"
15
+	"github.com/gotestyourself/gotestyourself/skip"
15 16
 	"github.com/stretchr/testify/assert"
16 17
 )
17 18
 
18 19
 func TestNewEnvClient(t *testing.T) {
19
-	if runtime.GOOS == "windows" {
20
-		t.Skip("skipping unix only test for windows")
21
-	}
22
-	cases := []struct {
20
+	skip.IfCondition(t, runtime.GOOS == "windows")
21
+
22
+	testcases := []struct {
23
+		doc             string
23 24
 		envs            map[string]string
24 25
 		expectedError   string
25 26
 		expectedVersion string
26 27
 	}{
27 28
 		{
29
+			doc:             "default api version",
28 30
 			envs:            map[string]string{},
29 31
 			expectedVersion: api.DefaultVersion,
30 32
 		},
31 33
 		{
34
+			doc: "invalid cert path",
32 35
 			envs: map[string]string{
33 36
 				"DOCKER_CERT_PATH": "invalid/path",
34 37
 			},
35 38
 			expectedError: "Could not load X509 key pair: open invalid/path/cert.pem: no such file or directory",
36 39
 		},
37 40
 		{
41
+			doc: "default api version with cert path",
38 42
 			envs: map[string]string{
39 43
 				"DOCKER_CERT_PATH": "testdata/",
40 44
 			},
41 45
 			expectedVersion: api.DefaultVersion,
42 46
 		},
43 47
 		{
48
+			doc: "default api version with cert path and tls verify",
44 49
 			envs: map[string]string{
45 50
 				"DOCKER_CERT_PATH":  "testdata/",
46 51
 				"DOCKER_TLS_VERIFY": "1",
... ...
@@ -48,6 +53,7 @@ func TestNewEnvClient(t *testing.T) {
48 48
 			expectedVersion: api.DefaultVersion,
49 49
 		},
50 50
 		{
51
+			doc: "default api version with cert path and host",
51 52
 			envs: map[string]string{
52 53
 				"DOCKER_CERT_PATH": "testdata/",
53 54
 				"DOCKER_HOST":      "https://notaunixsocket",
... ...
@@ -55,24 +61,21 @@ func TestNewEnvClient(t *testing.T) {
55 55
 			expectedVersion: api.DefaultVersion,
56 56
 		},
57 57
 		{
58
+			doc: "invalid docker host",
58 59
 			envs: map[string]string{
59 60
 				"DOCKER_HOST": "host",
60 61
 			},
61 62
 			expectedError: "unable to parse docker host `host`",
62 63
 		},
63 64
 		{
65
+			doc: "invalid docker host, with good format",
64 66
 			envs: map[string]string{
65 67
 				"DOCKER_HOST": "invalid://url",
66 68
 			},
67 69
 			expectedVersion: api.DefaultVersion,
68 70
 		},
69 71
 		{
70
-			envs: map[string]string{
71
-				"DOCKER_API_VERSION": "anything",
72
-			},
73
-			expectedVersion: "anything",
74
-		},
75
-		{
72
+			doc: "override api version",
76 73
 			envs: map[string]string{
77 74
 				"DOCKER_API_VERSION": "1.22",
78 75
 			},
... ...
@@ -82,24 +85,23 @@ func TestNewEnvClient(t *testing.T) {
82 82
 
83 83
 	env := envToMap()
84 84
 	defer mapToEnv(env)
85
-	for _, c := range cases {
86
-		mapToEnv(env)
85
+	for _, c := range testcases {
87 86
 		mapToEnv(c.envs)
88 87
 		apiclient, err := NewEnvClient()
89 88
 		if c.expectedError != "" {
90
-			assert.Error(t, err)
91
-			assert.Equal(t, c.expectedError, err.Error())
89
+			assert.Error(t, err, c.doc)
90
+			assert.Equal(t, c.expectedError, err.Error(), c.doc)
92 91
 		} else {
93
-			assert.NoError(t, err)
92
+			assert.NoError(t, err, c.doc)
94 93
 			version := apiclient.ClientVersion()
95
-			assert.Equal(t, c.expectedVersion, version)
94
+			assert.Equal(t, c.expectedVersion, version, c.doc)
96 95
 		}
97 96
 
98 97
 		if c.envs["DOCKER_TLS_VERIFY"] != "" {
99 98
 			// pedantic checking that this is handled correctly
100 99
 			tr := apiclient.client.Transport.(*http.Transport)
101
-			assert.NotNil(t, tr.TLSClientConfig)
102
-			assert.Equal(t, tr.TLSClientConfig.InsecureSkipVerify, false)
100
+			assert.NotNil(t, tr.TLSClientConfig, c.doc)
101
+			assert.Equal(t, tr.TLSClientConfig.InsecureSkipVerify, false, c.doc)
103 102
 		}
104 103
 	}
105 104
 }
106 105
new file mode 100644
... ...
@@ -0,0 +1,17 @@
0
+comment:
1
+  layout: header, changes, diff, sunburst
2
+coverage:
3
+  status:
4
+    patch:
5
+      default:
6
+        target: 50%
7
+        only_pulls: true
8
+    # project will give us the diff in the total code coverage between a commit
9
+    # and its parent
10
+    project:
11
+      default:
12
+        target: auto
13
+        threshold: "15%"
14
+    changes: false
15
+ignore:
16
+  - "vendor/*"
... ...
@@ -4,6 +4,8 @@ set -eu -o pipefail
4 4
 
5 5
 hack/validate/default
6 6
 hack/test/unit
7
+bash <(curl -s https://codecov.io/bash) -f coverage.txt || \
8
+    echo 'Codecov failed to upload'
7 9
 
8 10
 hack/make.sh \
9 11
 	binary-daemon \
... ...
@@ -19,4 +19,20 @@ TESTDIRS="${TESTDIRS:-"./..."}"
19 19
 exclude_paths="/vendor/|/integration"
20 20
 pkg_list=$(go list $TESTDIRS | grep -vE "($exclude_paths)")
21 21
 
22
-go test -cover "${BUILDFLAGS[@]}" $TESTFLAGS $pkg_list
22
+# install test dependencies once before running tests for each package. This
23
+# significantly reduces the runtime.
24
+go test -i "${BUILDFLAGS[@]}" $pkg_list
25
+
26
+for pkg in $pkg_list; do
27
+    go test "${BUILDFLAGS[@]}" \
28
+        -cover \
29
+        -coverprofile=profile.out \
30
+        -covermode=atomic \
31
+        $TESTFLAGS \
32
+        "${pkg}"
33
+
34
+    if test -f profile.out; then
35
+        cat profile.out >> coverage.txt
36
+        rm profile.out
37
+    fi
38
+done