@@ -2,7 +2,7 @@ import http from 'http';
22import { expect } from 'chai' ;
33import HttpConnection from '../../../../lib/connection/connections/HttpConnection' ;
44import ThriftHttpConnection from '../../../../lib/connection/connections/ThriftHttpConnection' ;
5-
5+ import IConnectionOptions from '../../../../lib/connection/contracts/IConnectionOptions' ;
66import ClientContextStub from '../../.stubs/ClientContextStub' ;
77
88describe ( 'HttpConnection.connect' , ( ) => {
@@ -127,4 +127,46 @@ describe('HttpConnection.connect', () => {
127127 ...extraHeaders ,
128128 } ) ;
129129 } ) ;
130+
131+ it ( 'should handle trailing slashes in host and path correctly' , async ( ) => {
132+ interface TestCase {
133+ input : {
134+ host : string ;
135+ path ?: string ;
136+ } ;
137+ expected : string ;
138+ }
139+
140+ const testCases : TestCase [ ] = [
141+ {
142+ input : { host : 'xyz.com/' , path : '/sql/v1/' } ,
143+ expected : 'https://xyz.com:443/sql/v1'
144+ } ,
145+ {
146+ input : { host : 'xyz.com' , path : 'sql/v1' } ,
147+ expected : 'https://xyz.com:443/sql/v1'
148+ } ,
149+ {
150+ input : { host : 'xyz.com/' , path : 'sql/v1' } ,
151+ expected : 'https://xyz.com:443/sql/v1'
152+ } ,
153+ {
154+ input : { host : 'xyz.com' , path : undefined } ,
155+ expected : 'https://xyz.com:443/'
156+ }
157+ ] ;
158+
159+ for ( const testCase of testCases ) {
160+ const options : IConnectionOptions = {
161+ host : testCase . input . host ,
162+ port : 443 ,
163+ path : testCase . input . path ,
164+ https : true ,
165+ } ;
166+
167+ const connection = new HttpConnection ( options , new ClientContextStub ( ) ) ;
168+ const thriftConnection = await connection . getThriftConnection ( ) ;
169+ expect ( thriftConnection . url ) . to . be . equal ( testCase . expected ) ;
170+ }
171+ } ) ;
130172} ) ;
0 commit comments