Skip to content

Commit

Permalink
Add capability to run specific unit test(s)
Browse files Browse the repository at this point in the history
Prior to this changeset, running "make unit-tests"
will execute go tests for all Fabric packages.
This changeset adds the ability to selectively run
go tests for specified packages while still using
the build environment (which is useful to emulate
what is run in CI).  To do this, the following
changes were made:

- Added TEST_PKGS environment variable to
unit-tests/run.sh.  If not set, you default
to running tests for all packages

- Modified unit-test/docker-compose.yaml to
pass TEST_PKGS into the Docker build env

TEST_PKGS expects a space-delimited list of
qualified Go pkg URLs like you would pass to
the go list command.

To use the new feature, export / set TEST_PKGS
prior to running make unit-tests :

export TEST_PKGS=\
"github.com/hyperledger/fabric/core/comm/... \
github.com/hyperledger/fabric/gossip/..."
make unit-tests

*latest patch uses a shorter syntax in run.sh

Fixes FAB-1455

Change-Id: I5d889f3f25ad3b628c463202939638ba6906d85f
Signed-off-by: Gari Singh <gari.r.singh@gmail.com>
  • Loading branch information
mastersingh24 committed Dec 28, 2016
1 parent 2a123fe commit 47b185f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions unit-test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ unit-tests:
- UNIT_TEST_PEER_IP=vp
- GO_LDFLAGS
- OUTPUT
- TEST_PKGS=${TEST_PKGS}
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ${GOPATH}/src/github.com/hyperledger/fabric:/opt/gopath/src/github.com/hyperledger/fabric
Expand Down
7 changes: 5 additions & 2 deletions unit-test/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
set -e
ARCH=`uname -m`

echo -n "Obtaining list of tests to run.."
#check to see if TEST_PKGS is set else use default (all packages)
TEST_PKGS=${TEST_PKGS:-github.com/hyperledger/fabric/...}
echo -n "Obtaining list of tests to run for the following packages: ${TEST_PKGS}"

# Some examples don't play nice with `go test`
PKGS=`go list github.com/hyperledger/fabric/... 2> /dev/null | \
PKGS=`go list ${TEST_PKGS} 2> /dev/null | \
grep -v /vendor/ | \
grep -v /build/ | \
grep -v /examples/chaincode/chaintool/ | \
Expand Down

0 comments on commit 47b185f

Please sign in to comment.