@@ -189,3 +189,85 @@ func TestBuildAddHeaderMaps(t *testing.T) {
189
189
190
190
g .Expect (maps ).To (ConsistOf (expectedMap ))
191
191
}
192
+
193
+ func TestExecuteStreamMaps (t * testing.T ) {
194
+ g := NewWithT (t )
195
+ conf := dataplane.Configuration {
196
+ TLSServers : []dataplane.Layer4Server {
197
+ {
198
+ Hostname : "example.com" ,
199
+ Port : 8081 ,
200
+ UpstreamName : "backend1" ,
201
+ },
202
+ {
203
+ Hostname : "example.com" ,
204
+ Port : 8080 ,
205
+ UpstreamName : "backend1" ,
206
+ },
207
+ {
208
+ Hostname : "cafe.example.com" ,
209
+ Port : 8080 ,
210
+ UpstreamName : "backend2" ,
211
+ },
212
+ },
213
+ }
214
+
215
+ expSubStrings := map [string ]int {
216
+ "example.com unix:/var/lib/nginx/example.com8081.sock;" : 1 ,
217
+ "example.com unix:/var/lib/nginx/example.com8080.sock;" : 1 ,
218
+ "cafe.example.com unix:/var/lib/nginx/cafe.example.com8080.sock;" : 1 ,
219
+ }
220
+
221
+ type assertion func (g * WithT , data string )
222
+
223
+ expectedResults := map [string ]assertion {
224
+ streamConfigFile : func (g * WithT , data string ) {
225
+ for expSubStr , expCount := range expSubStrings {
226
+ g .Expect (strings .Count (data , expSubStr )).To (Equal (expCount ))
227
+ }
228
+ },
229
+ }
230
+
231
+ results := executeStreamMaps (conf )
232
+ g .Expect (results ).To (HaveLen (len (expectedResults )))
233
+
234
+ for _ , res := range results {
235
+ g .Expect (expectedResults ).To (HaveKey (res .dest ), "executeStreamServers returned unexpected result destination" )
236
+
237
+ assertData := expectedResults [res .dest ]
238
+ assertData (g , string (res .data ))
239
+ }
240
+ }
241
+
242
+ func TestCreateStreamMaps (t * testing.T ) {
243
+ g := NewWithT (t )
244
+ conf := dataplane.Configuration {
245
+ TLSServers : []dataplane.Layer4Server {
246
+ {
247
+ Hostname : "example.com" ,
248
+ Port : 8081 ,
249
+ UpstreamName : "backend1" ,
250
+ },
251
+ {
252
+ Hostname : "example.com" ,
253
+ Port : 8080 ,
254
+ UpstreamName : "backend1" ,
255
+ },
256
+ {
257
+ Hostname : "cafe.example.com" ,
258
+ Port : 8080 ,
259
+ UpstreamName : "backend2" ,
260
+ },
261
+ },
262
+ }
263
+
264
+ maps := createStreamMaps (conf )
265
+ g .Expect (maps ).To (HaveLen (2 ))
266
+
267
+ g .Expect (maps [0 ].Parameters ).To (HaveLen (1 ))
268
+ g .Expect (maps [1 ].Parameters ).To (HaveLen (2 ))
269
+
270
+ g .Expect (maps [0 ].Parameters [0 ].Result ).To (Equal ("unix:/var/lib/nginx/example.com8081.sock" ))
271
+ g .Expect (maps [1 ].Parameters [0 ].Result ).To (Equal ("unix:/var/lib/nginx/example.com8080.sock" ))
272
+ g .Expect (maps [0 ].Parameters [0 ].Result ).To (Equal ("unix:/var/lib/nginx/cafe.example.com8080.sock" ))
273
+ }
0 commit comments