Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EsArchiver: support for injecting kibana version and use it for spaces tests #94420

Merged
merged 4 commits into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/kbn-es-archiver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0",
"private": "true",
"main": "target/index.js",
"main": "target/packages/kbn-es-archiver/src/index.js",
"kibana": {
"devOnly": true
},
Expand Down
18 changes: 16 additions & 2 deletions packages/kbn-es-archiver/src/lib/archives/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { createGzip } from 'zlib';
import { createConcatStream, createListStream, createPromiseFromStreams } from '@kbn/utils';

import { createParseArchiveStreams } from './parse';
import { version as kibanaPackageVersion } from '../../../../../package.json';

describe('esArchiver createParseArchiveStreams', () => {
describe('{ gzip: false }', () => {
Expand Down Expand Up @@ -54,6 +55,17 @@ describe('esArchiver createParseArchiveStreams', () => {
expect(output).toEqual([{ a: 1 }, 1]);
});

it('replaces $KIBANA_PACKAGE_VERSION with the current kibana version', async () => {
const output = await createPromiseFromStreams([
createListStream([
Buffer.from('{'),
Buffer.from('"$KIBANA_PACKAGE_VERSION": "enabled"}'),
]),
...createParseArchiveStreams({ gzip: false }),
]);
return expect(output).toEqual({ [kibanaPackageVersion]: 'enabled' });
});

it('provides each JSON object as soon as it is parsed', async () => {
let onReceived: (resolved: any) => void;
const receivedPromise = new Promise((resolve) => (onReceived = resolve));
Expand All @@ -74,11 +86,13 @@ describe('esArchiver createParseArchiveStreams', () => {
createConcatStream([]),
] as [Readable, ...Writable[]]);

input.write(Buffer.from('{"a": 1}\n\n{"a":'));
// before emitting a result, the buffer waits until it at least receives toReplace.length bytes
// so we need a long second object to ensure that the first gets emitted.
input.write(Buffer.from('{"a": 1}\n\n{"propertyNameLongerThanToReplace":'));
expect(await receivedPromise).toEqual({ a: 1 });
input.write(Buffer.from('2}'));
input.end();
expect(await finalPromise).toEqual([{ a: 1 }, { a: 2 }]);
expect(await finalPromise).toEqual([{ a: 1 }, { propertyNameLongerThanToReplace: 2 }]);
});
});

Expand Down
2 changes: 2 additions & 0 deletions packages/kbn-es-archiver/src/lib/archives/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
createSplitStream,
createReplaceStream,
createMapStream,
kibanaPackageJson,
} from '@kbn/utils';

import { RECORD_SEPARATOR } from './constants';
Expand All @@ -21,6 +22,7 @@ export function createParseArchiveStreams({ gzip = false } = {}) {
return [
gzip ? createGunzip() : new PassThrough(),
createReplaceStream('\r\n', '\n'),
createReplaceStream('$KIBANA_PACKAGE_VERSION', kibanaPackageJson.version),
createSplitStream(RECORD_SEPARATOR),
createFilterStream<string>((l) => !!l.match(/[^\s]/)),
createMapStream<string>((json) => JSON.parse(json.trim())),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"type": "index",
"value": {
"aliases": {
".kibana_8.0.0": {},
".kibana_$KIBANA_PACKAGE_VERSION": {},
".kibana": {}
},
"index": ".kibana_8.0.0_001",
"index": ".kibana_$KIBANA_PACKAGE_VERSION_001",
"mappings": {
"dynamic": "false",
"properties": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"type": "index",
"value": {
"aliases": {
".kibana_8.0.0": {},
".kibana_$KIBANA_PACKAGE_VERSION": {},
".kibana": {}
},
"index": ".kibana_8.0.0_001",
"index": ".kibana_$KIBANA_PACKAGE_VERSION_001",
"mappings": {
"dynamic": "false",
"properties": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"type": "index",
"value": {
"aliases": {
".kibana_8.0.0": {},
".kibana_$KIBANA_PACKAGE_VERSION": {},
".kibana": {}
},
"index": ".kibana_8.0.0_001",
"index": ".kibana_$KIBANA_PACKAGE_VERSION_001",
"mappings": {
"dynamic": "false"
},
Expand Down