-
Notifications
You must be signed in to change notification settings - Fork 2
Chaincode Build lib Repository
Table of Contents
The Build-lib Repository is contains the scripts that prepare, build, test, and deploy your chaincode. When each l
The environment variables can be
env.sh
#!/usr/bin/env bash
ROOTDIR=${ROOTDIR:=$PWD}
export GO_VERSION=${GO_VERSION:="1.9.2"}
# set location for go executables
export GOROOT=${ROOTDIR}/go
export PATH=${GOROOT}/bin:$PATH
export GOPATH=${ROOTDIR}
export CONFIGPATH=${CONFIGPATH:="deploy_config.json"}
export HLF_VERSION=${HLF_VERSION:="1.0.4"}
export FABRIC_SRC_DIR=${ROOTDIR}/fabric-${HLF_VERSION}
When pull requests are created against the build-lib repository, they will be automatically checked using travis integration
Bats, or Bash Automated Testing System,is the testing framework that we use to produce tests for our scripts in the build-lib repository.
- Navigate to the top level directory and run the following command:
$ brew install bats-core
- Install bats-mock to enable stubbing
Note – Bats can also be installed using from the source or run in a Docker image.
Sample Test:
@test "test.sh: should exist and be executable" {
[ -x "${SCRIPT_DIR}/go-chaincode/build.sh" ]
}
• "✓" for passed test
• “x” for failure
• Exits with a 1 for failure and 0 for pass
Sample Output:
x name of test one
✓ name of test two
2 tests, 1 failures
Bats is TAP-compliant: Automatic when not connected to terminal To force TAP use “--tap” :
bats --tap test.bats
Sample Output:
1..2
ok 1 name of test one
ok 2 name of test two
- Navigate to the top level directory and run the following command:
git clone --branch v1.0.1 --depth 1 https://github.com/jasonkarns/bats-mock.git
Once you have installed Bats, you will have access to the bats manuals:
$ man 1 bats
$ man 7 bats
Further documentation is provided on the Bats Repositories:
Bats-core repository README: https://github.com/bats-core/bats-core/blob/master/README.md
Original Bats repo wiki: https://github.com/sstephenson/bats/wiki/
Original Bats repo README:https://github.com/sstephenson/bats/blob/master/README.md
- Stubbing only applies to bats
run <program>context - Stubbing is not applied to expressions within
$()stored in variables - Environment variables will be effective within script executed in
bats runcontext only if exported within the test, but will be effective without being exported in the test when executed in bashsource <program>context - Stubbing commands within tests may interfere with identical commands used in setup hook
- Stub state is saved locally in the file structure, which can lead to unexpected behavior
If you hit number 5, there is now a cleanup_stubs helper which you can add to the teardown function. (JT)