-
Notifications
You must be signed in to change notification settings - Fork 8.8k
/
ledger_mgmt_test_exports.go
63 lines (55 loc) · 1.82 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
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package ledgermgmt
import (
"fmt"
"os"
"github.com/hyperledger/fabric/common/metrics/disabled"
"github.com/hyperledger/fabric/core/chaincode/platforms"
"github.com/hyperledger/fabric/core/chaincode/platforms/golang"
"github.com/hyperledger/fabric/core/ledger/ledgerconfig"
"github.com/hyperledger/fabric/core/ledger/mock"
)
// InitializeTestEnv initializes ledgermgmt for tests
func InitializeTestEnv() {
remove()
InitializeTestEnvWithInitializer(nil)
}
// InitializeTestEnvWithInitializer initializes ledgermgmt for tests with the supplied Initializer
func InitializeTestEnvWithInitializer(initializer *Initializer) {
remove()
InitializeExistingTestEnvWithInitializer(initializer)
}
// InitializeExistingTestEnvWithInitializer initializes ledgermgmt for tests with existing ledgers
// This function does not remove the existing ledgers and is used in upgrade tests
// TODO ledgermgmt should be reworked to move the package scoped functions to a struct
func InitializeExistingTestEnvWithInitializer(initializer *Initializer) {
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{})
}
initialize(initializer)
}
// CleanupTestEnv closes the ledgermagmt and removes the store directory
func CleanupTestEnv() {
Close()
remove()
}
func remove() {
path := ledgerconfig.GetRootPath()
fmt.Printf("removing dir = %s\n", path)
err := os.RemoveAll(path)
if err != nil {
logger.Errorf("Error: %s", err)
}
}