Skip to content

Commit

Permalink
Fix failing snapshot artifact tests when using env var (elastic#56063)
Browse files Browse the repository at this point in the history
  • Loading branch information
brianseeders committed Jan 28, 2020
1 parent bc1058b commit 8a8efdf
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions packages/kbn-es/src/artifact.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down

0 comments on commit 8a8efdf

Please sign in to comment.