commit
46ab3763a9
|
@ -28,14 +28,10 @@ key.pem
|
|||
config.yml
|
||||
bin/*
|
||||
.DS_Store
|
||||
coverage.txt
|
||||
coverage.xml
|
||||
report.xml
|
||||
gorush/log/*.log
|
||||
build.tar.gz
|
||||
gorush.tar.gz
|
||||
gorush.db
|
||||
vendor
|
||||
lint.txt
|
||||
vet.txt
|
||||
Dockerfile.tmp
|
||||
.cover
|
||||
|
|
|
@ -31,7 +31,7 @@ install:
|
|||
|
||||
script:
|
||||
- make coverage
|
||||
- $(go env GOPATH | awk 'BEGIN{FS=":"} {print $1}')/bin/goveralls -coverprofile=coverage.txt
|
||||
- $(go env GOPATH | awk 'BEGIN{FS=":"} {print $1}')/bin/goveralls -coverprofile=.cover/coverage.txt
|
||||
-service=travis-ci -repotoken=$COVERALLS_TOKEN
|
||||
|
||||
after_success:
|
||||
|
@ -41,4 +41,4 @@ after_success:
|
|||
&& test "$TRAVIS_PULL_REQUEST" == "false" && cd $TRAVIS_BUILD_DIR && make docker_build
|
||||
- test "$TRAVIS_BRANCH" == "master" && test "$TRAVIS_GO_VERSION" == "1.6.2"
|
||||
&& test "$TRAVIS_PULL_REQUEST" == "false" && cd $TRAVIS_BUILD_DIR && make deploy tag=latest
|
||||
- bash <(curl -s https://codecov.io/bash)
|
||||
- bash <(curl -s https://codecov.io/bash) -f .cover/coverage.txt
|
||||
|
|
47
Makefile
47
Makefile
|
@ -25,25 +25,25 @@ build: clean
|
|||
sh script/build.sh $(VERSION)
|
||||
|
||||
coverage:
|
||||
sh go.test.sh atomic
|
||||
sh ./script/coverage.sh testing atomic
|
||||
|
||||
test: redis_test boltdb_test memory_test config_test
|
||||
go test -v -cover -covermode=count -coverprofile=coverage.txt ./gorush/...
|
||||
go test -v -cover ./gorush/...
|
||||
|
||||
redis_test: init
|
||||
go test -v -cover -covermode=count -coverprofile=coverage.txt ./storage/redis/...
|
||||
go test -v -cover ./storage/redis/...
|
||||
|
||||
boltdb_test: init
|
||||
go test -v -cover -covermode=count -coverprofile=coverage.txt ./storage/boltdb/...
|
||||
go test -v -cover ./storage/boltdb/...
|
||||
|
||||
memory_test: init
|
||||
go test -v -cover -covermode=count -coverprofile=coverage.txt ./storage/memory/...
|
||||
go test -v -cover ./storage/memory/...
|
||||
|
||||
config_test: init
|
||||
go test -v -cover -covermode=count -coverprofile=coverage.txt ./config/...
|
||||
go test -v -cover ./config/...
|
||||
|
||||
html:
|
||||
go tool cover -html=coverage.txt
|
||||
go tool cover -html=.cover/coverage.txt
|
||||
|
||||
docker_build: clean
|
||||
tar -zcvf build.tar.gz gorush.go gorush config storage Makefile glide.lock glide.yaml
|
||||
|
@ -68,6 +68,10 @@ endif
|
|||
|
||||
install:
|
||||
@which glide || (curl https://glide.sh/get | sh)
|
||||
@which go-junit-report || go get -u github.com/jstemmer/go-junit-report
|
||||
@which gocov || go get -u github.com/axw/gocov/gocov
|
||||
@which gocov-xml || go get -u github.com/AlekSi/gocov-xml
|
||||
@which golint || go get -u github.com/golang/lint/golint
|
||||
@glide install
|
||||
|
||||
update:
|
||||
|
@ -77,7 +81,32 @@ fmt:
|
|||
@echo $(TARGETS_NOVENDOR) | xargs go fmt
|
||||
|
||||
lint:
|
||||
@golint -set_exit_status=1 gorush/
|
||||
@golint -set_exit_status=1 ./...
|
||||
|
||||
vet:
|
||||
@go vet -n -x ./...
|
||||
|
||||
junit_report:
|
||||
sh ./script/coverage.sh junit
|
||||
|
||||
coverage_report:
|
||||
sh ./script/coverage.sh coverage
|
||||
|
||||
lint_report:
|
||||
sh ./script/coverage.sh lint
|
||||
|
||||
vet_report:
|
||||
sh ./script/coverage.sh vet
|
||||
|
||||
cloc_report:
|
||||
sh ./script/coverage.sh cloc
|
||||
|
||||
report: junit_report coverage_report lint_report vet_report cloc_report
|
||||
|
||||
clean:
|
||||
-rm -rf build.tar.gz gorush.tar.gz bin/* coverage.txt gorush.tar.gz gorush/gorush.db storage/boltdb/gorush.db
|
||||
-rm -rf build.tar.gz \
|
||||
gorush.tar.gz bin/* \
|
||||
gorush.tar.gz \
|
||||
gorush/gorush.db \
|
||||
storage/boltdb/gorush.db \
|
||||
.cover
|
||||
|
|
|
@ -3,7 +3,7 @@ FROM golang:1.6.2-alpine
|
|||
MAINTAINER Bo-Yi Wu <appleboy.tw@gmail.com>
|
||||
|
||||
RUN apk update \
|
||||
&& apk add git make curl && rm -rf /var/cache/apk/*
|
||||
&& apk add git make curl perl && rm -rf /var/cache/apk/*
|
||||
|
||||
# install glide package management.
|
||||
RUN curl https://glide.sh/get | sh
|
||||
|
|
|
@ -9,4 +9,6 @@ sed -i"" -e "s/localhost/redis/g" config/config.go
|
|||
sed -i"" -e "s/localhost/redis/g" config/config_test.go
|
||||
sed -i"" -e "s/localhost/redis/g" gorush/status_test.go
|
||||
sed -i"" -e "s/localhost/redis/g" storage/redis/redis_test.go
|
||||
make install && make test
|
||||
make install
|
||||
make coverage
|
||||
make report
|
||||
|
|
26
go.test.sh
26
go.test.sh
|
@ -1,26 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
output() {
|
||||
printf "\033[32m"
|
||||
echo $1
|
||||
printf "\033[0m"
|
||||
exit 1
|
||||
}
|
||||
|
||||
coverage_mode=$1
|
||||
|
||||
test -z $coverage_mode && output "Usage: $0 coverage_mode"
|
||||
test -z $(which glide) && output "glide command not found"
|
||||
|
||||
test -f coverage.txt && rm -rf coverage.txt
|
||||
echo "mode: ${coverage_mode}" > coverage.txt
|
||||
|
||||
for d in $(go list ./... | grep -v vendor); do
|
||||
go test -v -cover -coverprofile=profile.out -covermode=${coverage_mode} $d
|
||||
if [ -f profile.out ]; then
|
||||
sed '1d' profile.out >> coverage.txt
|
||||
rm profile.out
|
||||
fi
|
||||
done
|
|
@ -24,6 +24,7 @@ func PrintGoRushVersion() {
|
|||
version,
|
||||
runtime.Compiler,
|
||||
runtime.Version())
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
// VersionMiddleware : add version on header.
|
||||
|
|
|
@ -0,0 +1,113 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Generate test coverage statistics for Go packages.
|
||||
#
|
||||
|
||||
set -e
|
||||
|
||||
output() {
|
||||
printf "\033[32m"
|
||||
echo $1
|
||||
printf "\033[0m"
|
||||
|
||||
if [ "$2" = 1 ]; then
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
workdir=".cover"
|
||||
coverage_report="$workdir/coverage.txt"
|
||||
coverage_xml_report="$workdir/coverage.xml"
|
||||
junit_report="$workdir/junit.txt"
|
||||
junit_xml_report="$workdir/report.xml"
|
||||
lint_report="$workdir/lint.txt"
|
||||
vet_report="$workdir/vet.txt"
|
||||
cloc_report="$workdir/cloc.xml"
|
||||
packages=$(go list ./... | grep -v vendor)
|
||||
|
||||
test -d $workdir || mkdir -p $workdir
|
||||
|
||||
show_help() {
|
||||
cat << EOF
|
||||
Generate test coverage statistics for Go packages.
|
||||
|
||||
testing [set|count|atomic] Run go testing for all packages
|
||||
coverage Generate coverage report for all packages
|
||||
junit Generate coverage xml report for junit plugin
|
||||
lint Generate Lint report for all packages
|
||||
vet Generate Vet report for all packages
|
||||
cloc Generate Count Lines of Code report for all files
|
||||
EOF
|
||||
}
|
||||
|
||||
testing() {
|
||||
test -f ${junit_report} && rm -f ${junit_report}
|
||||
coverage_mode=$@
|
||||
output "Running ${coverage_mode} mode for coverage."
|
||||
for pkg in $packages; do
|
||||
f="$workdir/$(echo $pkg | tr / -).cover"
|
||||
output "Testing coverage report for ${pkg}"
|
||||
go test -v -cover -coverprofile=${f} -covermode=${coverage_mode} $pkg | tee -a ${junit_report}
|
||||
done
|
||||
|
||||
output "Convert all packages coverage report to $coverage_report"
|
||||
echo "mode: $coverage_mode" > "$coverage_report"
|
||||
grep -h -v "^mode:" "$workdir"/*.cover >> "$coverage_report"
|
||||
}
|
||||
|
||||
generate_cover_report() {
|
||||
gocov convert ${coverage_report} | gocov-xml > ${coverage_xml_report}
|
||||
}
|
||||
|
||||
generate_junit_report() {
|
||||
cat $junit_report | go-junit-report > ${junit_xml_report}
|
||||
}
|
||||
|
||||
generate_lint_report() {
|
||||
for pkg in $packages; do
|
||||
output "Go Lint report for ${pkg}"
|
||||
golint ${pkg} | tee -a ${lint_report}
|
||||
done
|
||||
}
|
||||
|
||||
generate_vet_report() {
|
||||
for pkg in $packages; do
|
||||
output "Go Vet report for ${pkg}"
|
||||
go vet -n -x ${pkg} | tee -a ${vet_report}
|
||||
done
|
||||
}
|
||||
|
||||
generate_cloc_report() {
|
||||
case "$OSTYPE" in
|
||||
darwin*)
|
||||
which cloc || brew install cloc ;;
|
||||
linux*)
|
||||
which cloc || apt-get install cloc ;;
|
||||
*)
|
||||
curl https://raw.githubusercontent.com/AlDanial/cloc/master/cloc -o /usr/bin/cloc
|
||||
chmod 755 /usr/bin/cloc
|
||||
esac
|
||||
|
||||
cloc --by-file --xml --out=${cloc_report} --exclude-dir=vendor,Godeps,.cover .
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
"")
|
||||
show_help ;;
|
||||
testing)
|
||||
mode="set"
|
||||
test -z $2 || mode=$2
|
||||
testing $mode ;;
|
||||
coverage)
|
||||
generate_cover_report ;;
|
||||
junit)
|
||||
generate_junit_report ;;
|
||||
lint)
|
||||
generate_lint_report ;;
|
||||
vet)
|
||||
generate_vet_report ;;
|
||||
cloc)
|
||||
generate_cloc_report ;;
|
||||
*)
|
||||
show_help ;;
|
||||
esac
|
Loading…
Reference in New Issue