|
| 1 | +import test from "ava"; |
| 2 | + |
| 3 | +import { mockCodeQLVersion, setupTests } from "../testing-utils"; |
| 4 | +import { DiskUsage } from "../util"; |
| 5 | + |
| 6 | +import { getCacheKey } from "./status"; |
| 7 | + |
| 8 | +setupTests(test); |
| 9 | + |
| 10 | +function makeDiskUsage(totalGiB: number): DiskUsage { |
| 11 | + return { |
| 12 | + numTotalBytes: totalGiB * 1024 * 1024 * 1024, |
| 13 | + numAvailableBytes: 0, |
| 14 | + }; |
| 15 | +} |
| 16 | + |
| 17 | +test("getCacheKey incorporates language, CodeQL version, and disk space", async (t) => { |
| 18 | + const codeql = mockCodeQLVersion("2.20.0"); |
| 19 | + t.is( |
| 20 | + await getCacheKey(codeql, "javascript", makeDiskUsage(50)), |
| 21 | + "codeql-overlay-status-javascript-2.20.0-runner-50GB", |
| 22 | + ); |
| 23 | + t.is( |
| 24 | + await getCacheKey(codeql, "python", makeDiskUsage(50)), |
| 25 | + "codeql-overlay-status-python-2.20.0-runner-50GB", |
| 26 | + ); |
| 27 | + t.is( |
| 28 | + await getCacheKey( |
| 29 | + mockCodeQLVersion("2.21.0"), |
| 30 | + "javascript", |
| 31 | + makeDiskUsage(50), |
| 32 | + ), |
| 33 | + "codeql-overlay-status-javascript-2.21.0-runner-50GB", |
| 34 | + ); |
| 35 | + t.is( |
| 36 | + await getCacheKey(codeql, "javascript", makeDiskUsage(100)), |
| 37 | + "codeql-overlay-status-javascript-2.20.0-runner-100GB", |
| 38 | + ); |
| 39 | +}); |
| 40 | + |
| 41 | +test("getCacheKey rounds disk space down to nearest 10 GiB", async (t) => { |
| 42 | + const codeql = mockCodeQLVersion("2.20.0"); |
| 43 | + t.is( |
| 44 | + await getCacheKey(codeql, "javascript", makeDiskUsage(14)), |
| 45 | + "codeql-overlay-status-javascript-2.20.0-runner-10GB", |
| 46 | + ); |
| 47 | + t.is( |
| 48 | + await getCacheKey(codeql, "javascript", makeDiskUsage(19)), |
| 49 | + "codeql-overlay-status-javascript-2.20.0-runner-10GB", |
| 50 | + ); |
| 51 | +}); |
0 commit comments