forked from IBM-Blockchain-Starter-Kit/build-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Includes minor changes to testcases to keep temporary test files inside the testcases' temporary directory Related to IBM-Blockchain-Starter-Kit#87 Signed-off-by: James Taylor <[email protected]>
- Loading branch information
Showing
4 changed files
with
39 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ bats/ | |
bats-mock/ | ||
*.tgz | ||
**/.DS_Store | ||
TEST-report.xml | ||
tst-output.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ github.com/hyperledger/fabric/core/chaincode/lib/[email protected] | |
|
||
## Unit tests | ||
|
||
Make sure you have installed [jq](https://stedolan.github.io/jq/download/) before attempting to run the test cases on your local system. You should also have bash 4 or a later version installed on your system. If running tests on macOS, you can use Homebrew to upgrade bash: `brew update && brew install bash`. | ||
Make sure you have installed [jq](https://stedolan.github.io/jq/download/) before attempting to run the test cases on your local system. | ||
|
||
This project is tested using Bats when making pull requests. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,13 @@ setup() { | |
testcase_dirname="$(mktemp -d)" | ||
|
||
setup_script_dir "${src_dir}" "${testcase_dirname}" | ||
|
||
testcase_gopath=${testcase_dirname}/go | ||
echo "export GOPATH=${testcase_gopath}" >> "${SCRIPT_DIR}/common/env.sh" | ||
} | ||
|
||
teardown() { | ||
cleanup_stubs | ||
} | ||
|
||
@test "vendor-dependencies.sh: should exist and be executable" { | ||
|
@@ -16,7 +23,8 @@ setup() { | |
|
||
@test "vendor-dependencies.sh: fetch_dependencies should run without errors when .govendor_packages file does not exist" { | ||
|
||
cat << EOF > sample-config.json | ||
mkdir -p "${testcase_gopath}/src" | ||
cat << EOF > "${testcase_gopath}/src/sample-config.json" | ||
{ | ||
"org1": { | ||
"chaincode": [ | ||
|
@@ -45,21 +53,18 @@ setup() { | |
} | ||
EOF | ||
|
||
mkdir -p "${PWD}/src/chaincode/contract1" | ||
mkdir -p "${testcase_gopath}/src/chaincode/contract1" | ||
|
||
stub go \ | ||
"get -u github.com/kardianos/govendor : true" | ||
|
||
source "${SCRIPT_DIR}/go-chaincode/vendor-dependencies.sh" | ||
|
||
run fetch_dependencies "sample-config.json" | ||
|
||
# Clean up before assertions | ||
rm sample-config.json | ||
rm -rf "${PWD}/src/chaincode" | ||
unstub go | ||
run fetch_dependencies "${testcase_gopath}/src/sample-config.json" | ||
|
||
# Assertions | ||
echo $output | ||
unstub go | ||
[ $status -eq 0 ] | ||
[ "${lines[0]}" = "Processing org 'org1'..." ] | ||
[ "${lines[1]}" = "About to fetch dependencies for 'chaincode/contract1'" ] | ||
|
@@ -72,7 +77,8 @@ EOF | |
|
||
@test "vendor-dependencies.sh: fetch_dependencies should run without errors when .govendor_packages file has new lines and white spaces; also testing with multiple .govendor_packages file (one per chaincode component)" { | ||
|
||
cat << EOF > sample-config.json | ||
mkdir -p "${testcase_gopath}/src" | ||
cat << EOF > "${testcase_gopath}/src/sample-config.json" | ||
{ | ||
"org1": { | ||
"chaincode": [ | ||
|
@@ -97,10 +103,10 @@ EOF | |
} | ||
EOF | ||
|
||
mkdir -p "${PWD}/src/chaincode/contract1" | ||
mkdir -p "${PWD}/src/chaincode/contract2" | ||
mkdir -p "${testcase_gopath}/src/chaincode/contract1" | ||
mkdir -p "${testcase_gopath}/src/chaincode/contract2" | ||
|
||
cat << EOF > "${PWD}/src/chaincode/contract1/.govendor_packages" | ||
cat << EOF > "${testcase_gopath}/src/chaincode/contract1/.govendor_packages" | ||
|
@@ -112,11 +118,12 @@ EOF | |
EOF | ||
|
||
cat << EOF > "${PWD}/src/chaincode/contract2/.govendor_packages" | ||
cat << EOF > "${testcase_gopath}/src/chaincode/contract2/.govendor_packages" | ||
github.com/hyperledger/fabric/core/chaincode/lib/[email protected] | ||
github.com/hyperledger/fabric/core/chaincode/lib/[email protected] | ||
github.com/hyperledger/fabric/core/chaincode/lib/[email protected] | ||
|
@@ -130,26 +137,23 @@ EOF | |
stub govendor \ | ||
"init : true" \ | ||
"fetch *github.com/hyperledger/fabric/core/chaincode/lib/[email protected]* : true" \ | ||
"init : true" \ | ||
"fetch *github.com/hyperledger/fabric/core/chaincode/lib/[email protected]* : true" | ||
"init : true" \ | ||
"fetch *github.com/hyperledger/fabric/core/chaincode/lib/[email protected]* : true" \ | ||
"fetch *github.com/hyperledger/fabric/core/chaincode/lib/[email protected]* : true" | ||
|
||
stub cp \ | ||
"-r vendor : true" \ | ||
"-r vendor : true" | ||
|
||
source "${SCRIPT_DIR}/go-chaincode/vendor-dependencies.sh" | ||
|
||
run fetch_dependencies "sample-config.json" | ||
|
||
# Clean up before assertions | ||
rm sample-config.json | ||
rm -rf "${PWD}/src/chaincode" | ||
unstub cp | ||
unstub govendor | ||
unstub go | ||
run fetch_dependencies "${testcase_gopath}/src/sample-config.json" | ||
|
||
# Assertions | ||
echo $output | ||
unstub cp | ||
unstub govendor | ||
unstub go | ||
[ $status -eq 0 ] | ||
[ "${lines[0]}" = "Processing org 'org1'..." ] | ||
[ "${lines[1]}" = "About to fetch dependencies for 'chaincode/contract1'" ] | ||
|
@@ -159,9 +163,6 @@ EOF | |
[ "${lines[8]}" = "About to fetch dependencies for 'chaincode/contract2'" ] | ||
[ "${lines[10]}" = "Found .govendor_packages file." ] | ||
[ "${lines[11]}" = "Fetching github.com/hyperledger/fabric/core/chaincode/lib/[email protected]" ] | ||
[ "${lines[14]}" = "Finished looking up dependencies for chaincode component." ] | ||
} | ||
|
||
teardown() { | ||
cleanup_stubs | ||
[ "${lines[12]}" = "Fetching github.com/hyperledger/fabric/core/chaincode/lib/[email protected]" ] | ||
[ "${lines[15]}" = "Finished looking up dependencies for chaincode component." ] | ||
} |