@@ -3,7 +3,7 @@ package client
3
3
4
4
import (
5
5
"envoy-tools/csds-client/client"
6
- clientutil "envoy-tools/csds-client/client/util"
6
+ clientUtil "envoy-tools/csds-client/client/util"
7
7
"io/ioutil"
8
8
"path/filepath"
9
9
"testing"
@@ -32,7 +32,7 @@ func TestParseNodeMatcherWithFile(t *testing.T) {
32
32
t .Errorf ("Parse NodeMatcher Error: %v" , err )
33
33
}
34
34
35
- if ! clientutil .ShouldEqualJSON (t , string (get ), want ) {
35
+ if ! clientUtil .ShouldEqualJSON (t , string (get ), want ) {
36
36
t .Errorf ("NodeMatcher = \n %v\n , want: \n %v\n " , string (get ), want )
37
37
}
38
38
}
@@ -57,7 +57,7 @@ func TestParseNodeMatcherWithString(t *testing.T) {
57
57
if err != nil {
58
58
t .Errorf ("Parse NodeMatcher Error: %v" , err )
59
59
}
60
- if ! clientutil .ShouldEqualJSON (t , string (get ), want ) {
60
+ if ! clientUtil .ShouldEqualJSON (t , string (get ), want ) {
61
61
t .Errorf ("NodeMatcher = \n %v\n , want: \n %v\n " , string (get ), want )
62
62
}
63
63
}
@@ -82,7 +82,7 @@ func TestParseNodeMatcherWithFileAndString(t *testing.T) {
82
82
if err != nil {
83
83
t .Errorf ("Parse NodeMatcher Error: %v" , err )
84
84
}
85
- if ! clientutil .ShouldEqualJSON (t , string (get ), want ) {
85
+ if ! clientUtil .ShouldEqualJSON (t , string (get ), want ) {
86
86
t .Errorf ("NodeMatcher = \n %v\n , want: \n %v\n " , string (get ), want )
87
87
}
88
88
}
@@ -103,12 +103,16 @@ func TestParseResponseWithoutNodeId(t *testing.T) {
103
103
if err = protojson .Unmarshal (responsejson , & response ); err != nil {
104
104
t .Errorf ("Read From File Failure: %v" , err )
105
105
}
106
- out := clientutil .CaptureOutput (func () {
106
+ out := clientUtil .CaptureOutput (func () {
107
107
if err := printOutResponse (& response , c .opts ); err != nil {
108
108
t .Errorf ("Print out response error: %v" , err )
109
109
}
110
110
})
111
- want := "Client ID xDS stream type Config Status \n test_node_1 test_stream_type1 N/A \n test_node_2 test_stream_type2 N/A \n test_node_3 test_stream_type3 N/A \n "
111
+ want := `Client ID xDS stream type Config Status
112
+ test_node_1 test_stream_type1 N/A
113
+ test_node_2 test_stream_type2 N/A
114
+ test_node_3 test_stream_type3 N/A
115
+ `
112
116
if out != want {
113
117
t .Errorf ("want\n %vout\n %v" , want , out )
114
118
}
@@ -131,12 +135,16 @@ func TestParseResponseWithNodeId(t *testing.T) {
131
135
if err = protojson .Unmarshal (responsejson , & response ); err != nil {
132
136
t .Errorf ("Read From File Failure: %v" , err )
133
137
}
134
- out := clientutil .CaptureOutput (func () {
138
+ out := clientUtil .CaptureOutput (func () {
135
139
if err := printOutResponse (& response , c .opts ); err != nil {
136
140
t .Errorf ("Print out response error: %v" , err )
137
141
}
138
142
})
139
- want := "Client ID xDS stream type Config Status \n test_nodeid test_stream_type1 RDS STALE \n CDS STALE \n Config has been saved to test_config.json\n "
143
+ want := `Client ID xDS stream type Config Status
144
+ test_nodeid test_stream_type1 RDS STALE
145
+ CDS STALE
146
+ Config has been saved to test_config.json
147
+ `
140
148
if out != want {
141
149
t .Errorf ("want\n %vout\n %v" , want , out )
142
150
}
@@ -146,7 +154,7 @@ func TestParseResponseWithNodeId(t *testing.T) {
146
154
if err != nil {
147
155
t .Errorf ("Write config to file failure: %v" , err )
148
156
}
149
- ok , err := clientutil .EqualJSONBytes (outputjson , responsejson )
157
+ ok , err := clientUtil .EqualJSONBytes (outputjson , responsejson )
150
158
if err != nil {
151
159
t .Errorf ("failed to parse json" )
152
160
}
@@ -162,11 +170,123 @@ func TestVisualization(t *testing.T) {
162
170
if err != nil {
163
171
t .Errorf ("Read From File Failure: %v" , err )
164
172
}
165
- if err := clientutil .Visualize (responsejson , false ); err != nil {
173
+ if err := clientUtil .Visualize (responsejson , false ); err != nil {
166
174
t .Errorf ("Visualization Failure: %v" , err )
167
175
}
168
- want := "digraph G {\n rankdir=LR;\n \\ \" test_lds_0\\ \" ->\\ \" test_rds_0\\ \" [ arrowsize=0.3, penwidth=0.3 ];\n \\ \" test_lds_0\\ \" ->\\ \" test_rds_1\\ \" [ arrowsize=0.3, penwidth=0.3 ];\n \\ \" test_rds_0\\ \" ->\\ \" test_cds_0\\ \" [ arrowsize=0.3, penwidth=0.3 ];\n \\ \" test_rds_0\\ \" ->\\ \" test_cds_1\\ \" [ arrowsize=0.3, penwidth=0.3 ];\n \\ \" test_rds_1\\ \" ->\\ \" test_cds_1\\ \" [ arrowsize=0.3, penwidth=0.3 ];\n \\ \" test_cds_0\\ \" [ color=\\ \" #34A853\\ \" , fillcolor=\\ \" #34A853\\ \" , fontcolor=white, fontname=Roboto, label=CDS0, shape=box, style=\\ \" \" filled,rounded\" \\ \" ];\n \\ \" test_cds_1\\ \" [ color=\\ \" #34A853\\ \" , fillcolor=\\ \" #34A853\\ \" , fontcolor=white, fontname=Roboto, label=CDS1, shape=box, style=\\ \" \" filled,rounded\" \\ \" ];\n \\ \" test_lds_0\\ \" [ color=\\ \" #4285F4\\ \" , fillcolor=\\ \" #4285F4\\ \" , fontcolor=white, fontname=Roboto, label=LDS0, shape=box, style=\\ \" \" filled,rounded\" \\ \" ];\n \\ \" test_rds_0\\ \" [ color=\\ \" #FBBC04\\ \" , fillcolor=\\ \" #FBBC04\\ \" , fontcolor=white, fontname=Roboto, label=RDS0, shape=box, style=\\ \" \" filled,rounded\" \\ \" ];\n \\ \" test_rds_1\\ \" [ color=\\ \" #FBBC04\\ \" , fillcolor=\\ \" #FBBC04\\ \" , fontcolor=white, fontname=Roboto, label=RDS1, shape=box, style=\\ \" \" filled,rounded\" \\ \" ];\n \n }\n "
169
- if err := clientutil .OpenBrowser ("http://dreampuf.github.io/GraphvizOnline/#" + want ); err != nil {
176
+ want := `digraph G {
177
+ rankdir=LR;
178
+ "test_lds_0"->"test_rds_0"[ arrowsize=0.3, penwidth=0.3 ];
179
+ "test_lds_0"->"test_rds_1"[ arrowsize=0.3, penwidth=0.3 ];
180
+ "test_rds_0"->"test_cds_0"[ arrowsize=0.3, penwidth=0.3 ];
181
+ "test_rds_0"->"test_cds_1"[ arrowsize=0.3, penwidth=0.3 ];
182
+ "test_rds_1"->"test_cds_1"[ arrowsize=0.3, penwidth=0.3 ];
183
+ "test_cds_0" [ color="#34A853", fillcolor="#34A853", fontcolor=white, fontname=Roboto, label=CDS0, shape=box, style="filled,rounded" ];
184
+ "test_cds_1" [ color="#34A853", fillcolor="#34A853", fontcolor=white, fontname=Roboto, label=CDS1, shape=box, style="filled,rounded" ];
185
+ "test_lds_0" [ color="#4285F4", fillcolor="#4285F4", fontcolor=white, fontname=Roboto, label=LDS0, shape=box, style="filled,rounded" ];
186
+ "test_rds_0" [ color="#FBBC04", fillcolor="#FBBC04", fontcolor=white, fontname=Roboto, label=RDS0, shape=box, style="filled,rounded" ];
187
+ "test_rds_1" [ color="#FBBC04", fillcolor="#FBBC04", fontcolor=white, fontname=Roboto, label=RDS1, shape=box, style="filled,rounded" ];
188
+
189
+ }
190
+ `
191
+ if err := clientUtil .OpenBrowser ("http://dreampuf.github.io/GraphvizOnline/#" + want ); err != nil {
170
192
t .Errorf ("Open want graph failure: %v" , err )
171
193
}
172
194
}
195
+
196
+ // TestNodeIdPrefixFilter tests node_id prefix filter
197
+ func TestNodeIdPrefixFilter (t * testing.T ) {
198
+ c := ClientV2 {
199
+ opts : client.ClientOptions {
200
+ Platform : "gcp" ,
201
+ FilterMode : "prefix" ,
202
+ FilterPattern : "test" ,
203
+ },
204
+ }
205
+ filename , _ := filepath .Abs ("./response_for_filter.json" )
206
+ responsejson , err := ioutil .ReadFile (filename )
207
+ if err != nil {
208
+ t .Errorf ("Read From File Failure: %v" , err )
209
+ }
210
+ var response csdspb_v2.ClientStatusResponse
211
+ if err = protojson .Unmarshal (responsejson , & response ); err != nil {
212
+ t .Errorf ("Read From File Failure: %v" , err )
213
+ }
214
+ out := clientUtil .CaptureOutput (func () {
215
+ if err := printOutResponse (& response , c .opts ); err != nil {
216
+ t .Errorf ("Print out response error: %v" , err )
217
+ }
218
+ })
219
+ want := `Client ID xDS stream type Config Status
220
+ test_node_1 test_stream_type1 N/A
221
+ test_node_2 test_stream_type2 N/A
222
+ test_node_3 test_stream_type3 N/A
223
+ `
224
+ if out != want {
225
+ t .Errorf ("want\n %vout\n %v" , want , out )
226
+ }
227
+ }
228
+
229
+ // TestNodeIdSuffixFilter tests node_id suffix filter
230
+ func TestNodeIdSuffixFilter (t * testing.T ) {
231
+ c := ClientV2 {
232
+ opts : client.ClientOptions {
233
+ Platform : "gcp" ,
234
+ FilterMode : "suffix" ,
235
+ FilterPattern : "3" ,
236
+ },
237
+ }
238
+ filename , _ := filepath .Abs ("./response_for_filter.json" )
239
+ responsejson , err := ioutil .ReadFile (filename )
240
+ if err != nil {
241
+ t .Errorf ("Read From File Failure: %v" , err )
242
+ }
243
+ var response csdspb_v2.ClientStatusResponse
244
+ if err = protojson .Unmarshal (responsejson , & response ); err != nil {
245
+ t .Errorf ("Read From File Failure: %v" , err )
246
+ }
247
+ out := clientUtil .CaptureOutput (func () {
248
+ if err := printOutResponse (& response , c .opts ); err != nil {
249
+ t .Errorf ("Print out response error: %v" , err )
250
+ }
251
+ })
252
+ want := `Client ID xDS stream type Config Status
253
+ test_node_3 test_stream_type3 N/A
254
+ node_3 test_stream_type4 N/A
255
+ `
256
+ if out != want {
257
+ t .Errorf ("want\n %vout\n %v" , want , out )
258
+ }
259
+ }
260
+
261
+ // TestNodeIdRegexFilter tests node_id regex filter
262
+ func TestNodeIdRegexFilter (t * testing.T ) {
263
+ c := ClientV2 {
264
+ opts : client.ClientOptions {
265
+ Platform : "gcp" ,
266
+ FilterMode : "regex" ,
267
+ FilterPattern : "test.*" ,
268
+ },
269
+ }
270
+ filename , _ := filepath .Abs ("./response_for_filter.json" )
271
+ responsejson , err := ioutil .ReadFile (filename )
272
+ if err != nil {
273
+ t .Errorf ("Read From File Failure: %v" , err )
274
+ }
275
+ var response csdspb_v2.ClientStatusResponse
276
+ if err = protojson .Unmarshal (responsejson , & response ); err != nil {
277
+ t .Errorf ("Read From File Failure: %v" , err )
278
+ }
279
+ out := clientUtil .CaptureOutput (func () {
280
+ if err := printOutResponse (& response , c .opts ); err != nil {
281
+ t .Errorf ("Print out response error: %v" , err )
282
+ }
283
+ })
284
+ want := `Client ID xDS stream type Config Status
285
+ test_node_1 test_stream_type1 N/A
286
+ test_node_2 test_stream_type2 N/A
287
+ test_node_3 test_stream_type3 N/A
288
+ `
289
+ if out != want {
290
+ t .Errorf ("want\n %vout\n %v" , want , out )
291
+ }
292
+ }
0 commit comments