Skip to content

Commit 0f9debe

Browse files
authored
[FTR] Use importExport for saved_object/basic archive (#100244)
Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>
1 parent eff7765 commit 0f9debe

43 files changed

Lines changed: 2232 additions & 6863 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/kbn-test/src/kbn_client/kbn_client.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88

99
import { ToolingLog } from '@kbn/dev-utils';
1010

11-
import { KbnClientRequester, ReqOptions } from './kbn_client_requester';
12-
import { KbnClientStatus } from './kbn_client_status';
11+
import { KbnClientImportExport } from './kbn_client_import_export';
1312
import { KbnClientPlugins } from './kbn_client_plugins';
14-
import { KbnClientVersion } from './kbn_client_version';
13+
import { KbnClientRequester, ReqOptions } from './kbn_client_requester';
1514
import { KbnClientSavedObjects } from './kbn_client_saved_objects';
15+
import { KbnClientSpaces } from './kbn_client_spaces';
16+
import { KbnClientStatus } from './kbn_client_status';
1617
import { KbnClientUiSettings, UiSettingValues } from './kbn_client_ui_settings';
17-
import { KbnClientImportExport } from './kbn_client_import_export';
18+
import { KbnClientVersion } from './kbn_client_version';
1819

1920
export interface KbnClientOptions {
2021
url: string;
@@ -29,6 +30,7 @@ export class KbnClient {
2930
readonly plugins: KbnClientPlugins;
3031
readonly version: KbnClientVersion;
3132
readonly savedObjects: KbnClientSavedObjects;
33+
readonly spaces: KbnClientSpaces;
3234
readonly uiSettings: KbnClientUiSettings;
3335
readonly importExport: KbnClientImportExport;
3436

@@ -59,6 +61,7 @@ export class KbnClient {
5961
this.plugins = new KbnClientPlugins(this.status);
6062
this.version = new KbnClientVersion(this.status);
6163
this.savedObjects = new KbnClientSavedObjects(this.log, this.requester);
64+
this.spaces = new KbnClientSpaces(this.requester);
6265
this.uiSettings = new KbnClientUiSettings(this.log, this.requester, this.uiSettingDefaults);
6366
this.importExport = new KbnClientImportExport(
6467
this.log,

packages/kbn-test/src/kbn_client/kbn_client_requester.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ export class KbnClientRequester {
121121
responseType: options.responseType,
122122
// work around https://github.com/axios/axios/issues/2791
123123
transformResponse: options.responseType === 'text' ? [(x) => x] : undefined,
124+
maxContentLength: 30000000,
125+
maxBodyLength: 30000000,
124126
paramsSerializer: (params) => Qs.stringify(params),
125127
});
126128

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
import { KbnClientRequester, uriencode } from './kbn_client_requester';
10+
11+
interface UpdateBody {
12+
name: string;
13+
description?: string;
14+
disabledFeatures?: string | string[];
15+
initials?: string;
16+
color?: string;
17+
imageUrl?: string;
18+
}
19+
20+
interface CreateBody extends UpdateBody {
21+
id: string;
22+
}
23+
24+
export class KbnClientSpaces {
25+
constructor(private readonly requester: KbnClientRequester) {}
26+
27+
async create(body: CreateBody) {
28+
await this.requester.request({
29+
method: 'POST',
30+
path: '/api/spaces/space',
31+
body,
32+
});
33+
}
34+
35+
async update(id: string, body: UpdateBody) {
36+
await this.requester.request({
37+
method: 'PUT',
38+
path: uriencode`/api/spaces/space/${id}`,
39+
body,
40+
});
41+
}
42+
43+
async get(id: string) {
44+
const { data } = await this.requester.request({
45+
method: 'GET',
46+
path: uriencode`/api/spaces/space/${id}`,
47+
});
48+
49+
return data;
50+
}
51+
52+
async list() {
53+
const { data } = await this.requester.request({
54+
method: 'GET',
55+
path: '/api/spaces/space',
56+
});
57+
58+
return data;
59+
}
60+
61+
async delete(id: string) {
62+
await this.requester.request({
63+
method: 'DELETE',
64+
path: uriencode`/api/spaces/space/${id}`,
65+
});
66+
}
67+
}

src/dev/precommit_hook/casing_check_config.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export const IGNORE_FILE_GLOBS = [
4141
'.ci/pipeline-library/**/*',
4242
'packages/kbn-test/jest-preset.js',
4343
'test/package/Vagrantfile',
44+
'**/test/**/fixtures/**/*',
4445

4546
// filename must match language code which requires capital letters
4647
'**/translations/*.json',
@@ -61,8 +62,6 @@ export const IGNORE_FILE_GLOBS = [
6162
'x-pack/plugins/apm/e2e/**/*',
6263

6364
'x-pack/plugins/maps/server/fonts/**/*',
64-
// packages for the ingest manager's api integration tests could be valid semver which has dashes
65-
'x-pack/test/fleet_api_integration/apis/fixtures/test_packages/**/*',
6665

6766
// Bazel default files
6867
'**/WORKSPACE.bazel',
@@ -98,7 +97,6 @@ export const IGNORE_DIRECTORY_GLOBS = [
9897
...KEBAB_CASE_DIRECTORY_GLOBS,
9998
'src/babel-*',
10099
'packages/*',
101-
'test/functional/fixtures/es_archiver/visualize_source-filters',
102100
'packages/kbn-pm/src/utils/__fixtures__/*',
103101
'x-pack/dev-tools',
104102
'packages/kbn-optimizer/src/__fixtures__/mock_repo/x-pack',

test/api_integration/apis/kql_telemetry/kql_telemetry.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import { FtrProviderContext } from '../../ftr_provider_context';
1313

1414
export default function ({ getService }: FtrProviderContext) {
1515
const supertest = getService('supertest');
16-
const esArchiver = getService('esArchiver');
16+
const kibanaServer = getService('kibanaServer');
1717
const es = getService('es');
1818

1919
describe('telemetry API', () => {
20-
before(() => esArchiver.load('saved_objects/basic'));
21-
after(() => esArchiver.unload('saved_objects/basic'));
20+
before(() => kibanaServer.importExport.load('saved_objects/basic'));
21+
after(() => kibanaServer.importExport.unload('saved_objects/basic'));
2222

2323
it('should increment the opt *in* counter in the .kibana/kql-telemetry document', async () => {
2424
await supertest

test/api_integration/apis/saved_objects/bulk_create.ts

Lines changed: 48 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import { getKibanaVersion } from './lib/saved_objects_test_utils';
1212

1313
export default function ({ getService }: FtrProviderContext) {
1414
const supertest = getService('supertest');
15-
const esArchiver = getService('esArchiver');
16-
const esDeleteAllIndices = getService('esDeleteAllIndices');
15+
const kibanaServer = getService('kibanaServer');
16+
const SPACE_ID = 'ftr-so-bulk-create';
1717

1818
const BULK_REQUESTS = [
1919
{
@@ -38,99 +38,58 @@ export default function ({ getService }: FtrProviderContext) {
3838

3939
before(async () => {
4040
KIBANA_VERSION = await getKibanaVersion(getService);
41+
await kibanaServer.spaces.create({ id: SPACE_ID, name: SPACE_ID });
42+
await kibanaServer.importExport.load('saved_objects/basic', { space: SPACE_ID });
4143
});
4244

43-
describe('with kibana index', () => {
44-
before(() => esArchiver.load('saved_objects/basic'));
45-
after(() => esArchiver.unload('saved_objects/basic'));
45+
after(() => kibanaServer.spaces.delete(SPACE_ID));
4646

47-
it('should return 200 with individual responses', async () =>
48-
await supertest
49-
.post(`/api/saved_objects/_bulk_create`)
50-
.send(BULK_REQUESTS)
51-
.expect(200)
52-
.then((resp) => {
53-
expect(resp.body).to.eql({
54-
saved_objects: [
55-
{
56-
type: 'visualization',
57-
id: 'dd7caf20-9efd-11e7-acb3-3dab96693fab',
58-
error: {
59-
error: 'Conflict',
60-
message:
61-
'Saved object [visualization/dd7caf20-9efd-11e7-acb3-3dab96693fab] conflict',
62-
statusCode: 409,
63-
},
47+
it('should return 200 with individual responses', async () =>
48+
await supertest
49+
.post(`/s/${SPACE_ID}/api/saved_objects/_bulk_create`)
50+
.send(BULK_REQUESTS)
51+
.expect(200)
52+
.then((resp) => {
53+
expect(resp.body).to.eql({
54+
saved_objects: [
55+
{
56+
type: 'visualization',
57+
id: 'dd7caf20-9efd-11e7-acb3-3dab96693fab',
58+
error: {
59+
error: 'Conflict',
60+
message:
61+
'Saved object [visualization/dd7caf20-9efd-11e7-acb3-3dab96693fab] conflict',
62+
statusCode: 409,
6463
},
65-
{
66-
type: 'dashboard',
67-
id: 'a01b2f57-fcfd-4864-b735-09e28f0d815e',
68-
updated_at: resp.body.saved_objects[1].updated_at,
69-
version: resp.body.saved_objects[1].version,
70-
attributes: {
71-
title: 'A great new dashboard',
72-
},
73-
migrationVersion: {
74-
dashboard: resp.body.saved_objects[1].migrationVersion.dashboard,
75-
},
76-
coreMigrationVersion: KIBANA_VERSION,
77-
references: [],
78-
namespaces: ['default'],
64+
},
65+
{
66+
type: 'dashboard',
67+
id: 'a01b2f57-fcfd-4864-b735-09e28f0d815e',
68+
updated_at: resp.body.saved_objects[1].updated_at,
69+
version: resp.body.saved_objects[1].version,
70+
attributes: {
71+
title: 'A great new dashboard',
7972
},
80-
],
81-
});
82-
}));
83-
84-
it('should not return raw id when object id is unspecified', async () =>
85-
await supertest
86-
.post(`/api/saved_objects/_bulk_create`)
87-
.send(BULK_REQUESTS.map(({ id, ...rest }) => rest))
88-
.expect(200)
89-
.then((resp) => {
90-
resp.body.saved_objects.map(({ id }: { id: string }) =>
91-
expect(id).not.match(/visualization|dashboard/)
92-
);
93-
}));
94-
});
95-
96-
describe('without kibana index', () => {
97-
before(
98-
async () =>
99-
// just in case the kibana server has recreated it
100-
await esDeleteAllIndices('.kibana*')
101-
);
102-
103-
it('should return 200 with errors', async () => {
104-
await new Promise((resolve) => setTimeout(resolve, 2000));
105-
await supertest
106-
.post('/api/saved_objects/_bulk_create')
107-
.send(BULK_REQUESTS)
108-
.expect(200)
109-
.then((resp) => {
110-
expect(resp.body).to.eql({
111-
saved_objects: [
112-
{
113-
id: BULK_REQUESTS[0].id,
114-
type: BULK_REQUESTS[0].type,
115-
error: {
116-
error: 'Internal Server Error',
117-
message: 'An internal server error occurred',
118-
statusCode: 500,
119-
},
73+
migrationVersion: {
74+
dashboard: resp.body.saved_objects[1].migrationVersion.dashboard,
12075
},
121-
{
122-
id: BULK_REQUESTS[1].id,
123-
type: BULK_REQUESTS[1].type,
124-
error: {
125-
error: 'Internal Server Error',
126-
message: 'An internal server error occurred',
127-
statusCode: 500,
128-
},
129-
},
130-
],
131-
});
76+
coreMigrationVersion: KIBANA_VERSION,
77+
references: [],
78+
namespaces: [SPACE_ID],
79+
},
80+
],
13281
});
133-
});
134-
});
82+
}));
83+
84+
it('should not return raw id when object id is unspecified', async () =>
85+
await supertest
86+
.post(`/s/${SPACE_ID}/api/saved_objects/_bulk_create`)
87+
.send(BULK_REQUESTS.map(({ id, ...rest }) => rest))
88+
.expect(200)
89+
.then((resp) => {
90+
resp.body.saved_objects.map(({ id }: { id: string }) =>
91+
expect(id).not.match(/visualization|dashboard/)
92+
);
93+
}));
13594
});
13695
}

0 commit comments

Comments
 (0)