@@ -267,8 +267,12 @@ describe("Configuration string parser suite", function () {
267267 "Invalid protocol version: 'automatic', accepted values: 'auto', '1', '2'" ,
268268 ) ;
269269
270- // defaults
271- let options = await SenderOptions . fromConfig ( "tcp::addr=localhost" ) ;
270+ let options : SenderOptions ;
271+
272+ // defaults with supported versions: 1,2
273+ mockHttp . reset ( ) ;
274+ mockHttps . reset ( ) ;
275+ options = await SenderOptions . fromConfig ( "tcp::addr=localhost" ) ;
272276 expect ( options . protocol_version ) . toBe ( "1" ) ;
273277 options = await SenderOptions . fromConfig ( "tcps::addr=localhost" ) ;
274278 expect ( options . protocol_version ) . toBe ( "1" ) ;
@@ -281,7 +285,80 @@ describe("Configuration string parser suite", function () {
281285 ) ;
282286 expect ( options . protocol_version ) . toBe ( "2" ) ;
283287
284- // auto, 1, 2 with each protocol (tcp, tcps, http, https)
288+ // defaults with supported versions: 1
289+ const only1 = {
290+ settings : {
291+ config : { "line.proto.support.versions" : [ 1 ] } ,
292+ } ,
293+ } ;
294+ mockHttp . reset ( only1 ) ;
295+ mockHttps . reset ( only1 ) ;
296+ options = await SenderOptions . fromConfig ( "tcp::addr=localhost" ) ;
297+ expect ( options . protocol_version ) . toBe ( "1" ) ;
298+ options = await SenderOptions . fromConfig ( "tcps::addr=localhost" ) ;
299+ expect ( options . protocol_version ) . toBe ( "1" ) ;
300+ options = await SenderOptions . fromConfig (
301+ `http::addr=localhost:${ MOCK_HTTP_PORT } ` ,
302+ ) ;
303+ expect ( options . protocol_version ) . toBe ( "1" ) ;
304+ options = await SenderOptions . fromConfig (
305+ `https::addr=localhost:${ MOCK_HTTPS_PORT } ` ,
306+ ) ;
307+ expect ( options . protocol_version ) . toBe ( "1" ) ;
308+
309+ // defaults with no supported versions
310+ const noVersions = {
311+ settings : {
312+ config : { } ,
313+ } ,
314+ } ;
315+ mockHttp . reset ( noVersions ) ;
316+ mockHttps . reset ( noVersions ) ;
317+ options = await SenderOptions . fromConfig ( "tcp::addr=localhost" ) ;
318+ expect ( options . protocol_version ) . toBe ( "1" ) ;
319+ options = await SenderOptions . fromConfig ( "tcps::addr=localhost" ) ;
320+ expect ( options . protocol_version ) . toBe ( "1" ) ;
321+ options = await SenderOptions . fromConfig (
322+ `http::addr=localhost:${ MOCK_HTTP_PORT } ` ,
323+ ) ;
324+ expect ( options . protocol_version ) . toBe ( "1" ) ;
325+ options = await SenderOptions . fromConfig (
326+ `https::addr=localhost:${ MOCK_HTTPS_PORT } ` ,
327+ ) ;
328+ expect ( options . protocol_version ) . toBe ( "1" ) ;
329+
330+ // defaults with no match with supported versions
331+ const no1and2 = {
332+ settings : {
333+ config : { "line.proto.support.versions" : [ 3 , 5 ] } ,
334+ } ,
335+ } ;
336+ mockHttp . reset ( no1and2 ) ;
337+ mockHttps . reset ( no1and2 ) ;
338+ options = await SenderOptions . fromConfig ( "tcp::addr=localhost" ) ;
339+ expect ( options . protocol_version ) . toBe ( "1" ) ;
340+ options = await SenderOptions . fromConfig ( "tcps::addr=localhost" ) ;
341+ expect ( options . protocol_version ) . toBe ( "1" ) ;
342+ await expect (
343+ async ( ) =>
344+ await SenderOptions . fromConfig (
345+ `http::addr=localhost:${ MOCK_HTTP_PORT } ` ,
346+ ) ,
347+ ) . rejects . toThrow (
348+ "Unsupported protocol versions received from server: 3,5" ,
349+ ) ;
350+ await expect (
351+ async ( ) =>
352+ await SenderOptions . fromConfig (
353+ `https::addr=localhost:${ MOCK_HTTPS_PORT } ` ,
354+ ) ,
355+ ) . rejects . toThrow (
356+ "Unsupported protocol versions received from server: 3,5" ,
357+ ) ;
358+
359+ // auto, 1, 2 with each protocol (tcp, tcps, http, https), supported versions: 1,2
360+ mockHttp . reset ( ) ;
361+ mockHttps . reset ( ) ;
285362 options = await SenderOptions . fromConfig (
286363 "tcp::addr=localhost;protocol_version=1" ,
287364 ) ;
0 commit comments