-
Notifications
You must be signed in to change notification settings - Fork 1
/
ledger_mgmt_test_exports.go
84 lines (71 loc) · 2.1 KB
/
ledger_mgmt_test_exports.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package ledgermgmt
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/mcc-github/blockchain/common/metrics/disabled"
"github.com/mcc-github/blockchain/core/chaincode/platforms"
"github.com/mcc-github/blockchain/core/chaincode/platforms/golang"
"github.com/mcc-github/blockchain/core/ledger"
"github.com/mcc-github/blockchain/core/ledger/mock"
)
func InitializeTestEnv(t *testing.T) (cleanup func()) {
cleanup, err := InitializeTestEnvWithInitializer(nil)
if err != nil {
t.Fatalf("Failed to initialize test environment: %s", err)
}
return cleanup
}
func InitializeTestEnvWithInitializer(initializer *Initializer) (cleanup func(), err error) {
return InitializeExistingTestEnvWithInitializer(initializer)
}
func InitializeExistingTestEnvWithInitializer(initializer *Initializer) (cleanup func(), err error) {
if initializer == nil {
initializer = &Initializer{}
}
if initializer.DeployedChaincodeInfoProvider == nil {
initializer.DeployedChaincodeInfoProvider = &mock.DeployedChaincodeInfoProvider{}
}
if initializer.MetricsProvider == nil {
initializer.MetricsProvider = &disabled.Provider{}
}
if initializer.PlatformRegistry == nil {
initializer.PlatformRegistry = platforms.NewRegistry(&golang.Platform{})
}
if initializer.Config == nil {
rootPath, err := ioutil.TempDir("", "ltestenv")
if err != nil {
return nil, err
}
initializer.Config = &ledger.Config{
RootFSPath: rootPath,
StateDB: &ledger.StateDB{
LevelDBPath: filepath.Join(rootPath, "stateleveldb"),
},
}
}
if initializer.Config.PrivateData == nil {
initializer.Config.PrivateData = &ledger.PrivateData{
StorePath: filepath.Join(initializer.Config.RootFSPath, "pvtdataStore"),
MaxBatchSize: 5000,
BatchesInterval: 1000,
PurgeInterval: 100,
}
}
if initializer.Config.HistoryDB == nil {
initializer.Config.HistoryDB = &ledger.HistoryDB{
Enabled: true,
}
}
initialize(initializer)
cleanup = func() {
Close()
os.RemoveAll(initializer.Config.RootFSPath)
}
return cleanup, nil
}