From c14eda6d3d735054b8b79e7968397905192edafb Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Thu, 30 Jun 2016 13:41:26 +0800 Subject: [PATCH 1/3] Support testing multiple package. Solution: https://goo.gl/QkJTrA ref: https://github.com/golang/go/issues/6909 Signed-off-by: Bo-Yi Wu --- Makefile | 5 ++++- go.test.sh | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100755 go.test.sh diff --git a/Makefile b/Makefile index 36974cb..00be0e2 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,9 @@ endif build: clean sh script/build.sh $(VERSION) +coverage: + sh go.test.sh atomic + test: redis_test boltdb_test memory_test config_test go test -v -cover -covermode=count -coverprofile=coverage.txt ./gorush/... @@ -41,7 +44,7 @@ config_test: init go test -v -cover -covermode=count -coverprofile=coverage.txt ./config/... html: - go tool cover -html=coverage.txt && unlink coverage.txt + go tool cover -html=coverage.txt docker_build: clean tar -zcvf build.tar.gz gorush.go gorush config storage Makefile glide.lock glide.yaml diff --git a/go.test.sh b/go.test.sh new file mode 100755 index 0000000..96295a8 --- /dev/null +++ b/go.test.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +set -e + +output() { + printf "\033[32m" + echo $1 + printf "\033[0m" + exit 0 +} + +coverage_mode=$1 + +test -z $coverage_mode && output "Usage: $0 coverage_mode" + +test -f coverage.txt && rm -rf coverage.txt +echo "mode: ${coverage_mode}" > coverage.txt + +for d in ./storage/boltdb/... ./storage/redis/... ./storage/memory/... ./config/... ./gorush/...; 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 From 84c13e6d42fe9c234a31280379373e8e3e677d5a Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Thu, 30 Jun 2016 13:47:10 +0800 Subject: [PATCH 2/3] add nil testing for memory. Signed-off-by: Bo-Yi Wu --- storage/memory/memory_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/storage/memory/memory_test.go b/storage/memory/memory_test.go index 491dfd7..7957177 100644 --- a/storage/memory/memory_test.go +++ b/storage/memory/memory_test.go @@ -10,6 +10,8 @@ func TestMemoryEngine(t *testing.T) { memory := New() + assert.Nil(t, memory.Init()) + memory.AddTotalCount(1) val = memory.GetTotalCount() assert.Equal(t, int64(1), val) From 1768d259fd46905a3cef7329c27edd70f491b012 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Thu, 30 Jun 2016 14:07:29 +0800 Subject: [PATCH 3/3] update test command. Signed-off-by: Bo-Yi Wu --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index cd5d235..3f7121e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,7 +30,7 @@ install: - go get github.com/mattn/goveralls script: - - make test + - make coverage - $(go env GOPATH | awk 'BEGIN{FS=":"} {print $1}')/bin/goveralls -coverprofile=coverage.txt -service=travis-ci -repotoken=$COVERALLS_TOKEN