From 460d80d310635eb95b26175e71ff254d14d2c70b Mon Sep 17 00:00:00 2001 From: Brian Seeders Date: Mon, 27 Jan 2020 21:44:58 -0500 Subject: [PATCH] Fix failing snapshot artifact tests when using env var (#56063) --- packages/kbn-es/src/artifact.test.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/kbn-es/src/artifact.test.js b/packages/kbn-es/src/artifact.test.js index 985b65c747563..453eb1a9a7689 100644 --- a/packages/kbn-es/src/artifact.test.js +++ b/packages/kbn-es/src/artifact.test.js @@ -52,21 +52,22 @@ const createArchive = (params = {}) => { const mockFetch = mock => fetch.mockReturnValue(Promise.resolve(new Response(JSON.stringify(mock)))); -let previousSnapshotManifestValue = null; +const previousEnvVars = {}; +const ENV_VARS_TO_RESET = ['ES_SNAPSHOT_MANIFEST', 'KBN_ES_SNAPSHOT_USE_UNVERIFIED']; beforeAll(() => { - if ('ES_SNAPSHOT_MANIFEST' in process.env) { - previousSnapshotManifestValue = process.env.ES_SNAPSHOT_MANIFEST; - delete process.env.ES_SNAPSHOT_MANIFEST; - } + ENV_VARS_TO_RESET.forEach(key => { + if (key in process.env) { + previousEnvVars[key] = process.env[key]; + delete process.env[key]; + } + }); }); afterAll(() => { - if (previousSnapshotManifestValue !== null) { - process.env.ES_SNAPSHOT_MANIFEST = previousSnapshotManifestValue; - } else { - delete process.env.ES_SNAPSHOT_MANIFEST; - } + Object.keys(previousEnvVars).forEach(key => { + process.env[key] = previousEnvVars[key]; + }); }); beforeEach(() => {