Throw an error if the feature flag API request errors

This commit is contained in:
Henry Mercer 2021-12-15 16:29:34 +00:00
parent d6499fad61
commit 621e0794ac
6 changed files with 28 additions and 37 deletions

View file

@ -27,6 +27,7 @@ const ava_1 = __importDefault(require("ava"));
const sinon = __importStar(require("sinon"));
const apiClient = __importStar(require("./api-client"));
const feature_flags_1 = require("./feature-flags");
const logging_1 = require("./logging");
const testing_utils_1 = require("./testing-utils");
const util = __importStar(require("./util"));
const util_1 = require("./util");
@ -102,18 +103,14 @@ for (const variant of ALL_FEATURE_FLAGS_DISABLED_VARIANTS) {
}
});
});
(0, ava_1.default)("All feature flags are disabled if the API request errors", async (t) => {
(0, ava_1.default)("Feature flags exception is propagated if the API request errors", async (t) => {
await (0, util_1.withTmpDir)(async (tmpDir) => {
(0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir);
const loggedMessages = [];
const featureFlags = new feature_flags_1.GitHubFeatureFlags({ type: util_1.GitHubVariant.DOTCOM }, testApiDetails, (0, testing_utils_1.getRecordingLogger)(loggedMessages));
const featureFlags = new feature_flags_1.GitHubFeatureFlags({ type: util_1.GitHubVariant.DOTCOM }, testApiDetails, (0, logging_1.getRunnerLogger)(true));
mockHttpRequests(500, {});
t.assert((await featureFlags.getDatabaseUploadsEnabled()) === false);
t.assert((await featureFlags.getMlPoweredQueriesEnabled()) === false);
t.assert((await featureFlags.getUploadsDomainEnabled()) === false);
t.assert(loggedMessages.find((v) => v.type === "info" &&
v.message ===
"Disabling all feature flags due to unknown error: Error: some error message") !== undefined);
await t.throwsAsync(async () => featureFlags.preloadFeatureFlags(), {
message: "Encountered an error while trying to load feature flags: Error: some error message",
});
});
});
const FEATURE_FLAGS = [
@ -125,8 +122,7 @@ for (const featureFlag of FEATURE_FLAGS) {
(0, ava_1.default)(`Feature flag '${featureFlag}' is enabled if enabled in the API response`, async (t) => {
await (0, util_1.withTmpDir)(async (tmpDir) => {
(0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir);
const loggedMessages = [];
const featureFlags = new feature_flags_1.GitHubFeatureFlags({ type: util_1.GitHubVariant.DOTCOM }, testApiDetails, (0, testing_utils_1.getRecordingLogger)(loggedMessages));
const featureFlags = new feature_flags_1.GitHubFeatureFlags({ type: util_1.GitHubVariant.DOTCOM }, testApiDetails, (0, logging_1.getRunnerLogger)(true));
const expectedFeatureFlags = {};
for (const f of FEATURE_FLAGS) {
expectedFeatureFlags[f] = false;