Skip to content

Commit e5cce50

Browse files
committed
Add code coverage report and codecov config
Signed-off-by: Daniel Nephin <[email protected]>
1 parent be14665 commit e5cce50

File tree

5 files changed

+58
-19
lines changed

5 files changed

+58
-19
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ dockerversion/version_autogen.go
2020
dockerversion/version_autogen_unix.go
2121
vendor/pkg/
2222
hack/integration-cli-on-swarm/integration-cli-on-swarm
23+
coverage.txt
24+
profile.out

client/client_test.go

+20-18
Original file line numberDiff line numberDiff line change
@@ -12,67 +12,70 @@ import (
1212
"github.com/docker/docker/api"
1313
"github.com/docker/docker/api/types"
1414
"github.com/docker/docker/internal/testutil"
15+
"github.com/gotestyourself/gotestyourself/skip"
1516
"github.com/stretchr/testify/assert"
1617
)
1718

1819
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
2324
envs map[string]string
2425
expectedError string
2526
expectedVersion string
2627
}{
2728
{
29+
doc: "default api version",
2830
envs: map[string]string{},
2931
expectedVersion: api.DefaultVersion,
3032
},
3133
{
34+
doc: "invalid cert path",
3235
envs: map[string]string{
3336
"DOCKER_CERT_PATH": "invalid/path",
3437
},
3538
expectedError: "Could not load X509 key pair: open invalid/path/cert.pem: no such file or directory",
3639
},
3740
{
41+
doc: "default api version with cert path",
3842
envs: map[string]string{
3943
"DOCKER_CERT_PATH": "testdata/",
4044
},
4145
expectedVersion: api.DefaultVersion,
4246
},
4347
{
48+
doc: "default api version with cert path and tls verify",
4449
envs: map[string]string{
4550
"DOCKER_CERT_PATH": "testdata/",
4651
"DOCKER_TLS_VERIFY": "1",
4752
},
4853
expectedVersion: api.DefaultVersion,
4954
},
5055
{
56+
doc: "default api version with cert path and host",
5157
envs: map[string]string{
5258
"DOCKER_CERT_PATH": "testdata/",
5359
"DOCKER_HOST": "https://notaunixsocket",
5460
},
5561
expectedVersion: api.DefaultVersion,
5662
},
5763
{
64+
doc: "invalid docker host",
5865
envs: map[string]string{
5966
"DOCKER_HOST": "host",
6067
},
6168
expectedError: "unable to parse docker host `host`",
6269
},
6370
{
71+
doc: "invalid docker host, with good format",
6472
envs: map[string]string{
6573
"DOCKER_HOST": "invalid://url",
6674
},
6775
expectedVersion: api.DefaultVersion,
6876
},
6977
{
70-
envs: map[string]string{
71-
"DOCKER_API_VERSION": "anything",
72-
},
73-
expectedVersion: "anything",
74-
},
75-
{
78+
doc: "override api version",
7679
envs: map[string]string{
7780
"DOCKER_API_VERSION": "1.22",
7881
},
@@ -82,24 +85,23 @@ func TestNewEnvClient(t *testing.T) {
8285

8386
env := envToMap()
8487
defer mapToEnv(env)
85-
for _, c := range cases {
86-
mapToEnv(env)
88+
for _, c := range testcases {
8789
mapToEnv(c.envs)
8890
apiclient, err := NewEnvClient()
8991
if c.expectedError != "" {
90-
assert.Error(t, err)
91-
assert.Equal(t, c.expectedError, err.Error())
92+
assert.Error(t, err, c.doc)
93+
assert.Equal(t, c.expectedError, err.Error(), c.doc)
9294
} else {
93-
assert.NoError(t, err)
95+
assert.NoError(t, err, c.doc)
9496
version := apiclient.ClientVersion()
95-
assert.Equal(t, c.expectedVersion, version)
97+
assert.Equal(t, c.expectedVersion, version, c.doc)
9698
}
9799

98100
if c.envs["DOCKER_TLS_VERIFY"] != "" {
99101
// pedantic checking that this is handled correctly
100102
tr := apiclient.client.Transport.(*http.Transport)
101-
assert.NotNil(t, tr.TLSClientConfig)
102-
assert.Equal(t, tr.TLSClientConfig.InsecureSkipVerify, false)
103+
assert.NotNil(t, tr.TLSClientConfig, c.doc)
104+
assert.Equal(t, tr.TLSClientConfig.InsecureSkipVerify, false, c.doc)
103105
}
104106
}
105107
}

codecov.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
comment:
2+
layout: header, changes, diff, sunburst
3+
coverage:
4+
status:
5+
patch:
6+
default:
7+
target: 50%
8+
only_pulls: true
9+
# project will give us the diff in the total code coverage between a commit
10+
# and its parent
11+
project:
12+
default:
13+
target: auto
14+
threshold: "15%"
15+
changes: false
16+
ignore:
17+
- "vendor/*"

hack/ci/janky

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ set -eu -o pipefail
44

55
hack/validate/default
66
hack/test/unit
7+
bash <(curl -s https://codecov.io/bash) -f coverage.txt || \
8+
echo 'Codecov failed to upload'
79

810
hack/make.sh \
911
binary-daemon \

hack/test/unit

+17-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,20 @@ TESTDIRS="${TESTDIRS:-"./..."}"
1919
exclude_paths="/vendor/|/integration"
2020
pkg_list=$(go list $TESTDIRS | grep -vE "($exclude_paths)")
2121

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

0 commit comments

Comments
 (0)