Skip to content
This repository was archived by the owner on Aug 13, 2024. It is now read-only.

Chaincode Build lib Repository

mayarobin edited this page Aug 9, 2018 · 26 revisions

Table of Contents

All About the Build-lib

The Build-lib Repository is contains the scripts that prepare, build, test, and deploy your chaincode. When each l

Environment Variables

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}

Testing Frameworks

Travis CI

When pull requests are created against the build-lib repository, they will be automatically checked using travis integration

Bats

What is Bats?

Bats, or Bash Automated Testing System,is the testing framework that we use to produce tests for our scripts in the build-lib repository.

Installing Bats

  1. Navigate to the top level directory and run the following command:
$ brew install bats-core
  1. Install bats-mock to enable stubbing

Note – Bats can also be installed using from the source or run in a Docker image.

Setting up a Bats file

Sample Test:

@test "test.sh: should exist and be executable" {
  [ -x "${SCRIPT_DIR}/go-chaincode/build.sh" ]
}

Running and Analyzing a Test

• "✓" 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 

Stubbing

  1. 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

Bats Resources

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

Important things to note

  1. Stubbing only applies to bats run <program> context
  2. Stubbing is not applied to expressions within $() stored in variables
  3. Environment variables will be effective within script executed in bats run context only if exported within the test, but will be effective without being exported in the test when executed in bash source <program> context
  4. Stubbing commands within tests may interfere with identical commands used in setup hook
  5. 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)

Clone this wiki locally