Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
Add code coverage report and codecov config
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Nephin <dnephin@docker.com>
  • Loading branch information
dnephin committed Jan 16, 2018
1 parent be14665 commit e5cce50
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -20,3 +20,5 @@ dockerversion/version_autogen.go
dockerversion/version_autogen_unix.go
vendor/pkg/
hack/integration-cli-on-swarm/integration-cli-on-swarm
coverage.txt
profile.out
38 changes: 20 additions & 18 deletions client/client_test.go
Expand Up @@ -12,67 +12,70 @@ import (
"github.com/docker/docker/api"
"github.com/docker/docker/api/types"
"github.com/docker/docker/internal/testutil"
"github.com/gotestyourself/gotestyourself/skip"
"github.com/stretchr/testify/assert"
)

func TestNewEnvClient(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("skipping unix only test for windows")
}
cases := []struct {
skip.IfCondition(t, runtime.GOOS == "windows")

testcases := []struct {
doc string
envs map[string]string
expectedError string
expectedVersion string
}{
{
doc: "default api version",
envs: map[string]string{},
expectedVersion: api.DefaultVersion,
},
{
doc: "invalid cert path",
envs: map[string]string{
"DOCKER_CERT_PATH": "invalid/path",
},
expectedError: "Could not load X509 key pair: open invalid/path/cert.pem: no such file or directory",
},
{
doc: "default api version with cert path",
envs: map[string]string{
"DOCKER_CERT_PATH": "testdata/",
},
expectedVersion: api.DefaultVersion,
},
{
doc: "default api version with cert path and tls verify",
envs: map[string]string{
"DOCKER_CERT_PATH": "testdata/",
"DOCKER_TLS_VERIFY": "1",
},
expectedVersion: api.DefaultVersion,
},
{
doc: "default api version with cert path and host",
envs: map[string]string{
"DOCKER_CERT_PATH": "testdata/",
"DOCKER_HOST": "https://notaunixsocket",
},
expectedVersion: api.DefaultVersion,
},
{
doc: "invalid docker host",
envs: map[string]string{
"DOCKER_HOST": "host",
},
expectedError: "unable to parse docker host `host`",
},
{
doc: "invalid docker host, with good format",
envs: map[string]string{
"DOCKER_HOST": "invalid://url",
},
expectedVersion: api.DefaultVersion,
},
{
envs: map[string]string{
"DOCKER_API_VERSION": "anything",
},
expectedVersion: "anything",
},
{
doc: "override api version",
envs: map[string]string{
"DOCKER_API_VERSION": "1.22",
},
Expand All @@ -82,24 +85,23 @@ func TestNewEnvClient(t *testing.T) {

env := envToMap()
defer mapToEnv(env)
for _, c := range cases {
mapToEnv(env)
for _, c := range testcases {
mapToEnv(c.envs)
apiclient, err := NewEnvClient()
if c.expectedError != "" {
assert.Error(t, err)
assert.Equal(t, c.expectedError, err.Error())
assert.Error(t, err, c.doc)
assert.Equal(t, c.expectedError, err.Error(), c.doc)
} else {
assert.NoError(t, err)
assert.NoError(t, err, c.doc)
version := apiclient.ClientVersion()
assert.Equal(t, c.expectedVersion, version)
assert.Equal(t, c.expectedVersion, version, c.doc)
}

if c.envs["DOCKER_TLS_VERIFY"] != "" {
// pedantic checking that this is handled correctly
tr := apiclient.client.Transport.(*http.Transport)
assert.NotNil(t, tr.TLSClientConfig)
assert.Equal(t, tr.TLSClientConfig.InsecureSkipVerify, false)
assert.NotNil(t, tr.TLSClientConfig, c.doc)
assert.Equal(t, tr.TLSClientConfig.InsecureSkipVerify, false, c.doc)
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions codecov.yml
@@ -0,0 +1,17 @@
comment:
layout: header, changes, diff, sunburst
coverage:
status:
patch:
default:
target: 50%
only_pulls: true
# project will give us the diff in the total code coverage between a commit
# and its parent
project:
default:
target: auto
threshold: "15%"
changes: false
ignore:
- "vendor/*"
2 changes: 2 additions & 0 deletions hack/ci/janky
Expand Up @@ -4,6 +4,8 @@ set -eu -o pipefail

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

hack/make.sh \
binary-daemon \
Expand Down
18 changes: 17 additions & 1 deletion hack/test/unit
Expand Up @@ -19,4 +19,20 @@ TESTDIRS="${TESTDIRS:-"./..."}"
exclude_paths="/vendor/|/integration"
pkg_list=$(go list $TESTDIRS | grep -vE "($exclude_paths)")

go test -cover "${BUILDFLAGS[@]}" $TESTFLAGS $pkg_list
# install test dependencies once before running tests for each package. This
# significantly reduces the runtime.
go test -i "${BUILDFLAGS[@]}" $pkg_list

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

0 comments on commit e5cce50

Please sign in to comment.