1- const { setupAuth, executeStackql } = require ( "../utils" ) ;
1+ const { setupAuth, getStackqlCommand , setOutput } = require ( "../utils" ) ;
22
33describe ( "util" , ( ) => {
44 let core ;
5- let exec ;
6- const expectedAuth = '{ "google": { "type": "service_account", "credentialsfilepath": "sa-key.json" }}'
5+ const expectedAuth =
6+ '{ "google": { "type": "service_account", "credentialsfilepath": "sa-key.json" }}' ;
77
88 beforeEach ( ( ) => {
99 core = {
@@ -18,10 +18,6 @@ describe("util", () => {
1818 console . error ( message ) ;
1919 } ) ,
2020 } ;
21-
22- exec = {
23- exec : jest . fn ( ) . mockResolvedValue ( true ) ,
24- } ;
2521 } ) ;
2622
2723 describe ( "setupAuth" , ( ) => {
@@ -30,7 +26,6 @@ describe("util", () => {
3026 AUTH_FILE_PATH : "./lib/tests/test-auth.json" ,
3127 } ;
3228
33-
3429 beforeEach ( ( ) => {
3530 jest . resetModules ( ) ;
3631 process . env = { ...AUTH_ENV } ;
@@ -43,41 +38,41 @@ describe("util", () => {
4338 it ( "should throw error when neither AUTH_STR or AUTH_FILE_PATH is set" , ( ) => {
4439 process . env . AUTH_STR = undefined ;
4540 process . env . AUTH_FILE_PATH = undefined ;
46-
47- setupAuth ( core )
41+
42+ setupAuth ( core ) ;
4843 expect ( core . setFailed ) . toBeCalledWith (
4944 "Either AUTH_FILE_PATH or AUTH_STR must be set."
5045 ) ;
5146 } ) ;
5247
5348 it ( "should set AUTH environment variable when AUTH_STR is set" , ( ) => {
54- process . env . AUTH_FILE_PATH = undefined ;
49+ process . env . AUTH_FILE_PATH = undefined ;
50+
51+ setupAuth ( core ) ;
5552
56- setupAuth ( core ) ;
57-
58- expect ( core . exportVariable ) . toBeCalledWith ( "AUTH" , expectedAuth ) ;
53+ expect ( core . exportVariable ) . toBeCalledWith ( "AUTH" , expectedAuth ) ;
5954 } ) ;
6055
6156 it ( "should set AUTH environment variable when AUTH_FILE_PATH is set" , ( ) => {
62- process . env . AUTH_STR = undefined ;
63-
64- setupAuth ( core ) ;
65-
66- expect ( core . exportVariable ) . toBeCalledWith ( "AUTH" , expectedAuth ) ;
57+ process . env . AUTH_STR = undefined ;
58+
59+ setupAuth ( core ) ;
60+
61+ expect ( core . exportVariable ) . toBeCalledWith ( "AUTH" , expectedAuth ) ;
6762 } ) ;
6863
6964 it ( "should throw error when AUTH_FILE_PATH is set but file does not exist" , ( ) => {
7065 process . env . AUTH_STR = undefined ;
7166 process . env . AUTH_FILE_PATH = "./failed-test-auth.json" ;
72-
73- setupAuth ( core )
67+
68+ setupAuth ( core ) ;
7469 expect ( core . setFailed ) . toBeCalledWith (
7570 `Cannot find auth file ${ process . env . AUTH_FILE_PATH } `
7671 ) ;
7772 } ) ;
7873 } ) ;
7974
80- describe ( "executeStackql " , ( ) => {
75+ describe ( "getStackqlCommand " , ( ) => {
8176 const EXECUTE_ENV = {
8277 QUERY : "test" ,
8378 QUERY_FILE_PATH : "test-query.json" ,
@@ -91,56 +86,52 @@ describe("util", () => {
9186
9287 afterEach ( ( ) => {
9388 process . env = EXECUTE_ENV ;
89+ jest . clearAllMocks ( ) ;
9490 } ) ;
9591
9692 it ( "should return error when there is neither query or query file path" , async ( ) => {
9793 process . env = { ...EXECUTE_ENV } ;
9894 process . env . QUERY = undefined ;
9995 process . env . QUERY_FILE_PATH = undefined ;
100-
101- await executeStackql ( core , exec ) ;
96+
97+ getStackqlCommand ( core ) ;
10298
10399 expect ( core . setFailed ) . toBeCalledWith (
104- "Either test_query or test_query_file_path need to be set"
100+ "Either query or query_file_path need to be set"
105101 ) ;
106102 } ) ;
107103
108- it ( "should return error when there is no AUTH" , async ( ) => {
104+ it ( "should return error when there is no AUTH" , async ( ) => {
109105 process . env = { ...EXECUTE_ENV } ;
110106 process . env . AUTH = undefined ;
111107
112- await executeStackql ( core , exec ) ;
108+ getStackqlCommand ( core ) ;
113109
114- expect ( core . setFailed ) . toHaveBeenCalledWith ( "Cannot find AUTH environment variable when executing stackql" ) ;
110+ expect ( core . setFailed ) . toHaveBeenCalledWith (
111+ "Cannot find AUTH environment variable when executing stackql"
112+ ) ;
115113 } ) ;
116114
117115 it ( "should execute stackql with query file path" , async ( ) => {
118116 process . env = { ...EXECUTE_ENV } ;
119117 process . env . QUERY = undefined ;
120118
121- await executeStackql ( core , exec ) ;
119+ getStackqlCommand ( core ) ;
122120
123- expect ( exec . exec ) . toHaveBeenCalledWith ( "stackql" , [
124- "exec" ,
125- "-i" ,
126- "test-query.json" ,
127- "--auth=test-auth" ,
128- "--output=json" ,
129- ] ) ;
121+ expect ( core . exportVariable ) . toBeCalledWith (
122+ "STACKQL_COMMAND" , "stackql exec -i test-query.json --auth='test-auth' --output='json'"
123+ ) ;
130124 } ) ;
131125
132126 it ( "should execute stackql with query" , async ( ) => {
133127 process . env = { ...EXECUTE_ENV } ;
134128 process . env . QUERY_FILE_PATH = undefined ;
135129
136- await executeStackql ( core , exec ) ;
130+ getStackqlCommand ( core ) ;
137131
138- expect ( exec . exec ) . toHaveBeenCalledWith ( "stackql" , [
139- "exec" ,
140- "test" ,
141- "--auth=test-auth" ,
142- "--output=json" ,
143- ] ) ;
132+ expect ( core . exportVariable ) . toBeCalledWith (
133+ "STACKQL_COMMAND" , "stackql exec \"test\" --auth='test-auth' --output='json'"
134+ ) ;
144135 } ) ;
145136 } ) ;
146137} ) ;
0 commit comments