@@ -17,16 +17,18 @@ const progressUpdateResponseStub: TProgressUpdateResp = {
17
17
describe ( 'buildUserAgentString' , ( ) => {
18
18
// It should follow https://www.rfc-editor.org/rfc/rfc7231#section-5.5.3 and
19
19
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent
20
- // UserAgent ::= <ProductName> '/' <ProductVersion> '(' <Comment> ')'
20
+ //
21
+ // UserAgent ::= <ProductName> '/' <ProductVersion> '(' <Comment> ')'
21
22
// 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>
25
26
//
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)
28
30
29
- function checkUserAgentString ( ua : string ) {
31
+ function checkUserAgentString ( ua : string , userAgentEntry ?: string ) {
30
32
// Prefix: 'NodejsDatabricksSqlConnector/'
31
33
// Version: three period-separated digits and optional suffix
32
34
const re =
@@ -39,13 +41,18 @@ describe('buildUserAgentString', () => {
39
41
const parts = comment . split ( ';' ) . map ( ( s ) => s . trim ( ) ) ;
40
42
expect ( parts . length ) . to . be . gte ( 2 ) ; // at least Node and OS version should be there
41
43
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
+ }
46
47
}
47
48
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' , ( ) => {
49
56
const ua = buildUserAgentString ( ) ;
50
57
checkUserAgentString ( ua ) ;
51
58
} ) ;
0 commit comments