Skip to content

Commit a91b7a3

Browse files
committed
Add unit tests for isTrapCachingEnabled
1 parent 556dd79 commit a91b7a3

File tree

2 files changed

+120
-1
lines changed

2 files changed

+120
-1
lines changed

src/config-utils.test.ts

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import * as overlayStatus from "./overlay/status";
2626
import { parseRepositoryNwo } from "./repository";
2727
import {
2828
setupTests,
29+
setupActionsVars,
2930
mockLanguagesInRepo as mockLanguagesInRepo,
3031
createFeatures,
3132
getRecordingLogger,
@@ -2054,3 +2055,121 @@ test.serial("getPrimaryAnalysisConfig - Code Scanning + Code Quality", (t) => {
20542055
AnalysisKind.CodeScanning,
20552056
);
20562057
});
2058+
2059+
test.serial(
2060+
"isTrapCachingEnabled: explicit input true is respected",
2061+
async (t) => {
2062+
return await withTmpDir(async (tmpDir) => {
2063+
setupActionsVars(tmpDir, tmpDir);
2064+
sinon
2065+
.stub(actionsUtil, "getOptionalInput")
2066+
.withArgs("trap-caching")
2067+
.returns("true");
2068+
t.true(
2069+
await configUtils.isTrapCachingEnabled(
2070+
createFeatures([]),
2071+
OverlayDatabaseMode.None,
2072+
),
2073+
);
2074+
});
2075+
},
2076+
);
2077+
2078+
test.serial(
2079+
"isTrapCachingEnabled: disabled on self-hosted runner by default",
2080+
async (t) => {
2081+
return await withTmpDir(async (tmpDir) => {
2082+
setupActionsVars(tmpDir, tmpDir);
2083+
sinon
2084+
.stub(actionsUtil, "getOptionalInput")
2085+
.withArgs("trap-caching")
2086+
.returns(undefined);
2087+
t.false(
2088+
await configUtils.isTrapCachingEnabled(
2089+
createFeatures([]),
2090+
OverlayDatabaseMode.None,
2091+
),
2092+
);
2093+
});
2094+
},
2095+
);
2096+
2097+
test.serial(
2098+
"isTrapCachingEnabled: enabled on hosted runner by default",
2099+
async (t) => {
2100+
return await withTmpDir(async (tmpDir) => {
2101+
const hostedToolCache = path.join(tmpDir, "hostedtoolcache");
2102+
setupActionsVars(tmpDir, hostedToolCache);
2103+
sinon
2104+
.stub(actionsUtil, "getOptionalInput")
2105+
.withArgs("trap-caching")
2106+
.returns(undefined);
2107+
t.true(
2108+
await configUtils.isTrapCachingEnabled(
2109+
createFeatures([]),
2110+
OverlayDatabaseMode.None,
2111+
),
2112+
);
2113+
});
2114+
},
2115+
);
2116+
2117+
test.serial(
2118+
"isTrapCachingEnabled: enabled on hosted runner when overlay enabled but feature flag off",
2119+
async (t) => {
2120+
return await withTmpDir(async (tmpDir) => {
2121+
const hostedToolCache = path.join(tmpDir, "hostedtoolcache");
2122+
setupActionsVars(tmpDir, hostedToolCache);
2123+
sinon
2124+
.stub(actionsUtil, "getOptionalInput")
2125+
.withArgs("trap-caching")
2126+
.returns(undefined);
2127+
t.true(
2128+
await configUtils.isTrapCachingEnabled(
2129+
createFeatures([]),
2130+
OverlayDatabaseMode.Overlay,
2131+
),
2132+
);
2133+
});
2134+
},
2135+
);
2136+
2137+
test.serial(
2138+
"isTrapCachingEnabled: disabled on hosted runner when overlay enabled and feature flag on",
2139+
async (t) => {
2140+
return await withTmpDir(async (tmpDir) => {
2141+
const hostedToolCache = path.join(tmpDir, "hostedtoolcache");
2142+
setupActionsVars(tmpDir, hostedToolCache);
2143+
sinon
2144+
.stub(actionsUtil, "getOptionalInput")
2145+
.withArgs("trap-caching")
2146+
.returns(undefined);
2147+
t.false(
2148+
await configUtils.isTrapCachingEnabled(
2149+
createFeatures([Feature.OverlayAnalysisDisableTrapCaching]),
2150+
OverlayDatabaseMode.Overlay,
2151+
),
2152+
);
2153+
});
2154+
},
2155+
);
2156+
2157+
test.serial(
2158+
"isTrapCachingEnabled: enabled on hosted runner when overlay is None even with feature flag on",
2159+
async (t) => {
2160+
return await withTmpDir(async (tmpDir) => {
2161+
const hostedToolCache = path.join(tmpDir, "hostedtoolcache");
2162+
setupActionsVars(tmpDir, hostedToolCache);
2163+
sinon
2164+
.stub(actionsUtil, "getOptionalInput")
2165+
.withArgs("trap-caching")
2166+
.returns(undefined);
2167+
t.true(
2168+
await configUtils.isTrapCachingEnabled(
2169+
createFeatures([Feature.OverlayAnalysisDisableTrapCaching]),
2170+
OverlayDatabaseMode.None,
2171+
),
2172+
);
2173+
});
2174+
},
2175+
);

src/config-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ async function validateOverlayDatabaseMode(
998998
});
999999
}
10001000

1001-
async function isTrapCachingEnabled(
1001+
export async function isTrapCachingEnabled(
10021002
features: FeatureEnablement,
10031003
overlayDatabaseMode: OverlayDatabaseMode,
10041004
): Promise<boolean> {

0 commit comments

Comments
 (0)