forked from go-chassis/go-chassis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chassis_test.go
executable file
·140 lines (126 loc) · 3.35 KB
/
chassis_test.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package chassis_test
import (
"github.com/ServiceComb/go-chassis"
"github.com/ServiceComb/go-chassis/core/config"
"github.com/ServiceComb/go-chassis/core/config/model"
"github.com/ServiceComb/go-chassis/core/lager"
"github.com/ServiceComb/go-chassis/util/fileutil"
"github.com/stretchr/testify/assert"
"os"
"path/filepath"
"testing"
)
const (
Provider = "provider"
)
func TestInit(t *testing.T) {
t.Log("Testing Chassis Init function")
d := filepath.Join("root", "conf")
path := filepath.Join(d, fileutil.Global)
var _, err = os.Stat(path)
// create file if not exists
if os.IsNotExist(err) {
err = os.MkdirAll(d, 777)
assert.NoError(t, err)
file, err := os.Create(path)
assert.NoError(t, err)
defer file.Close()
}
file, err := os.OpenFile(path, os.O_RDWR, 0644)
assert.NoError(t, err)
defer file.Close()
// write some text line-by-line to file
_, err = file.WriteString(`---
#APPLICATION_ID: CSE optional
cse:
flowcontrol:
Consumer:
qps:
enabled: true
limit:
Server.EmployServer: 100
loadbalance:
strategy:
name: RoundRobin
retryEnabled: false
retryOnNext: 2
retryOnSame: 3
backoff:
kind: constant
minMs: 200
maxMs: 400
service:
registry:
type: servicecenter
scope: full
address: http://127.0.0.1:30100
refeshInterval : 30s
watch: true
register: reg
handler:
chain:
consumer:
default: bizkeeper-consumer, loadbalance, ratelimiter-consumer
references:
Server:
version: 0.1
transport: highway
HelloServer:
version: 0.1
transport: highway
ssl:
registry.consumer.cipherPlugin: default
registry.consumer.verifyPeer: false
registry.consumer.cipherSuits: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
registry.consumer.protocol: TLSv1.2
registry.consumer.caFile:
registry.consumer.certFile:
registry.consumer.keyFile:
registry.consumer.certPwdFile:
`)
assert.NoError(t, err)
path = filepath.Join("root", "conf", "microservice.yaml")
_, err = os.Stat(path)
// create file if not exists
if os.IsNotExist(err) {
file, err := os.Create(filepath.Join("root", "conf", "microservice.yaml"))
assert.NoError(t, err)
defer file.Close()
}
file, err = os.OpenFile(path, os.O_RDWR, 0644)
assert.NoError(t, err)
defer file.Close()
_, err = file.WriteString(`---
#微服务的私有属性
service_description:
name: nodejs2
level: FRONT
version: 0.1
properties:
allowCrossApp: true
instance_properties:
a: s
p: s
`)
assert.NoError(t, err)
// save changes
err = file.Sync()
assert.NoError(t, err)
os.Setenv("CHASSIS_HOME", filepath.Join("root"))
lager.Initialize("", "INFO", "", "size", true, 1, 10, 7)
config.GlobalDefinition = &model.GlobalCfg{}
config.Init()
config.GlobalDefinition.Cse.Handler.Chain.Provider = map[string]string{
"default": "bizkeeper-provider",
}
config.GlobalDefinition.Cse.Service.Registry.AutoRegister = "abc"
err = chassis.Init()
assert.NoError(t, err)
chassis.RegisterSchema("rest", "str")
}
func TestInitError(t *testing.T) {
t.Log("Testing chassis Init function for errors")
p := filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "ServiceComb", "go-chassis", "examples", "communication/client")
os.Setenv("CHASSIS_HOME", p)
lager.Initialize("", "INFO", "", "size", true, 1, 10, 7)
}