@@ -37,9 +37,9 @@ const itIf =
3737 : it . skip ;
3838
3939let env : TestEnvironment ;
40- let driver ;
40+ let driver : any ;
4141let initClientFunc : ( props : any ) => any ;
42-
42+ let client : any ;
4343const sslCertificate = {
4444 ca : readFileSync ( "/app/global-bundle.pem" ) . toString ( )
4545} ;
@@ -67,18 +67,10 @@ async function initDefaultConfig(host: string): Promise<any> {
6767 return props ;
6868}
6969
70- async function validateConnection ( client : AwsPGClient | AwsMySQLClient ) {
71- try {
72- await client . connect ( ) ;
73- const res = await DriverHelper . executeQuery ( env . engine , client , "select 1" ) ;
74- expect ( res ) . not . toBeNull ( ) ;
75- } finally {
76- try {
77- await client . end ( ) ;
78- } catch ( error ) {
79- // pass
80- }
81- }
70+ async function validateConnection ( ) {
71+ await client . connect ( ) ;
72+ const res = await DriverHelper . executeQuery ( env . engine , client , "select 1" ) ;
73+ expect ( res ) . not . toBeNull ( ) ;
8274}
8375
8476describe ( "iam authentication" , ( ) => {
@@ -87,13 +79,19 @@ describe("iam authentication", () => {
8779 jest . useFakeTimers ( {
8880 doNotFake : [ "nextTick" ]
8981 } ) ;
82+ client = null ;
9083 env = await TestEnvironment . getCurrent ( ) ;
9184 driver = DriverHelper . getDriverForDatabaseEngine ( env . engine ) ;
9285 initClientFunc = DriverHelper . getClient ( driver ) ;
9386 IamAuthenticationPlugin . clearCache ( ) ;
9487 } ) ;
9588
9689 afterEach ( async ( ) => {
90+ try {
91+ await client . end ( ) ;
92+ } catch ( error ) {
93+ // pass
94+ }
9795 await PluginManager . releaseResources ( ) ;
9896 await TestEnvironment . verifyClusterStatus ( ) ;
9997 logger . info ( `Test finished: ${ expect . getState ( ) . currentTestName } ` ) ;
@@ -109,7 +107,7 @@ describe("iam authentication", () => {
109107 async ( ) => {
110108 const config = await initDefaultConfig ( env . databaseInfo . writerInstanceEndpoint ) ;
111109 config [ "user" ] = `WRONG_${ env . info . databaseInfo . username } _USER` ;
112- const client : AwsPGClient | AwsMySQLClient = initClientFunc ( config ) ;
110+ client = initClientFunc ( config ) ;
113111
114112 await expect ( client . connect ( ) ) . rejects . toThrow ( ) ;
115113 } ,
@@ -121,7 +119,7 @@ describe("iam authentication", () => {
121119 async ( ) => {
122120 const config = await initDefaultConfig ( env . databaseInfo . writerInstanceEndpoint ) ;
123121 config [ "user" ] = undefined ;
124- const client : AwsPGClient | AwsMySQLClient = initClientFunc ( config ) ;
122+ client = initClientFunc ( config ) ;
125123
126124 await expect ( client . connect ( ) ) . rejects . toBeInstanceOf ( AwsWrapperError ) ;
127125 } ,
@@ -133,7 +131,7 @@ describe("iam authentication", () => {
133131 async ( ) => {
134132 const config = await initDefaultConfig ( env . databaseInfo . writerInstanceEndpoint ) ;
135133 config [ "iamHost" ] = "<>" ;
136- const client : AwsPGClient | AwsMySQLClient = initClientFunc ( config ) ;
134+ client = initClientFunc ( config ) ;
137135
138136 await expect ( client . connect ( ) ) . rejects . toBeInstanceOf ( AwsWrapperError ) ;
139137 } ,
@@ -153,9 +151,9 @@ describe("iam authentication", () => {
153151 config [ "password" ] = "anything" ;
154152 config [ "iamHost" ] = instance . host ;
155153
156- const client : AwsPGClient | AwsMySQLClient = initClientFunc ( config ) ;
154+ client = initClientFunc ( config ) ;
157155
158- await validateConnection ( client ) ;
156+ await validateConnection ( ) ;
159157 } else {
160158 throw new AwsWrapperError ( "Host not found" ) ;
161159 }
@@ -169,8 +167,8 @@ describe("iam authentication", () => {
169167 async ( ) => {
170168 const config = await initDefaultConfig ( env . databaseInfo . writerInstanceEndpoint ) ;
171169 config [ "password" ] = "anything" ;
172- const client : AwsPGClient | AwsMySQLClient = initClientFunc ( config ) ;
173- await validateConnection ( client ) ;
170+ client = initClientFunc ( config ) ;
171+ await validateConnection ( ) ;
174172 } ,
175173 100000
176174 ) ;
@@ -180,8 +178,8 @@ describe("iam authentication", () => {
180178 async ( ) => {
181179 const config = await initDefaultConfig ( env . databaseInfo . writerInstanceEndpoint ) ;
182180 config [ "password" ] = undefined ;
183- const client : AwsPGClient | AwsMySQLClient = initClientFunc ( config ) ;
184- await validateConnection ( client ) ;
181+ client = initClientFunc ( config ) ;
182+ await validateConnection ( ) ;
185183 } ,
186184 100000
187185 ) ;
0 commit comments