Add structure to generate code coverage representation

Signed-off-by: Nathan LeClaire <nathan.leclaire@gmail.com>
This commit is contained in:
Nathan LeClaire 2015-01-30 16:45:44 -08:00
parent a57917045c
commit d1fdc87f54
49 changed files with 149 additions and 0 deletions

View File

@ -2,7 +2,14 @@ language: go
sudo: false
go:
- 1.3
install:
- export GOPATH=${TRAVIS_BUILD_DIR}/Godeps/_workspace:$GOPATH
- export PATH=${TRAVIS_BUILD_DIR}/Godeps/_workspace/bin:$PATH
- go get -t -v ./...
- go get code.google.com/p/go.tools/cmd/cover
script:
- script/validate-dco
- script/validate-gofmt
- go test -v -short ./...
- rm -rf $HOME/.docker
- script/generate-coverage

View File

@ -1,11 +1,16 @@
FROM golang:1.3-cross
RUN apt-get update && apt-get install -y --no-install-recommends openssh-client
# TODO: Vendor these `go get` commands using Godep.
RUN go get github.com/mitchellh/gox
RUN go get github.com/aktau/github-release
RUN go get github.com/tools/godep
RUN go get code.google.com/p/go.tools/cmd/cover
ENV GOPATH /go/src/github.com/docker/machine/Godeps/_workspace:/go
ENV MACHINE_BINARY /go/src/github.com/docker/machine/docker-machine
ENV USER root
WORKDIR /go/src/github.com/docker/machine
ADD . /go/src/github.com/docker/machine

View File

@ -330,6 +330,28 @@ pass an argument to that script to specify which directory, e.g.:
If you make a pull request, it is highly encouraged that you submit tests for
the code that you have added or modified in the same pull request.
## Code Coverage
Machine includes a script to check for missing `*_test.go` files and to generate
an [HTML-based repesentation of which code is covered by tests](http://blog.golang.org/cover#TOC_5.).
To run the code coverage script, execute:
```console
$ ./script/coverage serve
```
You will see the results of the code coverage check as they come in.
This will also generate the code coverage website and serve it from a container
on port 8000. By default, `/` will show you the source files from the base
directory, and you can navigate to the coverage for any particular subdirectory
of the Docker Machine repo's root by going to that path. For instance, to see
the coverage for the VirtualBox driver's package, browse to `/drivers/virtualbox`.
![](/docs/img/coverage.png)
You can hit `CTRL+C` to stop the server.
## Integration Tests
There is a suite of integration tests that will run for the drivers. In order

BIN
docs/img/coverage.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 KiB

View File

@ -0,0 +1 @@
package amz

View File

@ -0,0 +1 @@
package amz

View File

@ -0,0 +1 @@
package amz

View File

@ -0,0 +1 @@
package amz

View File

@ -0,0 +1 @@
package amz

View File

@ -0,0 +1 @@
package amz

View File

@ -0,0 +1 @@
package amz

View File

@ -0,0 +1 @@
package amz

View File

@ -0,0 +1 @@
package amz

View File

@ -0,0 +1 @@
package amz

View File

@ -0,0 +1 @@
package amz

View File

@ -0,0 +1 @@
package amz

View File

@ -0,0 +1 @@
package amz

View File

@ -0,0 +1 @@
package azure

View File

@ -0,0 +1 @@
package digitalocean

View File

@ -0,0 +1 @@
package google

View File

@ -0,0 +1 @@
package google

View File

@ -0,0 +1 @@
package google

View File

@ -0,0 +1 @@
package none

View File

@ -0,0 +1 @@
package openstack

View File

@ -0,0 +1 @@
package openstack

View File

@ -0,0 +1 @@
package rackspace

View File

@ -0,0 +1 @@
package rackspace

View File

@ -0,0 +1 @@
package softlayer

View File

@ -0,0 +1 @@
package softlayer

View File

@ -0,0 +1 @@
package virtualbox

View File

@ -0,0 +1 @@
package virtualbox

View File

@ -0,0 +1 @@
package virtualbox

View File

@ -0,0 +1 @@
package vmwarefusion

View File

@ -0,0 +1 @@
package vmwarefusion

View File

@ -0,0 +1 @@
package vmwarefusion

View File

@ -0,0 +1 @@
package vmwarevcloudair

View File

@ -0,0 +1 @@
package errors

View File

@ -0,0 +1 @@
package errors

View File

@ -0,0 +1 @@
package errors

View File

@ -0,0 +1 @@
package errors

View File

@ -0,0 +1 @@
package errors

View File

@ -0,0 +1 @@
package errors

View File

@ -0,0 +1 @@
package errors

View File

@ -0,0 +1 @@
package errors

View File

@ -0,0 +1 @@
package vmwarevsphere

View File

@ -0,0 +1 @@
package vmwarevsphere

View File

@ -0,0 +1 @@
package vmwarevsphere

17
script/coverage Executable file
View File

@ -0,0 +1,17 @@
#!/bin/bash
set -e
docker build -t docker-machine .
if [[ "$1" == "serve" ]]; then
SERVE=yes
else
SERVE=no
fi
docker run -it \
-e IN_CONTAINER=yes \
-e SERVE=${SERVE} \
-p 8000:8000 \
--rm docker-machine \
./script/generate-coverage

55
script/generate-coverage Executable file
View File

@ -0,0 +1,55 @@
#!/bin/bash
set -e
COVERAGE_DIR=/tmp/coverage
generate_coverage_for_dir () {
echo
echo "Generating coverage report for $1..."
cd "$1" >/dev/null
PKG_COVERAGE_DIR=${COVERAGE_DIR}/"$1"
PKG_PROFILE=${PKG_COVERAGE_DIR}/profile.txt
mkdir -p ${PKG_COVERAGE_DIR}
go test -covermode=set -coverprofile=${PKG_PROFILE}
go tool cover -html=${PKG_PROFILE} -o ${PKG_COVERAGE_DIR}/index.html
cd - >/dev/null
echo "Done generating coverage for $1."
for f in $(ls "$1"); do
REL_PATH="$1/$f"
for exclude in ${EXCLUDED_DIRS}; do
if [[ "$REL_PATH" == "$exclude" ]]; then
continue 2
fi
done
# If file is directory and not Godeps
# (don't worry about generating 3rd party code coverage)
if [[ -d "$REL_PATH" ]]; then
# invoke recursively
generate_coverage_for_dir ${REL_PATH}
fi
done
echo
}
if [[ "$IN_CONTAINER" == "yes" ]]; then
cd /go/src/github.com/docker
DIR="machine"
else
DIR="."
fi
# Script will bomb out on some dirs if there are no buildable source files,
# we shouldn't be checking these anyway so skip over them.
EXCLUDED_DIRS="${DIR}/Godeps ${DIR}/_integration-test ${DIR}/docs ${DIR}/script"
generate_coverage_for_dir ${DIR}
echo "Done checking and generating coverage!"
if [[ "$SERVE" == "yes" ]]; then
cd ${COVERAGE_DIR}/machine
echo "*****************************************"
echo "* Serving coverage file on port 8000... *"
echo "*****************************************"
python -m SimpleHTTPServer 8000
fi