forked from dappledger/ann-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenv.go
109 lines (91 loc) · 2.64 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright © 2017 ZhongAn Technology
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package tests
import (
"fmt"
"os"
"strconv"
"strings"
"github.com/dappledger/AnnChain/gemmill/go-crypto"
gcrypto "github.com/dappledger/ann-go-sdk/crypto"
. "github.com/dappledger/ann-tests/cluster"
"github.com/dappledger/ann-tests/cluster/binary"
"github.com/dappledger/ann-tests/cluster/docker"
)
var (
TestValidatorNum = lookupIntEnv("TEST_VALIDATOR_NUM", 4)
TestPlatform = lookupStringEnv("TEST_PLATFORM", "binary")
TestCryptoType = lookupStringEnv("TEST_CRYPTO_TYPE", "ZA")
TestConsensusType = lookupStringEnv("TEST_CONSENSUS_TYPE", "pbft")
)
var (
TestGenesisImage = lookupStringEnv("TEST_GENESIS_IMAGE", "annchain/genesis:latest")
)
var (
TestKeepCluster = lookupBoolEnv("TEST_KEEP_CLUSTER", false)
TestDebug = lookupBoolEnv("TEST_DEBUG", false)
)
func init() {
fmt.Printf(`Testing Env:
image: %s
crypto_type: %s
validators num: %d,
`, TestGenesisImage, TestCryptoType, TestValidatorNum)
}
func lookupIntEnv(key string, defaultValue int) int {
v, ok := os.LookupEnv(key)
if !ok {
return defaultValue
}
i, err := strconv.Atoi(v)
if err != nil {
return defaultValue
}
return i
}
func lookupStringEnv(key, defaultValue string) string {
v, ok := os.LookupEnv(key)
if !ok {
return defaultValue
}
return v
}
func lookupBoolEnv(key string, defaultValue bool) bool {
v, ok := os.LookupEnv(key)
if !ok {
return defaultValue
}
return strings.ToLower(v) == "true"
}
func NewClusterFromEnv() (Cluster, error) {
blockBrowserImage := "annchain/browser"
crypto.NodeInit(TestCryptoType)
gcrypto.NodeInit(TestCryptoType)
if TestPlatform == "binary" {
c, err := binary.New(&binary.Option{
ValidatorNum: TestValidatorNum,
CryptoType: TestCryptoType,
BinaryPath: TestGenesisImage,
Consensus: TestConsensusType,
})
return c, err
}
return docker.NewDockerCompose(&docker.Option{
ValidatorNum: TestValidatorNum,
IPPrefix: "192.168.32",
HasBrowser: false,
GenesisImage: TestGenesisImage,
BlockBrowserImage: blockBrowserImage + ":latest",
CryptoType: TestCryptoType,
}), nil
}