Add extra test ensuring env var overrides cached feature flag
This commit is contained in:
parent
cfce1c4e19
commit
4ee97e5e55
3 changed files with 44 additions and 1 deletions
12
lib/feature-flags.test.js
generated
12
lib/feature-flags.test.js
generated
|
|
@ -196,6 +196,18 @@ for (const feature of Object.keys(feature_flags_1.featureConfig)) {
|
|||
t.false(await featureEnablement.getValue(feature_flags_1.Feature.CliConfigFileEnabled, includeCodeQlIfRequired(feature_flags_1.Feature.CliConfigFileEnabled)), "Feature flag should be enabled after reading from cached file");
|
||||
});
|
||||
});
|
||||
(0, ava_1.default)("Environment variable can override feature flag cache", async (t) => {
|
||||
await (0, util_1.withTmpDir)(async (tmpDir) => {
|
||||
const featureEnablement = setUpFeatureFlagTests(tmpDir);
|
||||
const expectedFeatureEnablement = initializeFeatures(true);
|
||||
(0, testing_utils_1.mockFeatureFlagApiEndpoint)(200, expectedFeatureEnablement);
|
||||
const cachedFeatureFlags = path.join(tmpDir, feature_flags_1.FEATURE_FLAGS_FILE_NAME);
|
||||
t.true(await featureEnablement.getValue(feature_flags_1.Feature.CliConfigFileEnabled, includeCodeQlIfRequired(feature_flags_1.Feature.CliConfigFileEnabled)), "Feature flag should be enabled initially");
|
||||
t.true(fs.existsSync(cachedFeatureFlags), "Feature flag cached file should exist after getting feature flags");
|
||||
process.env.CODEQL_PASS_CONFIG_TO_CLI = "false";
|
||||
t.false(await featureEnablement.getValue(feature_flags_1.Feature.CliConfigFileEnabled, includeCodeQlIfRequired(feature_flags_1.Feature.CliConfigFileEnabled)), "Feature flag should be disabled after setting env var");
|
||||
});
|
||||
});
|
||||
function assertAllFeaturesUndefinedInApi(t, loggedMessages) {
|
||||
for (const feature of Object.keys(feature_flags_1.featureConfig)) {
|
||||
t.assert(loggedMessages.find((v) => v.type === "debug" &&
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -340,6 +340,37 @@ test("Feature flags are saved to disk", async (t) => {
|
|||
});
|
||||
});
|
||||
|
||||
test("Environment variable can override feature flag cache", async (t) => {
|
||||
await withTmpDir(async (tmpDir) => {
|
||||
const featureEnablement = setUpFeatureFlagTests(tmpDir);
|
||||
const expectedFeatureEnablement = initializeFeatures(true);
|
||||
mockFeatureFlagApiEndpoint(200, expectedFeatureEnablement);
|
||||
|
||||
const cachedFeatureFlags = path.join(tmpDir, FEATURE_FLAGS_FILE_NAME);
|
||||
t.true(
|
||||
await featureEnablement.getValue(
|
||||
Feature.CliConfigFileEnabled,
|
||||
includeCodeQlIfRequired(Feature.CliConfigFileEnabled)
|
||||
),
|
||||
"Feature flag should be enabled initially"
|
||||
);
|
||||
|
||||
t.true(
|
||||
fs.existsSync(cachedFeatureFlags),
|
||||
"Feature flag cached file should exist after getting feature flags"
|
||||
);
|
||||
process.env.CODEQL_PASS_CONFIG_TO_CLI = "false";
|
||||
|
||||
t.false(
|
||||
await featureEnablement.getValue(
|
||||
Feature.CliConfigFileEnabled,
|
||||
includeCodeQlIfRequired(Feature.CliConfigFileEnabled)
|
||||
),
|
||||
"Feature flag should be disabled after setting env var"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
function assertAllFeaturesUndefinedInApi(t, loggedMessages: LoggedMessage[]) {
|
||||
for (const feature of Object.keys(featureConfig)) {
|
||||
t.assert(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue