Skip to content

Commit 5d135ad

Browse files
committed
[FAB-4134] Consolidate unit-test support config
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]>
1 parent 71f3ddc commit 5d135ad

File tree

10 files changed

+79
-360
lines changed

10 files changed

+79
-360
lines changed

core/chaincode/config.go

-82
This file was deleted.

core/chaincode/exectransaction_test.go

+32-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package chaincode
1818

1919
import (
20+
"flag"
2021
"fmt"
2122
"math/rand"
2223
"net"
@@ -33,6 +34,7 @@ import (
3334

3435
"github.com/golang/protobuf/proto"
3536

37+
"github.com/hyperledger/fabric/bccsp/factory"
3638
mockpolicies "github.com/hyperledger/fabric/common/mocks/policies"
3739
"github.com/hyperledger/fabric/common/policies"
3840
"github.com/hyperledger/fabric/common/util"
@@ -45,6 +47,7 @@ import (
4547
"github.com/hyperledger/fabric/core/peer"
4648
"github.com/hyperledger/fabric/core/policy"
4749
"github.com/hyperledger/fabric/core/scc"
50+
"github.com/hyperledger/fabric/core/testutil"
4851
pb "github.com/hyperledger/fabric/protos/peer"
4952
putils "github.com/hyperledger/fabric/protos/utils"
5053

@@ -1782,10 +1785,38 @@ func TestMain(m *testing.M) {
17821785
return
17831786
}
17841787

1785-
SetupTestConfig()
1788+
setupTestConfig()
17861789
os.Exit(m.Run())
17871790
}
17881791

1792+
func setupTestConfig() {
1793+
flag.Parse()
1794+
1795+
// Now set the configuration file
1796+
viper.SetEnvPrefix("CORE")
1797+
viper.AutomaticEnv()
1798+
replacer := strings.NewReplacer(".", "_")
1799+
viper.SetEnvKeyReplacer(replacer)
1800+
viper.SetConfigName("chaincodetest") // name of config file (without extension)
1801+
viper.AddConfigPath("./") // path to look for the config file in
1802+
err := viper.ReadInConfig() // Find and read the config file
1803+
if err != nil { // Handle errors reading the config file
1804+
panic(fmt.Errorf("Fatal error config file: %s \n", err))
1805+
}
1806+
1807+
testutil.SetupTestLogging()
1808+
1809+
// Set the number of maxprocs
1810+
var numProcsDesired = viper.GetInt("peer.gomaxprocs")
1811+
chaincodeLogger.Debugf("setting Number of procs to %d, was %d\n", numProcsDesired, runtime.GOMAXPROCS(2))
1812+
1813+
// Init the BCCSP
1814+
err = factory.InitFactories(nil)
1815+
if err != nil {
1816+
panic(fmt.Errorf("Could not initialize BCCSP Factories [%s]", err))
1817+
}
1818+
}
1819+
17891820
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) {
17901821
chaincodeSpec := &pb.ChaincodeSpec{
17911822
ChaincodeId: &pb.ChaincodeID{

core/container/config.go

-92
This file was deleted.

core/container/dockercontroller/dockercontroller_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ func TestHostConfig(t *testing.T) {
5454
}
5555

5656
func TestGetDockerHostConfig(t *testing.T) {
57-
os.Setenv("HYPERLEDGER_VM_DOCKER_HOSTCONFIG_NETWORKMODE", "overlay")
58-
os.Setenv("HYPERLEDGER_VM_DOCKER_HOSTCONFIG_CPUSHARES", fmt.Sprint(1024*1024*1024*2))
57+
os.Setenv("CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE", "overlay")
58+
os.Setenv("CORE_VM_DOCKER_HOSTCONFIG_CPUSHARES", fmt.Sprint(1024*1024*1024*2))
5959
coreutil.SetupTestConfig()
6060
hostConfig := getDockerHostConfig()
6161
testutil.AssertNotNil(t, hostConfig)

core/container/vm_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"testing"
2323

2424
"github.com/hyperledger/fabric/common/util"
25+
"github.com/hyperledger/fabric/core/testutil"
2526
pb "github.com/hyperledger/fabric/protos/peer"
2627
"github.com/stretchr/testify/assert"
2728
"golang.org/x/net/context"
@@ -30,7 +31,7 @@ import (
3031
func TestMain(m *testing.M) {
3132
flag.BoolVar(&runTests, "run-controller-tests", false, "run tests")
3233
flag.Parse()
33-
SetupTestConfig()
34+
testutil.SetupTestConfig()
3435
os.Exit(m.Run())
3536
}
3637

core/endorser/config.go

-88
This file was deleted.

0 commit comments

Comments
 (0)