@@ -14,7 +14,7 @@ import {
1414
1515const apiEndpoint = "api.fake.firebolt.io" ;
1616
17- const selectEngineResponse = {
17+ export const selectEngineResponse = {
1818 meta : [
1919 {
2020 name : "engine_name" ,
@@ -33,7 +33,7 @@ const selectEngineResponse = {
3333 rows : 1
3434} ;
3535
36- const selectEnginesResponse = {
36+ export const selectEnginesResponse = {
3737 meta : [
3838 {
3939 name : "engine_name" ,
@@ -119,6 +119,36 @@ describe("engine service", () => {
119119 expect ( engine ) . toBeTruthy ( ) ;
120120 expect ( engine . endpoint ) . toEqual ( "https://some_engine.com" ) ;
121121 } ) ;
122+
123+ it ( "gets engine by name v2 status" , async ( ) => {
124+ // Copy
125+ const engineResponse = JSON . parse ( JSON . stringify ( selectEngineResponse ) ) ;
126+ engineResponse . data . forEach ( ( row : string [ ] ) => {
127+ row [ 2 ] = "RUNNING" ;
128+ } ) ;
129+ server . use (
130+ rest . post (
131+ `https://some_system_engine.com/${ QUERY_URL } ` ,
132+ ( req , res , ctx ) => {
133+ return res ( ctx . json ( engineResponse ) ) ;
134+ }
135+ )
136+ ) ;
137+
138+ const firebolt = Firebolt ( { apiEndpoint } ) ;
139+ await firebolt . connect ( {
140+ account : "my_account" ,
141+ auth : {
142+ client_id : "id" ,
143+ client_secret : "secret"
144+ }
145+ } ) ;
146+ const resourceManager = firebolt . resourceManager ;
147+ const engine = await resourceManager . engine . getByName ( "some_engine" ) ;
148+ expect ( engine ) . toBeTruthy ( ) ;
149+ expect ( engine . endpoint ) . toEqual ( "https://some_engine.com" ) ;
150+ } ) ;
151+
122152 it ( "starts engine" , async ( ) => {
123153 let startEngineCalled = false ;
124154 const expectedEngine = "some_engine" ;
@@ -256,6 +286,58 @@ describe("engine service", () => {
256286 expect ( engines [ 1 ] . endpoint ) . toEqual ( "https://some_other_engine.com" ) ;
257287 } ) ;
258288
289+ it ( "gets all engines v2 status" , async ( ) => {
290+ // Copy
291+ const engineResponse = JSON . parse ( JSON . stringify ( selectEnginesResponse ) ) ;
292+ engineResponse . data . forEach ( ( row : string [ ] ) => {
293+ row [ 2 ] = "RUNNING" ;
294+ } ) ;
295+ server . use (
296+ rest . post (
297+ `https://some_system_engine.com/${ QUERY_URL } ` ,
298+ ( req , res , ctx ) => {
299+ return res ( ctx . json ( engineResponse ) ) ;
300+ }
301+ )
302+ ) ;
303+
304+ const connectionOptions = {
305+ account : "my_account" ,
306+ auth : {
307+ client_id : "id" ,
308+ client_secret : "secret"
309+ }
310+ } ;
311+ const firebolt = Firebolt ( { apiEndpoint } ) ;
312+ const connection = await firebolt . connect ( connectionOptions ) ;
313+ // Also test diffrent way of instantiating a resource manager
314+ const logger = new Logger ( ) ;
315+ const httpClient = new NodeHttpClient ( ) ;
316+ new Authenticator (
317+ {
318+ httpClient,
319+ logger,
320+ apiEndpoint,
321+ queryFormatter : new QueryFormatter ( )
322+ } ,
323+ connectionOptions
324+ ) ;
325+ const resourceManager = new ResourceManager ( {
326+ logger,
327+ connection,
328+ apiEndpoint,
329+ httpClient
330+ } ) ;
331+ const engines = await resourceManager . engine . getAll ( ) ;
332+ expect ( engines ) . toBeTruthy ( ) ;
333+ expect ( engines [ 0 ] . current_status_summary ) . toEqual (
334+ EngineStatusSummary . RUNNING
335+ ) ;
336+ expect ( engines [ 1 ] . current_status_summary ) . toEqual (
337+ EngineStatusSummary . RUNNING
338+ ) ;
339+ } ) ;
340+
259341 it ( "does not start engine that errors out" , async ( ) => {
260342 let startEngineCalled = false ;
261343 const expectedEngine = "some_engine" ;
@@ -298,6 +380,7 @@ describe("engine service", () => {
298380 const engine = await resourceManager . engine . getByName ( expectedEngine ) ;
299381 expect ( engine . start ( ) ) . rejects . toThrowError ( ConnectionError ) ;
300382 } ) ;
383+
301384 it ( "does not start engine that has unexpected status" , async ( ) => {
302385 let startEngineCalled = false ;
303386 const expectedEngine = "some_engine" ;
@@ -463,6 +546,7 @@ describe("engine service", () => {
463546 expect ( engine ) . toBeTruthy ( ) ;
464547 expect ( engine . endpoint ) . toEqual ( "https://some_engine.com" ) ;
465548 } ) ;
549+
466550 it ( "create engine with environment variable" , async ( ) => {
467551 const engine_version = "20.1.1" ;
468552 server . use (
@@ -495,10 +579,13 @@ describe("engine service", () => {
495579
496580 delete process . env . ENGINE_NAME ;
497581 } ) ;
582+
498583 it ( "Parses different engine statuses correctly" , async ( ) => {
499584 const statuses = [ "RUNNING" , "Running" , "running" ] ;
500585 for ( const status of statuses ) {
501586 expect ( processEngineStatus ( status ) ) . toEqual ( EngineStatusSummary . RUNNING ) ;
502587 }
588+ expect ( processEngineStatus ( undefined ) ) . toBe ( undefined ) ;
589+ expect ( processEngineStatus ( "unexisting" ) ) . not . toBeTruthy ( ) ;
503590 } ) ;
504591} ) ;
0 commit comments