@@ -17,16 +17,18 @@ const progressUpdateResponseStub: TProgressUpdateResp = {
1717describe ( 'buildUserAgentString' , ( ) => {
1818 // It should follow https://www.rfc-editor.org/rfc/rfc7231#section-5.5.3 and
1919 // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent
20- // UserAgent ::= <ProductName> '/' <ProductVersion> '(' <Comment> ')'
20+ //
21+ // UserAgent ::= <ProductName> '/' <ProductVersion> '(' <Comment> ')'
2122 // where:
22- // < ProductName> is " NodejsDatabricksSqlConnector"
23- // < ProductVersion> is three period-separated digits (optionally with a suffix)
24- // <Comment> is " Node.js <NodeJsVersion>; <OSPlatform> <OSVersion>"
23+ // ProductName ::= ' NodejsDatabricksSqlConnector'
24+ // ProductVersion ::= three period-separated digits
25+ // <Comment> ::= [ <userAgentEntry> ';' ] ' Node.js' <NodeJsVersion> ';' <OSPlatform> <OSVersion>
2526 //
26- // Example:
27- // - NodejsDatabricksSqlConnector/0.1.8-beta.1 (Node.js 16.13.1; Darwin 21.5.0)
27+ // Examples:
28+ // - with <userAgentEntry> provided: NodejsDatabricksSqlConnector/0.1.8-beta.1 (<userAgentEntry>; Node.js 16.13.1; Darwin 21.5.0)
29+ // - without <userAgentEntry> provided: NodejsDatabricksSqlConnector/0.1.8-beta.1 (Node.js 16.13.1; Darwin 21.5.0)
2830
29- function checkUserAgentString ( ua : string ) {
31+ function checkUserAgentString ( ua : string , userAgentEntry ?: string ) {
3032 // Prefix: 'NodejsDatabricksSqlConnector/'
3133 // Version: three period-separated digits and optional suffix
3234 const re =
@@ -39,13 +41,18 @@ describe('buildUserAgentString', () => {
3941 const parts = comment . split ( ';' ) . map ( ( s ) => s . trim ( ) ) ;
4042 expect ( parts . length ) . to . be . gte ( 2 ) ; // at least Node and OS version should be there
4143
42- // First part should start with "Node.js" followed by a version number.
43- expect ( parts [ 0 ] ) . to . match ( / ^ N o d e \. j s \s + \d + \. \d + \. \d + / ) ;
44- // Second part should represent the OS platform (a word) and OS version.
45- expect ( parts [ 1 ] ) . to . match ( / ^ \w + / ) ;
44+ if ( userAgentEntry ) {
45+ expect ( comment . trim ( ) ) . to . satisfy ( ( s : string ) => s . startsWith ( `${ userAgentEntry } ;` ) ) ;
46+ }
4647 }
4748
48- it ( 'matches pattern' , ( ) => {
49+ it ( 'matches pattern with userAgentEntry' , ( ) => {
50+ const userAgentEntry = 'Some user agent' ;
51+ const ua = buildUserAgentString ( userAgentEntry ) ;
52+ checkUserAgentString ( ua , userAgentEntry ) ;
53+ } ) ;
54+
55+ it ( 'matches pattern without userAgentEntry' , ( ) => {
4956 const ua = buildUserAgentString ( ) ;
5057 checkUserAgentString ( ua ) ;
5158 } ) ;
0 commit comments