-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-8658] peer mock functions to separate file
Production and test should not be co-mingled in the same files. The mock initialization functions are currently referenced by code outside of the peer package and can't be moved to an _test.go file right now without introducing compilation errors. Change-Id: I179c21f9268d464b4a8d583066e5f122b2141dc4 Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
- Loading branch information
Showing
3 changed files
with
56 additions
and
45 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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package peer | ||
|
||
import ( | ||
configtxtest "github.com/hyperledger/fabric/common/configtx/test" | ||
mockchannelconfig "github.com/hyperledger/fabric/common/mocks/config" | ||
mockconfigtx "github.com/hyperledger/fabric/common/mocks/configtx" | ||
mockpolicies "github.com/hyperledger/fabric/common/mocks/policies" | ||
"github.com/hyperledger/fabric/core/ledger" | ||
"github.com/hyperledger/fabric/core/ledger/ledgermgmt" | ||
) | ||
|
||
//MockInitialize resets chains for test env | ||
func MockInitialize() { | ||
ledgermgmt.InitializeTestEnvWithCustomProcessors(ConfigTxProcessors) | ||
chains.list = nil | ||
chains.list = make(map[string]*chain) | ||
chainInitializer = func(string) { return } | ||
} | ||
|
||
// MockCreateChain used for creating a ledger for a chain for tests | ||
// without having to join | ||
func MockCreateChain(cid string) error { | ||
var ledger ledger.PeerLedger | ||
var err error | ||
|
||
if ledger = GetLedger(cid); ledger == nil { | ||
gb, _ := configtxtest.MakeGenesisBlock(cid) | ||
if ledger, err = ledgermgmt.CreateLedger(gb); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
chains.Lock() | ||
defer chains.Unlock() | ||
|
||
chains.list[cid] = &chain{ | ||
cs: &chainSupport{ | ||
Resources: &mockchannelconfig.Resources{ | ||
PolicyManagerVal: &mockpolicies.Manager{ | ||
Policy: &mockpolicies.Policy{}, | ||
}, | ||
ConfigtxValidatorVal: &mockconfigtx.Validator{}, | ||
}, | ||
ledger: ledger, | ||
}, | ||
} | ||
|
||
return nil | ||
} |
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