Add code coverage report and codecov config

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2017-09-19 18:00:54 -04:00
parent be14665210
commit e5cce50c7e
5 changed files with 58 additions and 19 deletions

2
.gitignore vendored
View File

@ -20,3 +20,5 @@ dockerversion/version_autogen.go
dockerversion/version_autogen_unix.go dockerversion/version_autogen_unix.go
vendor/pkg/ vendor/pkg/
hack/integration-cli-on-swarm/integration-cli-on-swarm hack/integration-cli-on-swarm/integration-cli-on-swarm
coverage.txt
profile.out

View File

@ -12,35 +12,40 @@ import (
"github.com/docker/docker/api" "github.com/docker/docker/api"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/internal/testutil" "github.com/docker/docker/internal/testutil"
"github.com/gotestyourself/gotestyourself/skip"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestNewEnvClient(t *testing.T) { func TestNewEnvClient(t *testing.T) {
if runtime.GOOS == "windows" { skip.IfCondition(t, runtime.GOOS == "windows")
t.Skip("skipping unix only test for windows")
} testcases := []struct {
cases := []struct { doc string
envs map[string]string envs map[string]string
expectedError string expectedError string
expectedVersion string expectedVersion string
}{ }{
{ {
doc: "default api version",
envs: map[string]string{}, envs: map[string]string{},
expectedVersion: api.DefaultVersion, expectedVersion: api.DefaultVersion,
}, },
{ {
doc: "invalid cert path",
envs: map[string]string{ envs: map[string]string{
"DOCKER_CERT_PATH": "invalid/path", "DOCKER_CERT_PATH": "invalid/path",
}, },
expectedError: "Could not load X509 key pair: open invalid/path/cert.pem: no such file or directory", 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{ envs: map[string]string{
"DOCKER_CERT_PATH": "testdata/", "DOCKER_CERT_PATH": "testdata/",
}, },
expectedVersion: api.DefaultVersion, expectedVersion: api.DefaultVersion,
}, },
{ {
doc: "default api version with cert path and tls verify",
envs: map[string]string{ envs: map[string]string{
"DOCKER_CERT_PATH": "testdata/", "DOCKER_CERT_PATH": "testdata/",
"DOCKER_TLS_VERIFY": "1", "DOCKER_TLS_VERIFY": "1",
@ -48,6 +53,7 @@ func TestNewEnvClient(t *testing.T) {
expectedVersion: api.DefaultVersion, expectedVersion: api.DefaultVersion,
}, },
{ {
doc: "default api version with cert path and host",
envs: map[string]string{ envs: map[string]string{
"DOCKER_CERT_PATH": "testdata/", "DOCKER_CERT_PATH": "testdata/",
"DOCKER_HOST": "https://notaunixsocket", "DOCKER_HOST": "https://notaunixsocket",
@ -55,24 +61,21 @@ func TestNewEnvClient(t *testing.T) {
expectedVersion: api.DefaultVersion, expectedVersion: api.DefaultVersion,
}, },
{ {
doc: "invalid docker host",
envs: map[string]string{ envs: map[string]string{
"DOCKER_HOST": "host", "DOCKER_HOST": "host",
}, },
expectedError: "unable to parse docker host `host`", expectedError: "unable to parse docker host `host`",
}, },
{ {
doc: "invalid docker host, with good format",
envs: map[string]string{ envs: map[string]string{
"DOCKER_HOST": "invalid://url", "DOCKER_HOST": "invalid://url",
}, },
expectedVersion: api.DefaultVersion, expectedVersion: api.DefaultVersion,
}, },
{ {
envs: map[string]string{ doc: "override api version",
"DOCKER_API_VERSION": "anything",
},
expectedVersion: "anything",
},
{
envs: map[string]string{ envs: map[string]string{
"DOCKER_API_VERSION": "1.22", "DOCKER_API_VERSION": "1.22",
}, },
@ -82,24 +85,23 @@ func TestNewEnvClient(t *testing.T) {
env := envToMap() env := envToMap()
defer mapToEnv(env) defer mapToEnv(env)
for _, c := range cases { for _, c := range testcases {
mapToEnv(env)
mapToEnv(c.envs) mapToEnv(c.envs)
apiclient, err := NewEnvClient() apiclient, err := NewEnvClient()
if c.expectedError != "" { if c.expectedError != "" {
assert.Error(t, err) assert.Error(t, err, c.doc)
assert.Equal(t, c.expectedError, err.Error()) assert.Equal(t, c.expectedError, err.Error(), c.doc)
} else { } else {
assert.NoError(t, err) assert.NoError(t, err, c.doc)
version := apiclient.ClientVersion() version := apiclient.ClientVersion()
assert.Equal(t, c.expectedVersion, version) assert.Equal(t, c.expectedVersion, version, c.doc)
} }
if c.envs["DOCKER_TLS_VERIFY"] != "" { if c.envs["DOCKER_TLS_VERIFY"] != "" {
// pedantic checking that this is handled correctly // pedantic checking that this is handled correctly
tr := apiclient.client.Transport.(*http.Transport) tr := apiclient.client.Transport.(*http.Transport)
assert.NotNil(t, tr.TLSClientConfig) assert.NotNil(t, tr.TLSClientConfig, c.doc)
assert.Equal(t, tr.TLSClientConfig.InsecureSkipVerify, false) assert.Equal(t, tr.TLSClientConfig.InsecureSkipVerify, false, c.doc)
} }
} }
} }

17
codecov.yml Normal file
View File

@ -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/*"

View File

@ -4,6 +4,8 @@ set -eu -o pipefail
hack/validate/default hack/validate/default
hack/test/unit hack/test/unit
bash <(curl -s https://codecov.io/bash) -f coverage.txt || \
echo 'Codecov failed to upload'
hack/make.sh \ hack/make.sh \
binary-daemon \ binary-daemon \

View File

@ -19,4 +19,20 @@ TESTDIRS="${TESTDIRS:-"./..."}"
exclude_paths="/vendor/|/integration" exclude_paths="/vendor/|/integration"
pkg_list=$(go list $TESTDIRS | grep -vE "($exclude_paths)") 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