Skip to content

Commit

Permalink
Merge pull request bittorrent#446 from TRON-US/BTFS-1782
Browse files Browse the repository at this point in the history
BTFS-1782 add steps for showing unit test coverage
  • Loading branch information
Eric Chen authored Apr 21, 2020
2 parents d2ca13b + 7806fb7 commit 3ded220
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 2 deletions.
5 changes: 4 additions & 1 deletion Dockerfile.unit_testing
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ ENV SRC_DIR /go-btfs
ENV TEST_NO_FUSE 1
ENV PATH="/usr/local/go/bin:${PATH}"

#set test coverage output
ENV TEST_COVERAGE_OUTPUT="/btfs_data/tests_coverage"

#set timeout value for unit tests
ENV GOTFLAGS -timeout 3m

Expand All @@ -25,4 +28,4 @@ COPY . $SRC_DIR
RUN git init && git add .

# by default lets run the go fmt, tidy and unit tests
CMD make test_go_fmt test_go_mod test_go_test build
CMD make test_go_fmt test_go_mod test_go_test test_coverage_output test_coverage_html build
1 change: 1 addition & 0 deletions coverpkg_list.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github.com/TRON-US/go-btfs/assets/...,github.com/TRON-US/go-btfs/cmd/...,github.com/TRON-US/go-btfs/commands/...,github.com/TRON-US/go-btfs/core/...,github.com/TRON-US/go-btfs/keystore/...,github.com/TRON-US/go-btfs/namesys/...,github.com/TRON-US/go-btfs/p2p/...,github.com/TRON-US/go-btfs/plugin/...,github.com/TRON-US/go-btfs/repo/...,github.com/TRON-US/go-btfs/thirdparty/...
26 changes: 25 additions & 1 deletion mk/golang.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,24 @@ GOTAGS ?=
unexport GOFLAGS
GOFLAGS ?=
GOTFLAGS ?=
TEST_COVERAGE_OUTPUT ?= tests_coverage

#select explicit list of packages to test
COVERPKG_LIST := $(shell cat coverpkg_list.txt)

MY_FILE := test_pkgs.txt
MY_PKGS := $(shell cat ${MY_FILE})

#select packages that dont contain a test dir to avoid build errors
NON_TEST_PKGS := $(shell go list ./... | grep -v "/test")

# Try to make building as reproducible as possible by stripping the go path.
GOFLAGS += "-asmflags=all='-trimpath=$(GOPATH)'" "-gcflags=all='-trimpath=$(GOPATH)'"

#GOTFLAGS += "-coverprofile=$(TEST_COVERAGE_OUTPUT).out" "-coverpkg=$(COVERPKG_LIST)"
GOTFLAGS += "-coverprofile=$(TEST_COVERAGE_OUTPUT).out"
#GOTFLAGS += "-coverprofile=$(TEST_COVERAGE_OUTPUT).out" "-covermode=set"

ifeq ($(tarball-is),1)
GOFLAGS += -mod=vendor
endif
Expand Down Expand Up @@ -46,9 +60,19 @@ $(GOCC) build $(go-flags-with-tags) -o /dev/null "$(call go-pkg-name,$<)"
endef

test_go_test: $$(DEPS_GO)
$(GOCC) test $(go-flags-with-tags) $(GOTFLAGS) ./...
# $(GOCC) test $(go-flags-with-tags) $(GOTFLAGS) ./...
$(GOCC) test $(go-flags-with-tags) $(GOTFLAGS) $(MY_PKGS)
.PHONY: test_go_test

#Used to display coverage per function an total at the end
test_coverage_output:
$(GOCC) tool cover -func="$(TEST_COVERAGE_OUTPUT).out"

#Generates an html report of the unit tests coverage
test_coverage_html:
$(GOCC) tool cover -html="$(TEST_COVERAGE_OUTPUT).out" -o "$(TEST_COVERAGE_OUTPUT).html"
.PHONY: test_coverage_html

test_go_build: $$(TEST_GO_BUILD)

test_go_short: GOTFLAGS += -test.short
Expand Down
69 changes: 69 additions & 0 deletions test_pkgs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
github.com/TRON-US/go-btfs
github.com/TRON-US/go-btfs/assets
github.com/TRON-US/go-btfs/cmd/btfs
github.com/TRON-US/go-btfs/cmd/btfs/util
github.com/TRON-US/go-btfs/cmd/ipfswatch
github.com/TRON-US/go-btfs/cmd/seccat
github.com/TRON-US/go-btfs/commands
github.com/TRON-US/go-btfs/core
github.com/TRON-US/go-btfs/core/bootstrap
github.com/TRON-US/go-btfs/core/commands
github.com/TRON-US/go-btfs/core/commands/cmdenv
github.com/TRON-US/go-btfs/core/commands/dag
github.com/TRON-US/go-btfs/core/commands/e
github.com/TRON-US/go-btfs/core/commands/name
github.com/TRON-US/go-btfs/core/commands/object
github.com/TRON-US/go-btfs/core/commands/rm
github.com/TRON-US/go-btfs/core/commands/storage
github.com/TRON-US/go-btfs/core/commands/store
github.com/TRON-US/go-btfs/core/commands/store/announce
github.com/TRON-US/go-btfs/core/commands/store/challenge
github.com/TRON-US/go-btfs/core/commands/store/contracts
github.com/TRON-US/go-btfs/core/commands/store/hosts
github.com/TRON-US/go-btfs/core/commands/store/info
github.com/TRON-US/go-btfs/core/commands/store/stats
github.com/TRON-US/go-btfs/core/commands/store/upload
github.com/TRON-US/go-btfs/core/commands/store/upload/ds
github.com/TRON-US/go-btfs/core/commands/store/upload/helper
github.com/TRON-US/go-btfs/core/commands/unixfs
github.com/TRON-US/go-btfs/core/coreapi
github.com/TRON-US/go-btfs/core/coredag
github.com/TRON-US/go-btfs/core/corehttp
github.com/TRON-US/go-btfs/core/corehttp/remote
github.com/TRON-US/go-btfs/core/corerepo
github.com/TRON-US/go-btfs/core/coreunix
github.com/TRON-US/go-btfs/core/escrow
github.com/TRON-US/go-btfs/core/guard
github.com/TRON-US/go-btfs/core/hub
github.com/TRON-US/go-btfs/core/mock
github.com/TRON-US/go-btfs/core/node
github.com/TRON-US/go-btfs/core/node/helpers
github.com/TRON-US/go-btfs/core/node/libp2p
github.com/TRON-US/go-btfs/core/wallet
github.com/TRON-US/go-btfs/keystore
github.com/TRON-US/go-btfs/namesys
github.com/TRON-US/go-btfs/namesys/republisher
github.com/TRON-US/go-btfs/namesys/resolve
github.com/TRON-US/go-btfs/p2p
github.com/TRON-US/go-btfs/plugin
github.com/TRON-US/go-btfs/plugin/loader
github.com/TRON-US/go-btfs/plugin/plugins/badgerds
github.com/TRON-US/go-btfs/plugin/plugins/flatfs
github.com/TRON-US/go-btfs/plugin/plugins/git
github.com/TRON-US/go-btfs/plugin/plugins/levelds
github.com/TRON-US/go-btfs/protos/contracts
github.com/TRON-US/go-btfs/protos/session
github.com/TRON-US/go-btfs/protos/shard
github.com/TRON-US/go-btfs/repo
github.com/TRON-US/go-btfs/repo/common
github.com/TRON-US/go-btfs/repo/fsrepo
github.com/TRON-US/go-btfs/repo/fsrepo/migrations
github.com/TRON-US/go-btfs/spin
github.com/TRON-US/go-btfs/tar
github.com/TRON-US/go-btfs/thirdparty/assert
github.com/TRON-US/go-btfs/thirdparty/cidv0v1
github.com/TRON-US/go-btfs/thirdparty/dir
github.com/TRON-US/go-btfs/thirdparty/notifier
github.com/TRON-US/go-btfs/thirdparty/pollEndpoint
github.com/TRON-US/go-btfs/thirdparty/unit
github.com/TRON-US/go-btfs/thirdparty/verifbs

0 comments on commit 3ded220

Please sign in to comment.