1
- const { setupAuth, executeStackql } = require ( "../utils" ) ;
1
+ const { setupAuth, getStackqlCommand , setOutput } = require ( "../utils" ) ;
2
2
3
3
describe ( "util" , ( ) => {
4
4
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" }}' ;
7
7
8
8
beforeEach ( ( ) => {
9
9
core = {
@@ -18,10 +18,6 @@ describe("util", () => {
18
18
console . error ( message ) ;
19
19
} ) ,
20
20
} ;
21
-
22
- exec = {
23
- exec : jest . fn ( ) . mockResolvedValue ( true ) ,
24
- } ;
25
21
} ) ;
26
22
27
23
describe ( "setupAuth" , ( ) => {
@@ -30,7 +26,6 @@ describe("util", () => {
30
26
AUTH_FILE_PATH : "./lib/tests/test-auth.json" ,
31
27
} ;
32
28
33
-
34
29
beforeEach ( ( ) => {
35
30
jest . resetModules ( ) ;
36
31
process . env = { ...AUTH_ENV } ;
@@ -43,41 +38,41 @@ describe("util", () => {
43
38
it ( "should throw error when neither AUTH_STR or AUTH_FILE_PATH is set" , ( ) => {
44
39
process . env . AUTH_STR = undefined ;
45
40
process . env . AUTH_FILE_PATH = undefined ;
46
-
47
- setupAuth ( core )
41
+
42
+ setupAuth ( core ) ;
48
43
expect ( core . setFailed ) . toBeCalledWith (
49
44
"Either AUTH_FILE_PATH or AUTH_STR must be set."
50
45
) ;
51
46
} ) ;
52
47
53
48
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 ) ;
55
52
56
- setupAuth ( core ) ;
57
-
58
- expect ( core . exportVariable ) . toBeCalledWith ( "AUTH" , expectedAuth ) ;
53
+ expect ( core . exportVariable ) . toBeCalledWith ( "AUTH" , expectedAuth ) ;
59
54
} ) ;
60
55
61
56
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 ) ;
67
62
} ) ;
68
63
69
64
it ( "should throw error when AUTH_FILE_PATH is set but file does not exist" , ( ) => {
70
65
process . env . AUTH_STR = undefined ;
71
66
process . env . AUTH_FILE_PATH = "./failed-test-auth.json" ;
72
-
73
- setupAuth ( core )
67
+
68
+ setupAuth ( core ) ;
74
69
expect ( core . setFailed ) . toBeCalledWith (
75
70
`Cannot find auth file ${ process . env . AUTH_FILE_PATH } `
76
71
) ;
77
72
} ) ;
78
73
} ) ;
79
74
80
- describe ( "executeStackql " , ( ) => {
75
+ describe ( "getStackqlCommand " , ( ) => {
81
76
const EXECUTE_ENV = {
82
77
QUERY : "test" ,
83
78
QUERY_FILE_PATH : "test-query.json" ,
@@ -91,56 +86,52 @@ describe("util", () => {
91
86
92
87
afterEach ( ( ) => {
93
88
process . env = EXECUTE_ENV ;
89
+ jest . clearAllMocks ( ) ;
94
90
} ) ;
95
91
96
92
it ( "should return error when there is neither query or query file path" , async ( ) => {
97
93
process . env = { ...EXECUTE_ENV } ;
98
94
process . env . QUERY = undefined ;
99
95
process . env . QUERY_FILE_PATH = undefined ;
100
-
101
- await executeStackql ( core , exec ) ;
96
+
97
+ getStackqlCommand ( core ) ;
102
98
103
99
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"
105
101
) ;
106
102
} ) ;
107
103
108
- it ( "should return error when there is no AUTH" , async ( ) => {
104
+ it ( "should return error when there is no AUTH" , async ( ) => {
109
105
process . env = { ...EXECUTE_ENV } ;
110
106
process . env . AUTH = undefined ;
111
107
112
- await executeStackql ( core , exec ) ;
108
+ getStackqlCommand ( core ) ;
113
109
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
+ ) ;
115
113
} ) ;
116
114
117
115
it ( "should execute stackql with query file path" , async ( ) => {
118
116
process . env = { ...EXECUTE_ENV } ;
119
117
process . env . QUERY = undefined ;
120
118
121
- await executeStackql ( core , exec ) ;
119
+ getStackqlCommand ( core ) ;
122
120
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
+ ) ;
130
124
} ) ;
131
125
132
126
it ( "should execute stackql with query" , async ( ) => {
133
127
process . env = { ...EXECUTE_ENV } ;
134
128
process . env . QUERY_FILE_PATH = undefined ;
135
129
136
- await executeStackql ( core , exec ) ;
130
+ getStackqlCommand ( core ) ;
137
131
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
+ ) ;
144
135
} ) ;
145
136
} ) ;
146
137
} ) ;
0 commit comments