Skip to content

Commit 318913c

Browse files
committed
Add test for uploadSarif with upload: never
1 parent 7cd944c commit 318913c

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/upload-sarif.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,41 @@ test(
195195
},
196196
},
197197
);
198+
199+
test("uploadSarif doesn't upload if `upload` != `always`", async (t) => {
200+
await util.withTmpDir(async (tempDir) => {
201+
const logger = getRunnerLogger(true);
202+
const features = createFeatures([]);
203+
204+
const toFullPath = (filename: string) => path.join(tempDir, filename);
205+
206+
const postProcessSarifFiles = sinon.stub(
207+
uploadLib,
208+
"postProcessSarifFiles",
209+
);
210+
const uploadProcessedFiles = sinon.stub(uploadLib, "uploadProcessedFiles");
211+
212+
for (const analysisKind of Object.values(AnalysisKind)) {
213+
const analysisConfig = getAnalysisConfig(analysisKind);
214+
postProcessSarifFiles
215+
.withArgs(
216+
logger,
217+
sinon.match.any,
218+
sinon.match.any,
219+
sinon.match.any,
220+
sinon.match.any,
221+
analysisConfig,
222+
)
223+
.resolves({ sarif: { runs: [] }, analysisKey: "", environment: "" });
224+
}
225+
226+
fs.writeFileSync(toFullPath("test.sarif"), "");
227+
fs.writeFileSync(toFullPath("test.quality.sarif"), "");
228+
229+
const actual = await uploadSarif(logger, features, "never", "", tempDir);
230+
231+
t.truthy(actual);
232+
t.assert(postProcessSarifFiles.calledTwice);
233+
t.assert(uploadProcessedFiles.notCalled);
234+
});
235+
});

0 commit comments

Comments
 (0)