Skip to content

Commit

Permalink
[FAB-4134] Consolidate unit-test support config
Browse files Browse the repository at this point in the history
Peer code contains 5 different config.go as support configuration
for unit-tests in various packages. This changeset refactor and
consolidate them into 1 module.

Change-Id: I56866dbce1330a9a00a08f8820a16f8c75c48691
Signed-off-by: Binh Q. Nguyen <[email protected]>
  • Loading branch information
binhn committed May 24, 2017
1 parent 71f3ddc commit 5d135ad
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 360 deletions.
82 changes: 0 additions & 82 deletions core/chaincode/config.go

This file was deleted.

33 changes: 32 additions & 1 deletion core/chaincode/exectransaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package chaincode

import (
"flag"
"fmt"
"math/rand"
"net"
Expand All @@ -33,6 +34,7 @@ import (

"github.com/golang/protobuf/proto"

"github.com/hyperledger/fabric/bccsp/factory"
mockpolicies "github.com/hyperledger/fabric/common/mocks/policies"
"github.com/hyperledger/fabric/common/policies"
"github.com/hyperledger/fabric/common/util"
Expand All @@ -45,6 +47,7 @@ import (
"github.com/hyperledger/fabric/core/peer"
"github.com/hyperledger/fabric/core/policy"
"github.com/hyperledger/fabric/core/scc"
"github.com/hyperledger/fabric/core/testutil"
pb "github.com/hyperledger/fabric/protos/peer"
putils "github.com/hyperledger/fabric/protos/utils"

Expand Down Expand Up @@ -1782,10 +1785,38 @@ func TestMain(m *testing.M) {
return
}

SetupTestConfig()
setupTestConfig()
os.Exit(m.Run())
}

func setupTestConfig() {
flag.Parse()

// Now set the configuration file
viper.SetEnvPrefix("CORE")
viper.AutomaticEnv()
replacer := strings.NewReplacer(".", "_")
viper.SetEnvKeyReplacer(replacer)
viper.SetConfigName("chaincodetest") // name of config file (without extension)
viper.AddConfigPath("./") // path to look for the config file in
err := viper.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file
panic(fmt.Errorf("Fatal error config file: %s \n", err))
}

testutil.SetupTestLogging()

// Set the number of maxprocs
var numProcsDesired = viper.GetInt("peer.gomaxprocs")
chaincodeLogger.Debugf("setting Number of procs to %d, was %d\n", numProcsDesired, runtime.GOMAXPROCS(2))

// Init the BCCSP
err = factory.InitFactories(nil)
if err != nil {
panic(fmt.Errorf("Could not initialize BCCSP Factories [%s]", err))
}
}

func deployChaincode(ctx context.Context, name string, version string, chaincodeType pb.ChaincodeSpec_Type, path string, args [][]byte, creator []byte, channel string, nextBlockNumber uint64) ([]byte, *ccprovider.CCContext, error) {
chaincodeSpec := &pb.ChaincodeSpec{
ChaincodeId: &pb.ChaincodeID{
Expand Down
92 changes: 0 additions & 92 deletions core/container/config.go

This file was deleted.

4 changes: 2 additions & 2 deletions core/container/dockercontroller/dockercontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ func TestHostConfig(t *testing.T) {
}

func TestGetDockerHostConfig(t *testing.T) {
os.Setenv("HYPERLEDGER_VM_DOCKER_HOSTCONFIG_NETWORKMODE", "overlay")
os.Setenv("HYPERLEDGER_VM_DOCKER_HOSTCONFIG_CPUSHARES", fmt.Sprint(1024*1024*1024*2))
os.Setenv("CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE", "overlay")
os.Setenv("CORE_VM_DOCKER_HOSTCONFIG_CPUSHARES", fmt.Sprint(1024*1024*1024*2))
coreutil.SetupTestConfig()
hostConfig := getDockerHostConfig()
testutil.AssertNotNil(t, hostConfig)
Expand Down
3 changes: 2 additions & 1 deletion core/container/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"testing"

"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/core/testutil"
pb "github.com/hyperledger/fabric/protos/peer"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
Expand All @@ -30,7 +31,7 @@ import (
func TestMain(m *testing.M) {
flag.BoolVar(&runTests, "run-controller-tests", false, "run tests")
flag.Parse()
SetupTestConfig()
testutil.SetupTestConfig()
os.Exit(m.Run())
}

Expand Down
88 changes: 0 additions & 88 deletions core/endorser/config.go

This file was deleted.

Loading

0 comments on commit 5d135ad

Please sign in to comment.