@@ -98,53 +98,72 @@ test("getCodeQLSource sets CLI version for a semver tagged bundle", async (t) =>
98
98
} ) ;
99
99
100
100
test ( "getCodeQLSource correctly returns bundled CLI version when tools == linked" , async ( t ) => {
101
- const loggedMessages : LoggedMessage [ ] = [ ] ;
102
- const logger = getRecordingLogger ( loggedMessages ) ;
103
-
104
101
await withTmpDir ( async ( tmpDir ) => {
105
102
setupActionsVars ( tmpDir , tmpDir ) ;
106
103
const source = await setupCodeql . getCodeQLSource (
107
104
"linked" ,
108
105
SAMPLE_DEFAULT_CLI_VERSION ,
109
106
SAMPLE_DOTCOM_API_DETAILS ,
110
107
GitHubVariant . DOTCOM ,
111
- logger ,
108
+ getRunnerLogger ( true ) ,
112
109
) ;
113
110
114
- // Assert first that we got the right version of the CodeQL CLI,
115
- // and that we're sourcing it using the correct method for that.
116
111
t . is ( source . toolsVersion , LINKED_CLI_VERSION . cliVersion ) ;
117
112
t . is ( source . sourceType , "download" ) ;
118
-
119
- // Ensure that we're adequately notifying the user of the version we're using.
120
- const expected_message : LoggedMessage = {
121
- type : "info" ,
122
- message : `Using CodeQL CLI version: ${ LINKED_CLI_VERSION . cliVersion } from download.` ,
123
- } ;
124
-
125
- loggedMessages . forEach ( ( msg ) => {
126
- console . log ( msg . message ) ;
127
- } ) ;
128
-
129
- t . assert ( loggedMessages . includes ( expected_message ) ) ;
130
113
} ) ;
131
114
} ) ;
132
115
133
116
test ( "getCodeQLSource correctly returns bundled CLI version when tools == latest" , async ( t ) => {
134
- const loggedMessages = [ ] ;
135
- const logger = getRecordingLogger ( loggedMessages ) ;
136
-
137
117
await withTmpDir ( async ( tmpDir ) => {
138
118
setupActionsVars ( tmpDir , tmpDir ) ;
139
119
const source = await setupCodeql . getCodeQLSource (
140
120
"latest" ,
141
121
SAMPLE_DEFAULT_CLI_VERSION ,
142
122
SAMPLE_DOTCOM_API_DETAILS ,
143
123
GitHubVariant . DOTCOM ,
144
- logger ,
124
+ getRunnerLogger ( true ) ,
145
125
) ;
146
126
147
127
t . is ( source . toolsVersion , LINKED_CLI_VERSION . cliVersion ) ;
148
128
t . is ( source . sourceType , "download" ) ;
149
129
} ) ;
150
130
} ) ;
131
+
132
+ test ( "setupCodeQLBundle logs the CodeQL CLI version being used" , async ( t ) => {
133
+ const loggedMessages : LoggedMessage [ ] = [ ] ;
134
+ const logger = getRecordingLogger ( loggedMessages ) ;
135
+
136
+ // Stub the downloadCodeQL function to prevent downloading artefacts
137
+ // during testing from being called.
138
+ sinon . stub ( setupCodeql , "downloadCodeQL" ) . resolves ( {
139
+ toolsVersion : LINKED_CLI_VERSION . cliVersion ,
140
+ codeqlFolder : "codeql" ,
141
+ toolsDownloadDurationMs : 200 ,
142
+ } ) ;
143
+
144
+ await withTmpDir ( async ( tmpDir ) => {
145
+ setupActionsVars ( tmpDir , tmpDir ) ;
146
+ const result = await setupCodeql . setupCodeQLBundle (
147
+ "linked" ,
148
+ SAMPLE_DOTCOM_API_DETAILS ,
149
+ "tmp/codeql_action_test/" ,
150
+ GitHubVariant . DOTCOM ,
151
+ SAMPLE_DEFAULT_CLI_VERSION ,
152
+ logger ,
153
+ ) ;
154
+
155
+ // Basic sanity check that the version we got back is indeed
156
+ // the linked (default) CLI version.
157
+ t . is ( result . toolsVersion , LINKED_CLI_VERSION . cliVersion ) ;
158
+
159
+ const expected_message : LoggedMessage = {
160
+ type : "info" ,
161
+ message : `Using CodeQL CLI version ${ LINKED_CLI_VERSION . cliVersion } from download.` ,
162
+ } ;
163
+
164
+ // Ensure message logging CodeQL CLI version was present in user logs.
165
+ t . assert (
166
+ loggedMessages . some ( ( msg ) => msg . message === expected_message . message ) ,
167
+ ) ;
168
+ } ) ;
169
+ } ) ;
0 commit comments