@@ -6,7 +6,7 @@ import { Firebolt, QueryFormatter } from "../../../src";
66import { ResourceManager } from "../../../src/service" ;
77import { ConnectionError , DeprecationError } from "../../../src/common/errors" ;
88import { NodeHttpClient } from "../../../src/http/node" ;
9- import { Authenticator } from "../../../src/auth" ;
9+ import { Authenticator } from "../../../src/auth" ;
1010
1111const apiEndpoint = "api.fake.firebolt.io" ;
1212
@@ -225,7 +225,7 @@ describe("engine service", () => {
225225 client_id : "id" ,
226226 client_secret : "secret"
227227 }
228- }
228+ } ;
229229 const firebolt = Firebolt ( { apiEndpoint } ) ;
230230 const connection = await firebolt . connect ( connectionOptions ) ;
231231 // Also test diffrent way of instantiating a resource manager
@@ -367,9 +367,70 @@ describe("engine service", () => {
367367 try {
368368 await engine . delete ( ) ;
369369 expect ( false ) . toBeTruthy ( ) ;
370- }
371- catch ( e ) {
370+ } catch ( e ) {
372371 expect ( true ) . toBeTruthy ( ) ;
373372 }
374373 } ) ;
374+ it ( "create engine with options" , async ( ) => {
375+ server . use (
376+ rest . post (
377+ `https://some_system_engine.com/${ QUERY_URL } ` ,
378+ async ( req , res , ctx ) => {
379+ const requestBody = await req . text ( ) ;
380+ if ( requestBody . includes ( "CREATE ENGINE" ) ) {
381+ expect ( requestBody ) . toContain ( `ENGINE_TYPE = 'GENERAL_PURPOSE'` ) ;
382+ expect ( requestBody ) . not . toContain ( `REGION` ) ;
383+ }
384+ return res ( ctx . json ( selectEngineResponse ) ) ;
385+ }
386+ )
387+ ) ;
388+ const firebolt = Firebolt ( { apiEndpoint } ) ;
389+ await firebolt . connect ( {
390+ account : "my_account" ,
391+ auth : {
392+ client_id : "id" ,
393+ client_secret : "secret"
394+ }
395+ } ) ;
396+ const resourceManager = firebolt . resourceManager ;
397+ const engine = await resourceManager . engine . create ( "some_engine" , {
398+ region : undefined ,
399+ engine_type : "GENERAL_PURPOSE"
400+ } ) ;
401+ expect ( engine ) . toBeTruthy ( ) ;
402+ expect ( engine . endpoint ) . toEqual ( "https://some_engine.com" ) ;
403+ } ) ;
404+ it ( "create engine with environment variable" , async ( ) => {
405+ const engine_version = "20.1.1" ;
406+ server . use (
407+ rest . post (
408+ `https://some_system_engine.com/${ QUERY_URL } ` ,
409+ async ( req , res , ctx ) => {
410+ const requestBody = await req . text ( ) ;
411+ if ( requestBody . includes ( "CREATE ENGINE" ) ) {
412+ expect ( requestBody ) . toContain ( `VERSION = '${ engine_version } '` ) ;
413+ }
414+ return res ( ctx . json ( selectEngineResponse ) ) ;
415+ }
416+ )
417+ ) ;
418+ const firebolt = Firebolt ( { apiEndpoint } ) ;
419+ await firebolt . connect ( {
420+ account : "my_account" ,
421+ auth : {
422+ client_id : "id" ,
423+ client_secret : "secret"
424+ }
425+ } ) ;
426+ const resourceManager = firebolt . resourceManager ;
427+
428+ process . env . FB_INTERNAL_OPTIONS_ENGINE_VERSION = engine_version ;
429+
430+ const engine = await resourceManager . engine . create ( "some_engine" ) ;
431+ expect ( engine ) . toBeTruthy ( ) ;
432+ expect ( engine . endpoint ) . toEqual ( "https://some_engine.com" ) ;
433+
434+ delete process . env . ENGINE_NAME ;
435+ } ) ;
375436} ) ;
0 commit comments