-
Notifications
You must be signed in to change notification settings - Fork 0
/
wind_test.go
315 lines (246 loc) · 8.29 KB
/
wind_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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
package windward
import (
"fmt"
lacia "github.com/jialanli/lacia/utils"
"testing"
)
func TestCLink(t *testing.T) {
name := "./c.yml"
w := GetWindward()
w.InitConf([]string{name})
name0 := w.GetVal(name, "metadata.name")
fmt.Println("metadata.name-->", name0) //
namespace := w.GetVal(name, "metadata.namespace")
fmt.Println("metadata.namespace-->", namespace) //
ports := w.GetVal(name, "spec.ports")
fmt.Println("spec.ports-->", ports) //
port := w.GetVal(name, "spec.ports.port")
fmt.Println("spec.ports.port-->", port) //
protocol := w.GetVal(name, "spec.ports.protocol")
fmt.Println("spec.ports.protocol-->", protocol) //
targetPort := w.GetVal(name, "spec.ports.targetPort")
fmt.Println("spec.ports.targetPort-->", targetPort) //
sessionAffinity := w.GetVal(name, "spec.sessionAffinity")
fmt.Println("spec.sessionAffinity-->", sessionAffinity) //
types := w.GetVal(name, "spec.type")
fmt.Println("spec.type-->", types) //
/*
metadata.name--> wordpress3
metadata.namespace--> default
spec.ports--> [map[port:19987 protocol:TCP targetPort:19987]]
spec.ports.port--> 19987
spec.ports.protocol--> TCP
spec.ports.targetPort--> 19987
spec.sessionAffinity--> None
spec.type--> ClusterIP
*/
}
func TestA(t *testing.T) {
name := "./a.yml"
w := GetWindward()
w.InitConf([]string{name})
SecA := w.GetVal(name, "SecA")
fmt.Println("SecA-->", SecA) // SecA--> map[SecC:/A/B/c.go keyB:998]
SecC := w.GetVal(name, "SecC")
fmt.Println("SecC-->", SecC) // SecC--> /A/B/c.go
keyA := w.GetVal(name, "keyA")
fmt.Println("keyA-->", keyA) // keyA--> hello^
//
keyC := w.GetVal(name, "keyC")
fmt.Println("keyC-->", keyC) // keyC--> 1.0.1~|888`888
SecD := w.GetVal(name, "SecD")
fmt.Println("SecD-->", SecD) // SecD--> nihao
a := w.GetVal(name, "SecA.SecC")
fmt.Println("SecA.SecC-->", a) // SecA.SecC--> /A/B/c.go
b := w.GetVal(name, "SecA.keyB")
fmt.Println("SecA.keyB-->", b) // SecA.keyB--> 998
c := w.GetVal(name, "SecB.keyA")
fmt.Println("SecB.keyA-->", c) //
}
func TestMany(t *testing.T) {
/*
spec.ports.port--> 19987
spec.ports.protocol--> TCP
spec.ports.targetPort--> 19987
spec.sessionAffinity--> None
spec.type--> ClusterIP
SecA--> map[SecC:/A/B/c.go keyB:998]
SecC--> /A/B/c.go
keyA--> hello^
keyC--> 1.0.1~|888`888
SecD--> nihao
SecA.SecC--> /A/B/c.go
SecA.keyB--> 998
SecB.keyA--> hello^
*/
name, name1 := "./a.yml", "./c.yml"
w := GetWindward()
w.InitConf([]string{name, name1})
name0 := w.GetVal(name1, "metadata.name")
fmt.Println("metadata.name-->", name0) //
namespace := w.GetVal(name1, "metadata.namespace")
fmt.Println("metadata.namespace-->", namespace) //
ports := w.GetVal(name1, "spec.ports")
fmt.Println("spec.ports-->", ports) //
port := w.GetVal(name1, "spec.ports.port")
fmt.Println("spec.ports.port-->", port) //
protocol := w.GetVal(name1, "spec.ports.protocol")
fmt.Println("spec.ports.protocol-->", protocol) //
targetPort := w.GetVal(name1, "spec.ports.targetPort")
fmt.Println("spec.ports.targetPort-->", targetPort) //
sessionAffinity := w.GetVal(name1, "spec.sessionAffinity")
fmt.Println("spec.sessionAffinity-->", sessionAffinity) //
types := w.GetVal(name1, "spec.type")
fmt.Println("spec.type-->", types) //
SecA := w.GetVal(name, "SecA")
fmt.Println("SecA-->", SecA) // SecA--> map[SecC:/A/B/c.go keyB:998]
SecC := w.GetVal(name, "SecC")
fmt.Println("SecC-->", SecC) // SecC--> /A/B/c.go
keyA := w.GetVal(name, "keyA")
fmt.Println("keyA-->", keyA) // keyA--> hello^
//
keyC := w.GetVal(name, "keyC")
fmt.Println("keyC-->", keyC) // keyC--> 1.0.1~|888`888
SecD := w.GetVal(name, "SecD")
fmt.Println("SecD-->", SecD) // SecD--> nihao
a := w.GetVal(name, "SecA.SecC")
fmt.Println("SecA.SecC-->", a) // SecA.SecC--> /A/B/c.go
b := w.GetVal(name, "SecA.keyB")
fmt.Println("SecA.keyB-->", b) // SecA.keyB--> 998
c := w.GetVal(name, "SecB.keyA")
fmt.Println("SecB.keyA-->", c) //
}
func TestJs(t *testing.T) {
name := "./s.json"
w := GetWindward()
w.InitConf([]string{name})
c0 := w.GetVal(name, "name")
fmt.Println("name-->", c0) //
c1 := w.GetVal(name, "id")
fmt.Println("id-->", c1) //
c2 := w.GetVal(name, "type")
fmt.Println("type-->", c2) //
c3 := w.GetVal(name, "class")
fmt.Println("class-->", c3) //
c4 := w.GetVal(name, "class.data")
fmt.Println("class.data-->", c4) //
c5 := w.GetVal(name, "class.ins")
fmt.Println("class.ins-->", c5) //
c6 := w.GetVal(name, "other")
fmt.Println("other-->", c6) //
}
func TestMany0(t *testing.T) {
/*
name--> 你好
id--> 25
type--> 哈哈
class--> map[data:A ins:无名]
class.data--> A
class.ins--> 无名
other--> [map[s1:雨落山岚 s2:55] map[s1:雨落山岚晚成风 s2:99]]
metadata.name--> wordpress3
metadata.namespace--> default
spec.ports--> [map[port:19987 protocol:TCP targetPort:19987]]
spec.ports.port--> 19987
spec.ports.protocol--> TCP
spec.ports.targetPort--> 19987
spec.sessionAffinity--> None
spec.type--> ClusterIP
*/
name, name1 := "./s.json", "./c.yml"
w := GetWindward()
w.InitConf([]string{name, name1})
c0 := w.GetVal(name, "name")
fmt.Println("name-->", c0) //
c1 := w.GetVal(name, "id")
fmt.Println("id-->", c1) //
c2 := w.GetVal(name, "type")
fmt.Println("type-->", c2) //
c3 := w.GetVal(name, "class")
fmt.Println("class-->", c3) //
c4 := w.GetVal(name, "class.data")
fmt.Println("class.data-->", c4) //
c5 := w.GetVal(name, "class.ins")
fmt.Println("class.ins-->", c5) //
c6 := w.GetVal(name, "other")
fmt.Println("other-->", c6) //
name0 := w.GetVal(name1, "metadata.name")
fmt.Println("metadata.name-->", name0) //
namespace := w.GetVal(name1, "metadata.namespace")
fmt.Println("metadata.namespace-->", namespace) //
ports := w.GetVal(name1, "spec.ports")
fmt.Println("spec.ports-->", ports) //
port := w.GetVal(name1, "spec.ports.port")
fmt.Println("spec.ports.port-->", port) //
protocol := w.GetVal(name1, "spec.ports.protocol")
fmt.Println("spec.ports.protocol-->", protocol) //
targetPort := w.GetVal(name1, "spec.ports.targetPort")
fmt.Println("spec.ports.targetPort-->", targetPort) //
sessionAffinity := w.GetVal(name1, "spec.sessionAffinity")
fmt.Println("spec.sessionAffinity-->", sessionAffinity) //
types := w.GetVal(name1, "spec.type")
fmt.Println("spec.type-->", types) //
}
func TestUseManyConfigRead(t *testing.T) {
/*
JSON:err:<nil> data:{Name:你好 ID:25 Type:哈哈 Class:{Data:A Ins:无名} Other:[{S1:雨落山岚 S2:55} {S1:雨落山岚晚成风 S2:99}]}
YAML:err:<nil> date:{Kind:Service Metadata:{Name:wordpress3 Namespace:default} Spec:{Ports:[{TargetPort:19987 Port:19987 Protocol:TCP}] SessionAffinity:None Type:ClusterIP} ApiVersion:v1}--- PASS: TestUseManyConfigRead (0.01s)
*/
type other struct {
S1 string `json:"s1"`
S2 int `json:"s2"`
}
type JsonDemo struct {
Name string `json:"name"`
ID int `json:"id"`
Type string `json:"type"`
Class struct {
Data string `json:"data"`
Ins string `json:"ins"`
} `json:"class"`
Other []other `json:"other"`
}
name, name1 := "./s.json", "./c.yml"
w := GetWindward()
w.InitConf([]string{name, name1})
//c6 := w.GetVal(name, "other")
//fmt.Println("other-->", c6) //
var data JsonDemo
err := w.ReadConfig(name, &data)
fmt.Printf("JSON:err:%v \t data:%+v", err, data)
// yml
type metadata struct {
Name string `yaml:"name"`
Namespace string `yaml:"namespace"`
}
type ports struct {
TargetPort int `yaml:"targetPort"`
Port int `yaml:"port"`
Protocol string `yaml:"protocol"`
}
type spec struct {
Ports []ports `yaml:"ports"`
SessionAffinity string `yaml:"sessionAffinity"`
Type string `yaml:"type"`
}
type YamlDemo struct {
Kind string `yaml:"kind"`
Metadata metadata `yaml:"metadata"`
Spec spec `yaml:"spec"`
ApiVersion string `yaml:"apiVersion"`
}
var dataYaml YamlDemo
err = w.ReadConfig(name1, &dataYaml)
fmt.Printf("\nYAML:err:%v \tdate:%+v", err, dataYaml)
}
func TestManyType(t *testing.T) {
name, name1 := "./s.json", "./c.yml"
w := GetWindward()
w.InitConf([]string{name, name1})
namespace := w.GetVal(name1, "metadata.namespace")
fmt.Println("metadata.namespace-->", namespace) //
port := w.GetVal(name1, "spec.ports.port")
fmt.Println("spec.ports.port-->", port) //
fmt.Println(lacia.GetValTypeOf(namespace))
fmt.Println(lacia.GetValTypeOf(port))
}