forked from hyperledger/fabric-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
env.go
91 lines (75 loc) · 3.13 KB
/
env.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
85
86
87
88
89
90
91
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package integration
import (
"os"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
"github.com/hyperledger/fabric-sdk-go/pkg/util/pathvar"
)
const (
configPath = "${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/config/config_test.yaml"
entityMangerLocal = "${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/test//fixtures/config/overrides/local_entity_matchers.yaml"
//LocalOrdererPeersCAsConfig config file to override on local test having only peers, orderers and CA entity entries
LocalOrdererPeersCAsConfig = "${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/config/overrides/local_orderers_peers_ca.yaml"
//LocalOrdererPeersConfig config file to override on local test having only peers and orderers entity entries
LocalOrdererPeersConfig = "${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/config/overrides/local_orderers_peers.yaml"
)
// ConfigBackend contains config backend for integration tests
var ConfigBackend = fetchConfigBackend(configPath, LocalOrdererPeersCAsConfig)
func fetchConfigBackend(configPath string, localOverride string) core.ConfigProvider {
configProvider := config.FromFile(pathvar.Subst(configPath))
args := os.Args[1:]
for _, arg := range args {
//If testlocal is enabled, then update config backend to run 'local' test
if arg == "testLocal=true" {
return func() ([]core.ConfigBackend, error) {
return appendLocalEntityMappingBackend(configProvider, localOverride)
}
}
}
return configProvider
}
//IsLocal checks os argument and returns true if 'testLocal=true' argument found
func IsLocal() bool {
args := os.Args[1:]
for _, arg := range args {
if arg == "testLocal=true" {
return true
}
}
return false
}
//AddLocalEntityMapping adds local test entity mapping to config backend
// and returns updated config provider
func AddLocalEntityMapping(configProvider core.ConfigProvider, configOverridePath string) core.ConfigProvider {
return func() ([]core.ConfigBackend, error) {
return appendLocalEntityMappingBackend(configProvider, configOverridePath)
}
}
//appendLocalEntityMappingBackend appends entity matcher backend to given config provider
func appendLocalEntityMappingBackend(configProvider core.ConfigProvider, configOverridePath string) ([]core.ConfigBackend, error) {
//Current backend
currentBackends, err := configProvider()
if err != nil {
return nil, err
}
//Entity matcher config backend
configProvider = config.FromFile(pathvar.Subst(entityMangerLocal))
matcherBackends, err := configProvider()
if err != nil {
return nil, err
}
//Local orderer/peer/CA config overrides
configProvider = config.FromFile(pathvar.Subst(configOverridePath))
localBackends, err := configProvider()
if err != nil {
return nil, err
}
//backends should fal back in this order - matcherBackends, localBackends, currentBackends
localBackends = append(localBackends, matcherBackends...)
localBackends = append(localBackends, currentBackends...)
return localBackends, nil
}